Now scoping out Item loading.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -15,7 +16,6 @@ namespace CaveGame::Core
|
||||
Register(data.mnemonic, data);
|
||||
}
|
||||
|
||||
|
||||
bool Exists(const std::string& name) {
|
||||
return registered_items.contains(name);
|
||||
}
|
||||
@@ -38,4 +38,9 @@ namespace CaveGame::Core
|
||||
};
|
||||
|
||||
static ItemRegistry& Items() { return ItemRegistry::Instance();}
|
||||
|
||||
bool LoadItemMetadata(const std::filesystem::path& path);
|
||||
|
||||
bool LoadItemMetadata();
|
||||
|
||||
}
|
@@ -7,4 +7,7 @@
|
||||
|
||||
std::vector<std::string> string_split(const std::string& s, char delim);
|
||||
|
||||
std::string string_build(const std::vector<std::string> &list, const std::string& delim = " ");
|
||||
std::string string_build(const std::vector<std::string> &list, const std::string& delim = " ");
|
||||
|
||||
|
||||
std::string read_file(const std::string &file_path);
|
@@ -77,8 +77,6 @@ namespace CaveGame::Core {
|
||||
/// Convenient access to the tile registry.
|
||||
static TileRegistry& Tiles() { return TileRegistry::Instance();}
|
||||
|
||||
std::string read_file(const std::string& file_path);
|
||||
|
||||
Color4 parse_color(const JJX::json::value& v);
|
||||
|
||||
bool LoadTileMetadata(const std::filesystem::path& path);
|
||||
|
@@ -1,6 +1,15 @@
|
||||
#include <Core/ItemRegistry.hpp>
|
||||
#include <Core/Macros.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
|
||||
bool LoadItemMetadata(const std::filesystem::path &path) {
|
||||
|
||||
}
|
||||
|
||||
bool LoadItemMetadata() {
|
||||
LoadItemMetadata("assets/data/items.json");
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
#include <Core/Macros.hpp>
|
||||
#include <fstream>
|
||||
|
||||
std::vector<std::string> string_split(const std::string &s, char delim) {
|
||||
std::vector<std::string> result;
|
||||
@@ -29,3 +30,20 @@ std::string string_build(const std::vector<std::string> &list, const std::string
|
||||
// return ss.empty() ? s : ss + delim + s;
|
||||
// });
|
||||
}
|
||||
|
||||
std::string read_file(const std::string &file_path) {
|
||||
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
|
||||
if (!file)
|
||||
throw std::runtime_error("We couldn't find the file: " + file_path);
|
||||
|
||||
std::streamsize file_size;
|
||||
file.seekg(0, std::ios::end);
|
||||
file_size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::string file_content(file_size, '\0');
|
||||
file.read(&file_content[0], file_size);
|
||||
file.close();
|
||||
|
||||
return file_content;
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include <format>
|
||||
#include <Core/Item.hpp>
|
||||
#include <Core/ItemRegistry.hpp>
|
||||
#include <Core/Macros.hpp>
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
@@ -133,22 +134,7 @@ namespace CaveGame::Core
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string read_file(const std::string &file_path) {
|
||||
std::ifstream file(file_path, std::ios::binary);
|
||||
if (!file)
|
||||
throw std::runtime_error("We couldn't find the file: " + file_path);
|
||||
|
||||
std::streamsize file_size;
|
||||
file.seekg(0, std::ios::end);
|
||||
file_size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::string file_content(file_size, '\0');
|
||||
file.read(&file_content[0], file_size);
|
||||
file.close();
|
||||
|
||||
return file_content;
|
||||
}
|
||||
|
||||
Color4 parse_color(const JJX::json::value &v) {
|
||||
if (v.type == JJX::json::value_type::string)
|
||||
|
Reference in New Issue
Block a user