Items intruduced (part II)
This commit is contained in:
+19
-13
@@ -1,14 +1,11 @@
|
||||
#include "Content.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "../voxels/Block.h"
|
||||
#include "../content/ItemDef.h"
|
||||
|
||||
using glm::vec3;
|
||||
using std::string;
|
||||
using std::unordered_map;
|
||||
#include "../items/ItemDef.h"
|
||||
|
||||
ContentBuilder::~ContentBuilder() {
|
||||
}
|
||||
@@ -69,7 +66,7 @@ contenttype ContentBuilder::checkContentType(std::string id) {
|
||||
Content* ContentBuilder::build() {
|
||||
std::vector<Block*> blockDefsIndices;
|
||||
DrawGroups* groups = new DrawGroups;
|
||||
for (const string& name : blockIds) {
|
||||
for (const std::string& name : blockIds) {
|
||||
Block* def = blockDefs[name];
|
||||
|
||||
// Generating runtime info
|
||||
@@ -93,7 +90,7 @@ Content* ContentBuilder::build() {
|
||||
}
|
||||
|
||||
std::vector<ItemDef*> itemDefsIndices;
|
||||
for (const string& name : itemIds) {
|
||||
for (const std::string& name : itemIds) {
|
||||
ItemDef* def = itemDefs[name];
|
||||
|
||||
// Generating runtime info
|
||||
@@ -102,7 +99,14 @@ Content* ContentBuilder::build() {
|
||||
}
|
||||
|
||||
auto indices = new ContentIndices(blockDefsIndices, itemDefsIndices);
|
||||
return new Content(indices, groups, blockDefs);
|
||||
std::unique_ptr<Content> content (new Content(indices, groups, blockDefs, itemDefs));
|
||||
|
||||
// Now, it's time to solve foreign keys
|
||||
for (Block* def : blockDefsIndices) {
|
||||
def->rt.pickingItem = content->requireItem(def->pickingItem)->rt.id;
|
||||
}
|
||||
|
||||
return content.release();
|
||||
}
|
||||
|
||||
ContentIndices::ContentIndices(
|
||||
@@ -113,8 +117,10 @@ ContentIndices::ContentIndices(
|
||||
}
|
||||
|
||||
Content::Content(ContentIndices* indices, DrawGroups* drawGroups,
|
||||
unordered_map<string, Block*> blockDefs)
|
||||
std::unordered_map<std::string, Block*> blockDefs,
|
||||
std::unordered_map<std::string, ItemDef*> itemDefs)
|
||||
: blockDefs(blockDefs),
|
||||
itemDefs(itemDefs),
|
||||
indices(indices),
|
||||
drawGroups(drawGroups) {
|
||||
}
|
||||
@@ -124,7 +130,7 @@ Content::~Content() {
|
||||
delete drawGroups;
|
||||
}
|
||||
|
||||
Block* Content::findBlock(string id) const {
|
||||
Block* Content::findBlock(std::string id) const {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found == blockDefs.end()) {
|
||||
return nullptr;
|
||||
@@ -132,7 +138,7 @@ Block* Content::findBlock(string id) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
Block* Content::requireBlock(string id) const {
|
||||
Block* Content::requireBlock(std::string id) const {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found == blockDefs.end()) {
|
||||
throw std::runtime_error("missing block "+id);
|
||||
@@ -140,7 +146,7 @@ Block* Content::requireBlock(string id) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
ItemDef* Content::findItem(string id) const {
|
||||
ItemDef* Content::findItem(std::string id) const {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found == itemDefs.end()) {
|
||||
return nullptr;
|
||||
@@ -148,7 +154,7 @@ ItemDef* Content::findItem(string id) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
ItemDef* Content::requireItem(string id) const {
|
||||
ItemDef* Content::requireItem(std::string id) const {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found == itemDefs.end()) {
|
||||
throw std::runtime_error("missing item "+id);
|
||||
|
||||
@@ -97,7 +97,8 @@ public:
|
||||
DrawGroups* const drawGroups;
|
||||
|
||||
Content(ContentIndices* indices, DrawGroups* drawGroups,
|
||||
std::unordered_map<std::string, Block*> blockDefs);
|
||||
std::unordered_map<std::string, Block*> blockDefs,
|
||||
std::unordered_map<std::string, ItemDef*> itemDefs);
|
||||
~Content();
|
||||
|
||||
Block* findBlock(std::string id) const;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "Content.h"
|
||||
#include "ItemDef.h"
|
||||
#include "../items/ItemDef.h"
|
||||
#include "../util/listutil.h"
|
||||
#include "../voxels/Block.h"
|
||||
#include "../files/files.h"
|
||||
@@ -175,6 +175,8 @@ void ContentLoader::loadBlock(Block* def, std::string name, fs::path file) {
|
||||
root->flag("hidden", def->hidden);
|
||||
root->flag("sky-light-passing", def->skyLightPassing);
|
||||
root->num("draw-group", def->drawGroup);
|
||||
|
||||
root->str("picking-item", def->pickingItem);
|
||||
}
|
||||
|
||||
void ContentLoader::loadItem(ItemDef* def, std::string name, std::filesystem::path file) {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#include "ItemDef.h"
|
||||
|
||||
ItemDef::ItemDef(std::string name) : name(name) {
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifndef CONTENT_ITEM_DEF_H_
|
||||
#define CONTENT_ITEM_DEF_H_
|
||||
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "../graphics/UVRegion.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#define BLOCK_ITEM_SUFFIX ".item"
|
||||
|
||||
struct item_funcs_set {
|
||||
bool init: 1;
|
||||
};
|
||||
|
||||
enum class item_icon_type {
|
||||
none, // invisible (core:empty) must not be rendered
|
||||
sprite, // textured quad: icon is `atlas_name:texture_name`
|
||||
block, // block preview: icon is string block id
|
||||
};
|
||||
|
||||
class ItemDef {
|
||||
public:
|
||||
std::string const name;
|
||||
|
||||
bool generated = false;
|
||||
|
||||
item_icon_type iconType = item_icon_type::sprite;
|
||||
std::string icon = "block:notfound";
|
||||
|
||||
std::string placingBlock = "none";
|
||||
|
||||
struct {
|
||||
itemid_t id;
|
||||
item_funcs_set funcsset {};
|
||||
UVRegion iconRegion {0, 0, 1, 1};
|
||||
} rt;
|
||||
|
||||
ItemDef(std::string name);
|
||||
};
|
||||
|
||||
#endif //CONTENT_ITEM_DEF_H_
|
||||
Reference in New Issue
Block a user