lua: inventory library
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "../physics/PhysicsSolver.h"
|
||||
#include "../objects/Player.h"
|
||||
#include "../items/Inventory.h"
|
||||
#include "../items/Inventories.h"
|
||||
|
||||
Level::Level(World* world, const Content* content, Player* player, EngineSettings& settings)
|
||||
: world(world),
|
||||
@@ -30,6 +31,8 @@ Level::Level(World* world, const Content* content, Player* player, EngineSetting
|
||||
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
|
||||
this->chunksStorage->remove(chunk->x, chunk->z);
|
||||
});
|
||||
|
||||
inventories = std::make_unique<Inventories>(*this);
|
||||
}
|
||||
|
||||
Level::~Level(){
|
||||
|
||||
@@ -11,6 +11,7 @@ class World;
|
||||
class Player;
|
||||
class Chunks;
|
||||
class Inventory;
|
||||
class Inventories;
|
||||
class LevelEvents;
|
||||
class Lighting;
|
||||
class PhysicsSolver;
|
||||
@@ -23,6 +24,7 @@ public:
|
||||
Player* player;
|
||||
Chunks* chunks;
|
||||
ChunksStorage* chunksStorage;
|
||||
std::unique_ptr<Inventories> inventories;
|
||||
|
||||
PhysicsSolver* physics;
|
||||
Lighting* lighting;
|
||||
|
||||
+13
-4
@@ -13,6 +13,7 @@
|
||||
#include "../voxels/ChunksStorage.h"
|
||||
#include "../objects/Player.h"
|
||||
#include "../window/Camera.h"
|
||||
#include "../items/Inventories.h"
|
||||
|
||||
world_load_error::world_load_error(std::string message)
|
||||
: std::runtime_error(message) {
|
||||
@@ -65,6 +66,7 @@ void World::write(Level* level) {
|
||||
|
||||
const float DEF_PLAYER_Y = 100.0f;
|
||||
const float DEF_PLAYER_SPEED = 4.0f;
|
||||
const int DEF_PLAYER_INVENTORY_SIZE = 40;
|
||||
|
||||
Level* World::create(std::string name,
|
||||
fs::path directory,
|
||||
@@ -73,8 +75,12 @@ Level* World::create(std::string name,
|
||||
const Content* content,
|
||||
const std::vector<ContentPack>& packs) {
|
||||
auto world = new World(name, directory, seed, settings, content, packs);
|
||||
auto player = new Player(glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED);
|
||||
return new Level(world, content, player, settings);
|
||||
auto inv = std::make_shared<Inventory>(world->getNextInventoryId(), DEF_PLAYER_INVENTORY_SIZE);
|
||||
auto player = new Player(
|
||||
glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv
|
||||
);
|
||||
auto level = new Level(world, content, player, settings);
|
||||
level->inventories->store(player->getInventory());
|
||||
}
|
||||
|
||||
Level* World::load(fs::path directory,
|
||||
@@ -90,10 +96,13 @@ Level* World::load(fs::path directory,
|
||||
throw world_load_error("could not to find world.json");
|
||||
}
|
||||
|
||||
auto player = new Player(glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED);
|
||||
auto inv = std::make_shared<Inventory>(0, DEF_PLAYER_INVENTORY_SIZE);
|
||||
auto player = new Player(
|
||||
glm::vec3(0, DEF_PLAYER_Y, 0), DEF_PLAYER_SPEED, inv
|
||||
);
|
||||
auto level = new Level(world.get(), content, player, settings);
|
||||
wfile->readPlayer(player);
|
||||
|
||||
level->inventories->store(player->getInventory());
|
||||
world.release();
|
||||
return level;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user