Few more edits for the night
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <ReWindow/InputService.h>
|
||||
#include <Core/Macros.hpp>
|
||||
#include <jstick.hpp>
|
||||
#include <Core/ItemRegistry.hpp>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
#include <JJX/JSON.hpp>
|
||||
|
||||
@@ -38,7 +39,7 @@ namespace CaveGame::ClientApp
|
||||
void ReadRecipesAndRegister() {}
|
||||
|
||||
void ReadItemDataAndRegister() {
|
||||
Core::Item item;
|
||||
|
||||
|
||||
using namespace JJX;
|
||||
std::string content = read_file("assets/data/items.json");
|
||||
@@ -49,6 +50,22 @@ namespace CaveGame::ClientApp
|
||||
// TODO: Error
|
||||
return;
|
||||
}
|
||||
for (auto& entry : data.array.value()) {
|
||||
Core::Item item;
|
||||
|
||||
auto entry_obj = json::object_val(entry);
|
||||
|
||||
item.mnemonic = entry_obj["mnemonic-id"];
|
||||
item.display_name = entry_obj["display-name"];
|
||||
|
||||
|
||||
Items().Register(item);
|
||||
|
||||
}
|
||||
|
||||
for (auto [name, item] : Items().GetItemMap()) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadTileDataAndRegister()
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
|
@@ -1,11 +1,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Core/Data.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
using TileState = uint16_t;
|
||||
using TileID = uint16_t;
|
||||
|
||||
|
||||
class ITileMap
|
||||
|
@@ -19,7 +19,7 @@ namespace CaveGame::Core {
|
||||
struct Tile;
|
||||
|
||||
using ColorPallet = std::vector<Color4>;
|
||||
using TileTiccFunc = std::function<void(const Tile& data, ITileMap* world, int x, int y)>;
|
||||
//using TileTiccFunc = std::function<void(const Tile& data, ITileMap* world, int x, int y)>;
|
||||
|
||||
|
||||
struct Tile {
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "Core/Simplex.hpp"
|
||||
#include "Core/Data.hpp"
|
||||
#include <iostream>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <Core/Generator.hpp>
|
||||
#include <Core/Data.hpp>
|
||||
#include <Core/TileRegistry.hpp>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -39,12 +40,12 @@ namespace CaveGame::Core
|
||||
float rand = GetPrecomputedWhiteNoise2D(wx, wy)*(TopSoilDepth/2.f);
|
||||
|
||||
if (wy > 1000)
|
||||
return TileRegistry::Get()["stone"].numeric_id;
|
||||
return Tiles()["stone"].numeric_id;
|
||||
|
||||
if (depth < 0) { return TileID::AIR; }
|
||||
else if (depth < 2.5f) { return TileID::GRASS; }
|
||||
else if (depth < TopSoilDepth-rand) { return TileID::DIRT; }
|
||||
else { return TileID::STONE; }
|
||||
if (depth < 0) { return Tiles().MnemonicToNumeric("air"); }
|
||||
else if (depth < 2.5f) { return Tiles().MnemonicToNumeric("grass");; }
|
||||
else if (depth < TopSoilDepth-rand) { return Tiles().MnemonicToNumeric("dirt"); }
|
||||
else { return Tiles().MnemonicToNumeric("stone");; }
|
||||
}
|
||||
|
||||
float Generator::Perlin(int wx, int wy, float hScale, float vScale, float offset, float outputScale) {
|
||||
@@ -122,7 +123,7 @@ namespace CaveGame::Core
|
||||
}
|
||||
|
||||
if (cave_erosion > -CaveErosionRange && CaveErosionRange > cave_erosion) {
|
||||
return TileID::AIR;
|
||||
return Tiles()["air"].numeric_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -136,54 +137,54 @@ namespace CaveGame::Core
|
||||
// Yes, sometimes we re-use a pass to generate another tile entirely. Why?
|
||||
// We don't need the full parameter space for clay generation, as it's rarer, and it gives
|
||||
// more variety to dirt blob generation, for example.
|
||||
if (clay_pass > 0.85f) { return TileID::CLAY; }
|
||||
if (clay_pass < -0.75f) { return TileID::DIRT; }
|
||||
if (clay_pass > 0.85f) { return Tiles()["clay"].numeric_id; }
|
||||
if (clay_pass < -0.75f) { return Tiles()["dirt"].numeric_id; }
|
||||
|
||||
// Chunks of silt and dirt.
|
||||
float silt_pass = ComputeOre(wx, wy, SiltVeinHiPassScale, SiltVeinLoPassScale, SiltVeinHiPassOffset, SiltVeinLoPassOffset,
|
||||
SiltVeinHiPassOutputScale, SiltVeinLoPassOutputScale, SiltVeinNoise, SiltVeinRampFactor);
|
||||
|
||||
if (silt_pass > 0.85f) { return TileID::SILT; }
|
||||
if (silt_pass < -0.75f) { return TileID::DIRT; }
|
||||
if (silt_pass > 0.85f) { return Tiles()["silt"].numeric_id; }
|
||||
if (silt_pass < -0.75f) { return Tiles()["dirt"].numeric_id; }
|
||||
|
||||
// Chunks of stone.
|
||||
float stone_pass = ComputeOre(wx, wy, StoneVeinHiPassScale, StoneVeinLoPassScale, StoneVeinHiPassOffset, StoneVeinLoPassOffset,
|
||||
StoneVeinHiPassOutputScale, StoneVeinLoPassOutputScale, StoneVeinNoise, StoneVeinRampFactor);
|
||||
|
||||
// Chunks of stone
|
||||
if (stone_pass > 0.7f) { return TileID::STONE; }
|
||||
if (stone_pass < -0.7f) { return TileID::STONE; }
|
||||
if (stone_pass > 0.7f) { return Tiles()["stone"].numeric_id; }
|
||||
if (stone_pass < -0.7f) { return Tiles()["stone"].numeric_id; }
|
||||
|
||||
// Chunks of dirt
|
||||
float dirt_pass = ComputeOre(wx, wy, DirtVeinHiPassScale, DirtVeinLoPassScale, DirtVeinHiPassOffset, DirtVeinLoPassOffset,
|
||||
DirtVeinHiPassOutputScale, DirtVeinLoPassOutputScale, DirtVeinNoise, DirtVeinRampFactor);
|
||||
|
||||
if (-0.65 > dirt_pass && dirt_pass < 0.65f) { return TileID::DIRT; }
|
||||
if (-0.65 > dirt_pass && dirt_pass < 0.65f) { return Tiles()["dirt"].numeric_id; }
|
||||
|
||||
// Coal veins
|
||||
float coal_pass = ComputeOre(wx, wy, CoalVeinHiPassScale, CoalVeinLoPassScale, CoalVeinHiPassOffset, CoalVeinLoPassOffset,
|
||||
CoalVeinHiPassOutputScale, CoalVeinLoPassOutputScale, CoalVeinNoise, CoalVeinRampFactor);
|
||||
|
||||
if (coal_pass > 0.75f) { return TileID::COAL_ORE; }
|
||||
if (coal_pass < -0.75f) { return TileID::COAL_ORE;}
|
||||
if (coal_pass > 0.75f) { return Tiles()["coal-ore"].numeric_id; }
|
||||
if (coal_pass < -0.75f) { return Tiles()["coal-ore"].numeric_id;}
|
||||
|
||||
// Copper ore veins
|
||||
float copper_pass = ComputeOre(wx, wy, CopperVeinHiPassScale, CopperVeinLoPassScale, CopperVeinHiPassOffset, CopperVeinLoPassOffset,
|
||||
CopperVeinHiPassOutputScale, CopperVeinLoPassOutputScale, CopperVeinNoise, CopperVeinRampFactor);
|
||||
|
||||
if (copper_pass > 0.8f) { return TileID::COPPER_ORE; }
|
||||
if (copper_pass > 0.8f) { return Tiles()["copper-ore"].numeric_id; }
|
||||
|
||||
// Tin ore veins
|
||||
float tin_pass = ComputeOre(wx, wy, TinVeinHiPassScale, TinVeinLoPassScale, TinVeinHiPassOffset, TinVeinLoPassOffset,
|
||||
TinVeinHiPassOutputScale, TinVeinLoPassOutputScale, TinVeinNoise, TinVeinRampFactor);
|
||||
|
||||
if (tin_pass > 0.85f) { return TileID::TIN_ORE; }
|
||||
if (tin_pass > 0.85f) { return Tiles()["tin-ore"].numeric_id; }
|
||||
|
||||
// Iron ore veins
|
||||
float iron_pass = ComputeOre(wx, wy, IronVeinHiPassScale, IronVeinLoPassScale, IronVeinHiPassOffset, IronVeinLoPassOffset,
|
||||
IronVeinHiPassOutputScale, IronVeinLoPassOutputScale, IronVeinNoise, IronVeinRampFactor);
|
||||
|
||||
if (iron_pass > 0.90f) { return TileID::IRON_ORE;}
|
||||
if (iron_pass > 0.90f) { return Tiles()["iron-ore"].numeric_id;}
|
||||
|
||||
if (depth > 1000) {
|
||||
// Lead ore veins
|
||||
@@ -271,16 +272,16 @@ namespace CaveGame::Core
|
||||
continue;
|
||||
|
||||
|
||||
if (chunk->GetTile(x, y) != TileID::GRASS)
|
||||
if (chunk->GetTile(x, y) != Tiles()["grass"].numeric_id) {}
|
||||
continue;
|
||||
|
||||
if (world->GetTile(wx, wy-1) != TileID::AIR || world->GetTile(wx, wy-2) != TileID::AIR || world->GetTile(wx, wy-3) != TileID::AIR)
|
||||
if (world->GetTile(wx, wy-1) != Tiles()["air"].numeric_id || world->GetTile(wx, wy-2) != Tiles()["air"].numeric_id || world->GetTile(wx, wy-3) != Tiles()["air"].numeric_id )
|
||||
continue;
|
||||
|
||||
int treeHeight = 5 + (GetPrecomputedWhiteNoise1D(wx) * 12);
|
||||
|
||||
for (int tree_y = 0; tree_y < treeHeight; tree_y++) {
|
||||
world->SetTile(wx, wy-tree_y, TileID::OAK_LOG);
|
||||
world->SetTile(wx, wy-tree_y, Tiles()["oak-log"].numeric_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ namespace CaveGame::Core
|
||||
//if (tile == TileID::AIR || tile == TileID::VINE || tile == TileID::WATER)
|
||||
//return true;
|
||||
|
||||
if (tile == 0 || !Tiles::GetInstance()->GetByNumericID(tile).solid)
|
||||
if (tile == 0 || !Tiles().GetByNumericID(tile).solid)
|
||||
return true;
|
||||
|
||||
|
||||
|
@@ -3,31 +3,4 @@
|
||||
#include <map>
|
||||
|
||||
namespace CaveGame::Core {
|
||||
|
||||
std::map<std::string, Item*> item_registry{};
|
||||
|
||||
void RegisterItem(const std::string& mnemonic, Item* item)
|
||||
{
|
||||
item_registry.insert({mnemonic, item});
|
||||
}
|
||||
|
||||
void RegisterNewItem(const std::string& mnemonic, const Item& item)
|
||||
{
|
||||
//item_registry.emplace(mnemonic, new Item(item));
|
||||
}
|
||||
|
||||
Item* GetItem(const std::string& mnemonic)
|
||||
{
|
||||
return item_registry.at(mnemonic);
|
||||
}
|
||||
|
||||
std::map<std::string, Item*> GetAllItems()
|
||||
{
|
||||
return item_registry;
|
||||
}
|
||||
|
||||
Item::Item(const std::string& mnemonic) {
|
||||
this->mnemonic = mnemonic;
|
||||
RegisterItem(mnemonic, this);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user