Added plants. Added game time management.
This commit is contained in:
parent
c12a8ede5a
commit
2bd8605711
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<Background columns="380" rows="213" >
|
|
||||||
|
|
||||||
<Layer name="Background"
|
|
||||||
cells="levels/Farm_Background.csv"
|
|
||||||
texture="tilesets/Ground.png" />
|
|
||||||
|
|
||||||
<Layer name="Soil"
|
|
||||||
cells="levels/Farm_Soil.csv"
|
|
||||||
texture="tilesets/Ground.png" />
|
|
||||||
|
|
||||||
</Background>
|
|
15
assets/maps/Farm.map
Normal file
15
assets/maps/Farm.map
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Map width="380" height="213"
|
||||||
|
cellWidth="16" cellHeight="16" >
|
||||||
|
|
||||||
|
<Layer name="Background" cells="maps/Farm_Background.csv">
|
||||||
|
<TileSet texture="tilesets/Ground.png"
|
||||||
|
tileWidth="16" tileHeight="16" />
|
||||||
|
</Layer>
|
||||||
|
|
||||||
|
<Layer name="Soil" cells="maps/Farm_Soil.csv">
|
||||||
|
<TileSet texture="tilesets/Ground.png"
|
||||||
|
tileWidth="16" tileHeight="16" />
|
||||||
|
</Layer>
|
||||||
|
|
||||||
|
</Map>
|
33
assets/plants/Plantable.xml
Normal file
33
assets/plants/Plantable.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ItemCollection>
|
||||||
|
|
||||||
|
<GameObject name="Ugliceea">
|
||||||
|
<Transform />
|
||||||
|
<Sprite name="Ugliceea" anchorX="0" anchorY=".5">
|
||||||
|
<State name="0">
|
||||||
|
<Frame tileSet="plants/graphics/Ugliceea.png" cell="0" w="1" h="2" duration="1" />
|
||||||
|
</State>
|
||||||
|
<State name="1">
|
||||||
|
<Frame tileSet="plants/graphics/Ugliceea.png" cell="1" w="1" h="2" duration="1" />
|
||||||
|
</State>
|
||||||
|
<State name="2">
|
||||||
|
<Frame tileSet="plants/graphics/Ugliceea.png" cell="2" w="1" h="2" duration="1" />
|
||||||
|
</State>
|
||||||
|
<State name="3">
|
||||||
|
<Frame tileSet="plants/graphics/Ugliceea.png" cell="3" w="1" h="2" duration="1" />
|
||||||
|
</State>
|
||||||
|
<State name="4">
|
||||||
|
<Frame tileSet="plants/graphics/Ugliceea.png" cell="4" w="1" h="2" duration="1" />
|
||||||
|
</State>
|
||||||
|
</Sprite>
|
||||||
|
<SpriteRenderer />
|
||||||
|
<Plant needsWater="false" maxDaysWithoutWater="3">
|
||||||
|
<State len="1" />
|
||||||
|
<State len="1" />
|
||||||
|
<State len="2" />
|
||||||
|
<State len="1" />
|
||||||
|
<State len="-1" />
|
||||||
|
</Plant>
|
||||||
|
</GameObject>
|
||||||
|
|
||||||
|
</ItemCollection>
|
16
assets/plants/Seeds.xml
Normal file
16
assets/plants/Seeds.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ItemCollection>
|
||||||
|
|
||||||
|
<GameObject name="Ugliceea seed">
|
||||||
|
<Transform />
|
||||||
|
<Sprite name="Ugliceea seed" anchorX="0" anchorY="1">
|
||||||
|
<State name="0">
|
||||||
|
<Frame tileSet="plants/graphics/Ugliceea.png" cell="5" w="1" h="1" duration="1" />
|
||||||
|
</State>
|
||||||
|
</Sprite>
|
||||||
|
<SpriteRenderer />
|
||||||
|
<Item name="Ugliceea seed" description="A pretty interesting plant." />
|
||||||
|
<Seed plantName="Ugliceea" />
|
||||||
|
</GameObject>
|
||||||
|
|
||||||
|
</ItemCollection>
|
BIN
assets/plants/graphics/Ugliceea.png
Normal file
BIN
assets/plants/graphics/Ugliceea.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 697 B |
@ -6,15 +6,17 @@
|
|||||||
<GameObject name="Main Camera">
|
<GameObject name="Main Camera">
|
||||||
<Transform />
|
<Transform />
|
||||||
<Camera scale="4" mainCamera="true" />
|
<Camera scale="4" mainCamera="true" />
|
||||||
|
<GameTime />
|
||||||
</GameObject>
|
</GameObject>
|
||||||
|
|
||||||
<!-- Background object -->
|
<!-- Background object -->
|
||||||
<GameObject name="Background">
|
<GameObject name="Map">
|
||||||
<Background src="levels/Farm.back" />
|
<Map src="maps/Farm.map" />
|
||||||
<BackgroundRenderer />
|
<MapRenderer />
|
||||||
</GameObject>
|
</GameObject>
|
||||||
|
|
||||||
<GameObject name="Object Layer">
|
<GameObject name="Object Layer">
|
||||||
|
<Transform />
|
||||||
<Grid w="380" h="250" />
|
<Grid w="380" h="250" />
|
||||||
</GameObject>
|
</GameObject>
|
||||||
|
|
||||||
|
BIN
assets_original/plant_uglyceea.xcf
Normal file
BIN
assets_original/plant_uglyceea.xcf
Normal file
Binary file not shown.
@ -11,12 +11,17 @@ namespace farmlands {
|
|||||||
GameState GameState::s_current;
|
GameState GameState::s_current;
|
||||||
|
|
||||||
GameState::GameState()
|
GameState::GameState()
|
||||||
: config(nullptr),
|
: gameInitialized(false),
|
||||||
|
config(nullptr),
|
||||||
renderContext(),
|
renderContext(),
|
||||||
scene(nullptr),
|
scene(nullptr),
|
||||||
itemPrefabs(),
|
itemPrefabs(),
|
||||||
elapsedTime(0),
|
seedsPrefabs(),
|
||||||
gameInitialized(false)
|
plantsPrefabs(),
|
||||||
|
time(0),
|
||||||
|
date(0),
|
||||||
|
isMidnight(false),
|
||||||
|
deltaTime(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +29,15 @@ GameState::~GameState()
|
|||||||
{
|
{
|
||||||
if (scene) delete scene;
|
if (scene) delete scene;
|
||||||
if (config) delete config;
|
if (config) delete config;
|
||||||
|
|
||||||
|
for (auto obj : itemPrefabs)
|
||||||
|
delete obj;
|
||||||
|
|
||||||
|
for (auto obj : seedsPrefabs)
|
||||||
|
delete obj;
|
||||||
|
|
||||||
|
for (auto obj : plantsPrefabs)
|
||||||
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameState& farmlands::GameState::current()
|
GameState& farmlands::GameState::current()
|
||||||
@ -31,9 +45,4 @@ GameState& farmlands::GameState::current()
|
|||||||
return s_current;
|
return s_current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void farmlands::GameState::setCurrent(GameState& state)
|
|
||||||
{
|
|
||||||
s_current = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,9 @@ namespace farmlands {
|
|||||||
GameState();
|
GameState();
|
||||||
~GameState();
|
~GameState();
|
||||||
static GameState& current();
|
static GameState& current();
|
||||||
static void setCurrent(GameState& state);
|
|
||||||
|
// Initialized?
|
||||||
|
bool gameInitialized;
|
||||||
|
|
||||||
// Game settings
|
// Game settings
|
||||||
model::Configuration* config;
|
model::Configuration* config;
|
||||||
@ -35,10 +37,15 @@ namespace farmlands {
|
|||||||
// Scene
|
// Scene
|
||||||
model::Scene* scene;
|
model::Scene* scene;
|
||||||
std::vector<model::GameObject*> itemPrefabs;
|
std::vector<model::GameObject*> itemPrefabs;
|
||||||
|
std::vector<model::GameObject*> seedsPrefabs;
|
||||||
|
std::vector<model::GameObject*> plantsPrefabs;
|
||||||
|
|
||||||
// Misc
|
// Timing
|
||||||
float elapsedTime;
|
float time;
|
||||||
bool gameInitialized;
|
uint32_t date;
|
||||||
|
bool isMidnight;
|
||||||
|
|
||||||
|
float deltaTime;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static GameState s_current;
|
static GameState s_current;
|
||||||
|
@ -38,7 +38,7 @@ namespace assets {
|
|||||||
inline bool groundIsDirt(int cell) { return cell >= Ground::Dirt && cell <= Ground::DirtVariation8; }
|
inline bool groundIsDirt(int cell) { return cell >= Ground::Dirt && cell <= Ground::DirtVariation8; }
|
||||||
inline bool groundIsDrySoil(int cell) { return cell == Ground::SoilDry; }
|
inline bool groundIsDrySoil(int cell) { return cell == Ground::SoilDry; }
|
||||||
inline bool groundIsWetSoil(int cell) { return cell == Ground::SoilWet; }
|
inline bool groundIsWetSoil(int cell) { return cell == Ground::SoilWet; }
|
||||||
|
inline bool groundIsSoil(int cell) { return cell == Ground::SoilDry || cell == Ground::SoilWet; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ void DebugController::onUpdateLogic()
|
|||||||
vel = ScaleShiftVelocity;
|
vel = ScaleShiftVelocity;
|
||||||
|
|
||||||
// Time independent
|
// Time independent
|
||||||
vel *= GameState::current().elapsedTime;
|
vel *= GameState::current().deltaTime;
|
||||||
|
|
||||||
if (Input::instance().pressed(GameKey::Debug_ZoomIn))
|
if (Input::instance().pressed(GameKey::Debug_ZoomIn))
|
||||||
m_camera->scale *= 1 + vel;
|
m_camera->scale *= 1 + vel;
|
||||||
|
55
src/components/GameTime.cpp
Normal file
55
src/components/GameTime.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* GameTime.cpp
|
||||||
|
*
|
||||||
|
* Created on: Dec 9, 2016
|
||||||
|
* Author: tibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <GameState.h>
|
||||||
|
#include <components/GameTime.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Day length (in seconds)
|
||||||
|
//#define DAYLENGTH 24 * 60
|
||||||
|
#define DAYLENGTH 10
|
||||||
|
|
||||||
|
namespace farmlands {
|
||||||
|
namespace components {
|
||||||
|
|
||||||
|
GameTime::~GameTime()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
model::Component* GameTime::clone()
|
||||||
|
{
|
||||||
|
return new GameTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameTime::dump(unsigned level)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < level; i++)
|
||||||
|
std::cout<<" ";
|
||||||
|
|
||||||
|
std::cout << " .Component: GameTime \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameTime::onUpdateLogic()
|
||||||
|
{
|
||||||
|
float delta = GameState::current().deltaTime;
|
||||||
|
GameState::current().time += delta;
|
||||||
|
GameState::current().isMidnight = false;
|
||||||
|
|
||||||
|
if (GameState::current().time > DAYLENGTH)
|
||||||
|
{
|
||||||
|
GameState::current().time -= DAYLENGTH;
|
||||||
|
GameState::current().date++;
|
||||||
|
GameState::current().isMidnight = true;
|
||||||
|
|
||||||
|
std::cout << "It's midnight! Date: " << GameState::current().date << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace components */
|
||||||
|
} /* namespace farmlands */
|
33
src/components/GameTime.h
Normal file
33
src/components/GameTime.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* GameTime.h
|
||||||
|
*
|
||||||
|
* Created on: Dec 9, 2016
|
||||||
|
* Author: tibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef COMPONENTS_GAMETIME_H_
|
||||||
|
#define COMPONENTS_GAMETIME_H_
|
||||||
|
|
||||||
|
#include <model/Component.h>
|
||||||
|
|
||||||
|
namespace farmlands {
|
||||||
|
namespace components {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maintains game time.
|
||||||
|
*/
|
||||||
|
class GameTime: public model::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~GameTime();
|
||||||
|
|
||||||
|
virtual model::Component* clone() override;
|
||||||
|
virtual void dump(unsigned level) override;
|
||||||
|
|
||||||
|
virtual void onUpdateLogic() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace components */
|
||||||
|
} /* namespace farmlands */
|
||||||
|
|
||||||
|
#endif /* COMPONENTS_GAMETIME_H_ */
|
@ -139,6 +139,11 @@ void Grid::set(model::GameObject* obj, int x, int y, bool throwOnOverwrite)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_grid[index] = obj;
|
m_grid[index] = obj;
|
||||||
|
|
||||||
|
// Set transform as well
|
||||||
|
Transform* transf = obj->component<Transform>();
|
||||||
|
transf->x = x;
|
||||||
|
transf->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace basic */
|
} /* namespace basic */
|
||||||
|
@ -67,9 +67,9 @@ namespace basic {
|
|||||||
|
|
||||||
// Operations
|
// Operations
|
||||||
model::GameObject* get(int x, int y);
|
model::GameObject* get(int x, int y);
|
||||||
|
void set(model::GameObject* obj, int x, int y, bool throwOnOverwrite = true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set(model::GameObject* obj, int x, int y, bool throwOnOverwrite);
|
|
||||||
|
|
||||||
utils::Rect<int> m_bounds;
|
utils::Rect<int> m_bounds;
|
||||||
model::GameObject** m_grid;
|
model::GameObject** m_grid;
|
||||||
|
@ -64,7 +64,7 @@ void Sprite::dump(unsigned level)
|
|||||||
|
|
||||||
void Sprite::onPreRender()
|
void Sprite::onPreRender()
|
||||||
{
|
{
|
||||||
advanceTime(GameState::current().elapsedTime);
|
advanceTime(GameState::current().deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::addState(const SpriteState& state)
|
void Sprite::addState(const SpriteState& state)
|
||||||
|
@ -53,7 +53,7 @@ void Weapon::onUpdateLogic()
|
|||||||
{
|
{
|
||||||
if (attackTimeLeft > 0)
|
if (attackTimeLeft > 0)
|
||||||
{
|
{
|
||||||
attackTimeLeft -= GameState::current().elapsedTime;
|
attackTimeLeft -= GameState::current().deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
101
src/components/plants/Plant.cpp
Normal file
101
src/components/plants/Plant.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Plant.cpp
|
||||||
|
*
|
||||||
|
* Created on: Dec 9, 2016
|
||||||
|
* Author: tibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <GameState.h>
|
||||||
|
#include <components/plants/Plant.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace farmlands {
|
||||||
|
namespace components {
|
||||||
|
namespace plants {
|
||||||
|
|
||||||
|
Plant::Plant()
|
||||||
|
: needsWater(false),
|
||||||
|
daysWithoutWater(0),
|
||||||
|
maxDaysWithoutWater(2),
|
||||||
|
state(0),
|
||||||
|
stateDays(0),
|
||||||
|
stateLengths(),
|
||||||
|
m_sprite(nullptr)
|
||||||
|
{
|
||||||
|
// The age is set to 0xffffffff so that it is updated at the next 'update logic' call
|
||||||
|
}
|
||||||
|
|
||||||
|
Plant::~Plant()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
model::Component* Plant::clone()
|
||||||
|
{
|
||||||
|
Plant* clone = new Plant();
|
||||||
|
clone->needsWater = needsWater;
|
||||||
|
clone->daysWithoutWater = daysWithoutWater;
|
||||||
|
clone->maxDaysWithoutWater = maxDaysWithoutWater;
|
||||||
|
clone->state = state;
|
||||||
|
clone->stateDays = stateDays;
|
||||||
|
clone->state = state;
|
||||||
|
std::copy(stateLengths.begin(), stateLengths.end(), std::back_inserter(clone->stateLengths));
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plant::dump(unsigned level)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < level; i++)
|
||||||
|
std::cout<<" ";
|
||||||
|
|
||||||
|
std::cout << " .Component: Plant\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plant::onInitialize()
|
||||||
|
{
|
||||||
|
m_sprite = gameObject->component<basic::Sprite>();
|
||||||
|
|
||||||
|
if (stateLengths.empty())
|
||||||
|
stateLengths.push_back(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plant::onUpdateLogic()
|
||||||
|
{
|
||||||
|
// At midnight, the plant grows
|
||||||
|
if (GameState::current().isMidnight)
|
||||||
|
{
|
||||||
|
stateDays++;
|
||||||
|
daysWithoutWater++;
|
||||||
|
|
||||||
|
// Exceeded plant's survival time without water
|
||||||
|
if (needsWater && daysWithoutWater > maxDaysWithoutWater)
|
||||||
|
die();
|
||||||
|
|
||||||
|
// Increment state
|
||||||
|
bool haveState = state < stateLengths.size();
|
||||||
|
bool isFinite = (stateLengths[state] != -1);
|
||||||
|
bool finishedState = stateDays >= (size_t)stateLengths[state];
|
||||||
|
|
||||||
|
if (haveState && isFinite && finishedState)
|
||||||
|
{
|
||||||
|
++state;
|
||||||
|
stateDays = 0;
|
||||||
|
m_sprite->setState(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plant::onWatered()
|
||||||
|
{
|
||||||
|
daysWithoutWater = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plant::die()
|
||||||
|
{
|
||||||
|
// TODO: implement plant death
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace plants */
|
||||||
|
} /* namespace components */
|
||||||
|
} /* namespace farmlands */
|
55
src/components/plants/Plant.h
Normal file
55
src/components/plants/Plant.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Plant.h
|
||||||
|
*
|
||||||
|
* Created on: Dec 9, 2016
|
||||||
|
* Author: tibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef COMPONENTS_PLANTS_PLANT_H_
|
||||||
|
#define COMPONENTS_PLANTS_PLANT_H_
|
||||||
|
|
||||||
|
#include <components/basic/Sprite.h>
|
||||||
|
#include <model/Component.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace farmlands {
|
||||||
|
namespace components {
|
||||||
|
namespace plants {
|
||||||
|
|
||||||
|
class Plant: public model::Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Plant();
|
||||||
|
virtual ~Plant();
|
||||||
|
|
||||||
|
virtual model::Component* clone() override;
|
||||||
|
virtual void dump(unsigned level) override;
|
||||||
|
|
||||||
|
virtual void onInitialize() override;
|
||||||
|
virtual void onUpdateLogic() override;
|
||||||
|
|
||||||
|
void onWatered();
|
||||||
|
void die();
|
||||||
|
|
||||||
|
bool needsWater; // Watering - if the plant needs water (trees don't need water).
|
||||||
|
uint32_t daysWithoutWater; // How many days passed since last watered
|
||||||
|
uint32_t maxDaysWithoutWater; // How many days the plant can survive without water
|
||||||
|
|
||||||
|
size_t state; // Current state
|
||||||
|
uint32_t stateDays; // How many days have elapsed since the last state change
|
||||||
|
|
||||||
|
// The length of each state, measured in days.
|
||||||
|
// After all the states are passed through, the plant dies; -1 means infinity
|
||||||
|
std::vector<int32_t> stateLengths;
|
||||||
|
|
||||||
|
private:
|
||||||
|
basic::Sprite* m_sprite;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace plants */
|
||||||
|
} /* namespace components */
|
||||||
|
} /* namespace farmlands */
|
||||||
|
|
||||||
|
#endif /* COMPONENTS_PLANTS_PLANT_H_ */
|
101
src/components/plants/Seed.cpp
Normal file
101
src/components/plants/Seed.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Seed.cpp
|
||||||
|
*
|
||||||
|
* Created on: Dec 6, 2016
|
||||||
|
* Author: tibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <GameState.h>
|
||||||
|
#include <assets/Ground.h>
|
||||||
|
#include <components/plants/Seed.h>
|
||||||
|
#include <components/Map.h>
|
||||||
|
#include <math/GameMath.h>
|
||||||
|
#include <model/GameObject.h>
|
||||||
|
#include <utils/Assert.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace farmlands::model;
|
||||||
|
|
||||||
|
namespace farmlands {
|
||||||
|
namespace components {
|
||||||
|
namespace plants {
|
||||||
|
|
||||||
|
Seed::Seed()
|
||||||
|
: plantName(),
|
||||||
|
m_plant(nullptr),
|
||||||
|
m_grid(nullptr),
|
||||||
|
m_map(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Seed::~Seed()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
model::Component* Seed::clone()
|
||||||
|
{
|
||||||
|
Seed* clone = new Seed();
|
||||||
|
clone->plantName = plantName;
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seed::dump(unsigned level)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < level; i++)
|
||||||
|
std::cout<<" ";
|
||||||
|
|
||||||
|
std::cout << " .Component: Seed plant=" << plantName <<"\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seed::onInitialize()
|
||||||
|
{
|
||||||
|
GameObject* root = &GameState::current().scene->root;
|
||||||
|
|
||||||
|
// Obtain pointer to plant
|
||||||
|
for (auto plant : GameState::current().plantsPrefabs)
|
||||||
|
if (plant->name == plantName)
|
||||||
|
m_plant = plant;
|
||||||
|
|
||||||
|
Assert (m_plant != nullptr, "Plant " + plantName + " is missing.");
|
||||||
|
|
||||||
|
// Obtain pointer to object layer & map
|
||||||
|
auto objIt = root->findByName("Object Layer");
|
||||||
|
Assert (objIt != root->childrenEnd(), "Can't find object layer.");
|
||||||
|
m_grid = (*objIt)->component<basic::Grid>();
|
||||||
|
|
||||||
|
auto mapIt = root->findByComponent<Map>();
|
||||||
|
Assert (mapIt != root->childrenEnd(), "Can't find map layer.");
|
||||||
|
m_map = (*mapIt)->component<Map>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Seed::performAction(float x, float y, model::Direction d)
|
||||||
|
{
|
||||||
|
// Compute planting position
|
||||||
|
float digX, digY;
|
||||||
|
translate(x, y, d, 0.5f, &digX, &digY);
|
||||||
|
|
||||||
|
size_t col = floorf(digX);
|
||||||
|
size_t row = floorf(digY);
|
||||||
|
|
||||||
|
// Soil is located on layer 1
|
||||||
|
Cell cell = m_map->layer(1).get(row, col);
|
||||||
|
bool isSoil = assets::groundIsSoil(cell);
|
||||||
|
|
||||||
|
bool isFree = (m_grid->get(col, row) == nullptr);
|
||||||
|
|
||||||
|
// Place plant
|
||||||
|
if (isSoil && isFree)
|
||||||
|
{
|
||||||
|
// Plant
|
||||||
|
auto inst = GameObject::instantiate(m_plant, plantName, m_grid->gameObject);
|
||||||
|
m_grid->set(inst, col, row);
|
||||||
|
|
||||||
|
std::cout << "Planted " << plantName << " at " << col <<", " << row <<"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace plants */
|
||||||
|
} /* namespace components */
|
||||||
|
} /* namespace farmlands */
|
45
src/components/plants/Seed.h
Normal file
45
src/components/plants/Seed.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Seed.h
|
||||||
|
*
|
||||||
|
* Created on: Dec 6, 2016
|
||||||
|
* Author: tibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef COMPONENTS_ITEMS_SEED_H_
|
||||||
|
#define COMPONENTS_ITEMS_SEED_H_
|
||||||
|
|
||||||
|
#include <components/basic/Grid.h>
|
||||||
|
#include <components/items/IPlayerAction.h>
|
||||||
|
#include <components/Map.h>
|
||||||
|
#include <model/Component.h>
|
||||||
|
|
||||||
|
namespace farmlands {
|
||||||
|
namespace components {
|
||||||
|
namespace plants {
|
||||||
|
|
||||||
|
class Seed: public model::Component, public items::IPlayerAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Seed();
|
||||||
|
virtual ~Seed();
|
||||||
|
|
||||||
|
virtual model::Component* clone() override;
|
||||||
|
virtual void dump(unsigned level) override;
|
||||||
|
|
||||||
|
virtual void onInitialize() override;
|
||||||
|
|
||||||
|
virtual void performAction(float x, float y, model::Direction d) override;
|
||||||
|
|
||||||
|
std::string plantName;
|
||||||
|
|
||||||
|
private:
|
||||||
|
model::GameObject* m_plant;
|
||||||
|
basic::Grid* m_grid;
|
||||||
|
Map* m_map;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace plants */
|
||||||
|
} /* namespace components */
|
||||||
|
} /* namespace farmlands */
|
||||||
|
|
||||||
|
#endif /* COMPONENTS_ITEMS_SEED_H_ */
|
@ -81,7 +81,7 @@ void PlayerMovement::onUpdateLogic()
|
|||||||
velMultiplier = PlayerRunVelocity;
|
velMultiplier = PlayerRunVelocity;
|
||||||
|
|
||||||
// Make movement time independent
|
// Make movement time independent
|
||||||
velMultiplier *= GameState::current().elapsedTime;
|
velMultiplier *= GameState::current().deltaTime;
|
||||||
|
|
||||||
// Get velocity of axes
|
// Get velocity of axes
|
||||||
float vx = Input::instance().getX() * velMultiplier;
|
float vx = Input::instance().getX() * velMultiplier;
|
||||||
|
@ -113,7 +113,7 @@ int FarmlandsGame::run()
|
|||||||
{
|
{
|
||||||
// Update elapsed time
|
// Update elapsed time
|
||||||
Uint32 now = SDL_GetTicks();
|
Uint32 now = SDL_GetTicks();
|
||||||
GameState::current().elapsedTime = (now - m_time) * 0.001f;
|
GameState::current().deltaTime = (now - m_time) * 0.001f;
|
||||||
m_time = now;
|
m_time = now;
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -87,6 +87,9 @@ void ResourceManager::loadGame()
|
|||||||
storage::parseCollection(R::Items::Tools, GameState::current().itemPrefabs);
|
storage::parseCollection(R::Items::Tools, GameState::current().itemPrefabs);
|
||||||
storage::parseCollection(R::Items::Weapons, GameState::current().itemPrefabs);
|
storage::parseCollection(R::Items::Weapons, GameState::current().itemPrefabs);
|
||||||
|
|
||||||
|
storage::parseCollection(R::Plants::Plantable, GameState::current().plantsPrefabs);
|
||||||
|
storage::parseCollection(R::Plants::Seeds, GameState::current().seedsPrefabs);
|
||||||
|
|
||||||
// Get to "Inventory" object
|
// Get to "Inventory" object
|
||||||
model::GameObject* root = &GameState::current().scene->root;
|
model::GameObject* root = &GameState::current().scene->root;
|
||||||
model::GameObject* player = *root->findByName("Player");
|
model::GameObject* player = *root->findByName("Player");
|
||||||
@ -95,6 +98,9 @@ void ResourceManager::loadGame()
|
|||||||
// Give player all items
|
// Give player all items
|
||||||
for (auto prefab : GameState::current().itemPrefabs)
|
for (auto prefab : GameState::current().itemPrefabs)
|
||||||
model::GameObject::instantiate(prefab, "inv item", inventory);
|
model::GameObject::instantiate(prefab, "inv item", inventory);
|
||||||
|
|
||||||
|
for (auto prefab : GameState::current().seedsPrefabs)
|
||||||
|
model::GameObject::instantiate(prefab, "inv seed", inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ResourceManager::getPath(ResourceId resourceId)
|
std::string ResourceManager::getPath(ResourceId resourceId)
|
||||||
|
@ -28,45 +28,52 @@ namespace resources {
|
|||||||
{
|
{
|
||||||
Game = 9,
|
Game = 9,
|
||||||
};
|
};
|
||||||
|
enum Plants
|
||||||
|
{
|
||||||
|
Seeds = 10,
|
||||||
|
Plantable = 11,
|
||||||
|
graphics_Ugliceea = 12,
|
||||||
|
};
|
||||||
|
enum Maps
|
||||||
|
{
|
||||||
|
Farm_Background = 13,
|
||||||
|
Farm = 14,
|
||||||
|
Farm_Soil = 15,
|
||||||
|
};
|
||||||
enum Fonts
|
enum Fonts
|
||||||
{
|
{
|
||||||
DejaVuSans = 10,
|
DejaVuSans = 16,
|
||||||
};
|
};
|
||||||
enum Tilesets
|
enum Tilesets
|
||||||
{
|
{
|
||||||
PlayerTiles = 11,
|
PlayerTiles = 17,
|
||||||
Ground = 12,
|
Ground = 18,
|
||||||
};
|
};
|
||||||
enum Ui
|
enum Ui
|
||||||
{
|
{
|
||||||
Mini_inventory = 13,
|
Mini_inventory = 19,
|
||||||
Cursor = 14,
|
Cursor = 20,
|
||||||
};
|
|
||||||
enum Levels
|
|
||||||
{
|
|
||||||
Farm_Background = 15,
|
|
||||||
Farm = 16,
|
|
||||||
Farm_Soil = 17,
|
|
||||||
};
|
};
|
||||||
enum Config
|
enum Config
|
||||||
{
|
{
|
||||||
Default = 18,
|
Default = 21,
|
||||||
};
|
};
|
||||||
enum Items
|
enum Items
|
||||||
{
|
{
|
||||||
Tools = 19,
|
Tools = 22,
|
||||||
Weapons = 20,
|
Weapons = 23,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const int RInfo_Sprites_Begin = 0;
|
const int RInfo_Sprites_Begin = 0;
|
||||||
const int RInfo_Scenes_Begin = 9;
|
const int RInfo_Scenes_Begin = 9;
|
||||||
const int RInfo_Fonts_Begin = 10;
|
const int RInfo_Plants_Begin = 10;
|
||||||
const int RInfo_Tilesets_Begin = 11;
|
const int RInfo_Maps_Begin = 13;
|
||||||
const int RInfo_Ui_Begin = 13;
|
const int RInfo_Fonts_Begin = 16;
|
||||||
const int RInfo_Levels_Begin = 15;
|
const int RInfo_Tilesets_Begin = 17;
|
||||||
const int RInfo_Config_Begin = 18;
|
const int RInfo_Ui_Begin = 19;
|
||||||
const int RInfo_Items_Begin = 19;
|
const int RInfo_Config_Begin = 21;
|
||||||
|
const int RInfo_Items_Begin = 22;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This array contains the names of all the files, and the corresponding file type.
|
* This array contains the names of all the files, and the corresponding file type.
|
||||||
@ -82,14 +89,17 @@ namespace resources {
|
|||||||
{ "sprites/items/sword.png", ResourceType::Texture },
|
{ "sprites/items/sword.png", ResourceType::Texture },
|
||||||
{ "sprites/items/hoe.png", ResourceType::Texture },
|
{ "sprites/items/hoe.png", ResourceType::Texture },
|
||||||
{ "scenes/Game.scene", ResourceType::Scene },
|
{ "scenes/Game.scene", ResourceType::Scene },
|
||||||
|
{ "plants/Seeds.xml", ResourceType::None },
|
||||||
|
{ "plants/Plantable.xml", ResourceType::None },
|
||||||
|
{ "plants/graphics/Ugliceea.png", ResourceType::Texture },
|
||||||
|
{ "maps/Farm_Background.csv", ResourceType::MapLayer },
|
||||||
|
{ "maps/Farm.map", ResourceType::None },
|
||||||
|
{ "maps/Farm_Soil.csv", ResourceType::MapLayer },
|
||||||
{ "fonts/DejaVuSans.ttf", ResourceType::Font },
|
{ "fonts/DejaVuSans.ttf", ResourceType::Font },
|
||||||
{ "tilesets/PlayerTiles.png", ResourceType::Texture },
|
{ "tilesets/PlayerTiles.png", ResourceType::Texture },
|
||||||
{ "tilesets/Ground.png", ResourceType::Texture },
|
{ "tilesets/Ground.png", ResourceType::Texture },
|
||||||
{ "ui/mini_inventory.png", ResourceType::Texture },
|
{ "ui/mini_inventory.png", ResourceType::Texture },
|
||||||
{ "ui/cursor.png", ResourceType::Texture },
|
{ "ui/cursor.png", ResourceType::Texture },
|
||||||
{ "levels/Farm_Background.csv", ResourceType::MapLayer },
|
|
||||||
{ "levels/Farm.back", ResourceType::Map },
|
|
||||||
{ "levels/Farm_Soil.csv", ResourceType::MapLayer },
|
|
||||||
{ "config/Default.config", ResourceType::Configuration },
|
{ "config/Default.config", ResourceType::Configuration },
|
||||||
{ "items/Tools.items", ResourceType::ItemCollection },
|
{ "items/Tools.items", ResourceType::ItemCollection },
|
||||||
{ "items/Weapons.items", ResourceType::ItemCollection },
|
{ "items/Weapons.items", ResourceType::ItemCollection },
|
||||||
|
@ -53,7 +53,7 @@ void parseMapCells(resources::ResourceId cellsResource, components::Map* map, co
|
|||||||
template <>
|
template <>
|
||||||
components::Map* parse<components::Map> (boost::property_tree::ptree& root)
|
components::Map* parse<components::Map> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Map")
|
if (root.front().first == "Map")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -90,9 +90,12 @@ components::Map* parse<components::Map> (boost::property_tree::ptree& root)
|
|||||||
delete tileSet;
|
delete tileSet;
|
||||||
|
|
||||||
// Read cells
|
// Read cells
|
||||||
std::string cellsPath = layerNode.second.get<std::string>("<xmlattr>.cells");
|
std::string cellsPath = layerNode.second.get<std::string>("<xmlattr>.cells", "");
|
||||||
resources::ResourceId cellsId = resources::ResourceManager::instance().getId(cellsPath);
|
if (!cellsPath.empty())
|
||||||
parseMapCells(cellsId, map, layer);
|
{
|
||||||
|
resources::ResourceId cellsId = resources::ResourceManager::instance().getId(cellsPath);
|
||||||
|
parseMapCells(cellsId, map, layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -115,7 +118,7 @@ components::basic::Camera* parse<components::basic::Camera> (boost::property_tre
|
|||||||
template <>
|
template <>
|
||||||
components::basic::Frame* parse<components::basic::Frame> (boost::property_tree::ptree& root)
|
components::basic::Frame* parse<components::basic::Frame> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Frame")
|
if (root.front().first == "Frame")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -138,7 +141,7 @@ components::basic::Frame* parse<components::basic::Frame> (boost::property_tree:
|
|||||||
template <>
|
template <>
|
||||||
components::basic::Grid* parse<components::basic::Grid> (boost::property_tree::ptree& root)
|
components::basic::Grid* parse<components::basic::Grid> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Grid")
|
if (root.front().first == "Grid")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -158,7 +161,7 @@ components::basic::Grid* parse<components::basic::Grid> (boost::property_tree::p
|
|||||||
template <>
|
template <>
|
||||||
components::basic::Sprite* parse<components::basic::Sprite> (boost::property_tree::ptree& root)
|
components::basic::Sprite* parse<components::basic::Sprite> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Sprite")
|
if (root.front().first == "Sprite")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -192,7 +195,7 @@ components::basic::Sprite* parse<components::basic::Sprite> (boost::property_tre
|
|||||||
template <>
|
template <>
|
||||||
components::basic::SpriteState* parse<components::basic::SpriteState> (boost::property_tree::ptree& root)
|
components::basic::SpriteState* parse<components::basic::SpriteState> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "SpriteState")
|
if (root.front().first == "SpriteState")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -215,7 +218,7 @@ components::basic::SpriteState* parse<components::basic::SpriteState> (boost::pr
|
|||||||
template <>
|
template <>
|
||||||
components::basic::Transform* parse<components::basic::Transform> (boost::property_tree::ptree& root)
|
components::basic::Transform* parse<components::basic::Transform> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Transform")
|
if (root.front().first == "Transform")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -231,7 +234,7 @@ components::basic::Transform* parse<components::basic::Transform> (boost::proper
|
|||||||
template <>
|
template <>
|
||||||
components::DebugController* parse<components::DebugController> (boost::property_tree::ptree& root)
|
components::DebugController* parse<components::DebugController> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "DebugController")
|
if (root.front().first == "DebugController")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -239,10 +242,21 @@ components::DebugController* parse<components::DebugController> (boost::property
|
|||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
components::GameTime* parse<components::GameTime> (boost::property_tree::ptree& root)
|
||||||
|
{
|
||||||
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
|
if (root.front().first == "GameTime")
|
||||||
|
root = root.front().second;
|
||||||
|
|
||||||
|
components::GameTime* gameTime = new components::GameTime();
|
||||||
|
return gameTime;
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
components::items::Axe* parse<components::items::Axe> (boost::property_tree::ptree& root)
|
components::items::Axe* parse<components::items::Axe> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Axe")
|
if (root.front().first == "Axe")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -253,7 +267,7 @@ components::items::Axe* parse<components::items::Axe> (boost::property_tree::ptr
|
|||||||
template <>
|
template <>
|
||||||
components::items::Giftable* parse<components::items::Giftable> (boost::property_tree::ptree& root)
|
components::items::Giftable* parse<components::items::Giftable> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Giftable")
|
if (root.front().first == "Giftable")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -264,7 +278,7 @@ components::items::Giftable* parse<components::items::Giftable> (boost::property
|
|||||||
template <>
|
template <>
|
||||||
components::items::Hoe* parse<components::items::Hoe> (boost::property_tree::ptree& root)
|
components::items::Hoe* parse<components::items::Hoe> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Hoe")
|
if (root.front().first == "Hoe")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -275,7 +289,7 @@ components::items::Hoe* parse<components::items::Hoe> (boost::property_tree::ptr
|
|||||||
template <>
|
template <>
|
||||||
components::items::Item* parse<components::items::Item> (boost::property_tree::ptree& root)
|
components::items::Item* parse<components::items::Item> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Item")
|
if (root.front().first == "Item")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -283,7 +297,7 @@ components::items::Item* parse<components::items::Item> (boost::property_tree::p
|
|||||||
components::items::Item* item = new components::items::Item();
|
components::items::Item* item = new components::items::Item();
|
||||||
item->name = root.get<std::string>("<xmlattr>.name");
|
item->name = root.get<std::string>("<xmlattr>.name");
|
||||||
item->description = root.get<std::string>("<xmlattr>.description");
|
item->description = root.get<std::string>("<xmlattr>.description");
|
||||||
item->level = root.get<uint8_t>("<xmlattr>.level");
|
item->level = root.get<uint8_t>("<xmlattr>.level", 1);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +305,7 @@ components::items::Item* parse<components::items::Item> (boost::property_tree::p
|
|||||||
template <>
|
template <>
|
||||||
components::items::Pickaxe* parse<components::items::Pickaxe> (boost::property_tree::ptree& root)
|
components::items::Pickaxe* parse<components::items::Pickaxe> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Pickaxe")
|
if (root.front().first == "Pickaxe")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -302,7 +316,7 @@ components::items::Pickaxe* parse<components::items::Pickaxe> (boost::property_t
|
|||||||
template <>
|
template <>
|
||||||
components::items::Scythe* parse<components::items::Scythe> (boost::property_tree::ptree& root)
|
components::items::Scythe* parse<components::items::Scythe> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Pickaxe")
|
if (root.front().first == "Pickaxe")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -313,7 +327,7 @@ components::items::Scythe* parse<components::items::Scythe> (boost::property_tre
|
|||||||
template <>
|
template <>
|
||||||
components::items::WateringCan* parse<components::items::WateringCan> (boost::property_tree::ptree& root)
|
components::items::WateringCan* parse<components::items::WateringCan> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "WateringCan")
|
if (root.front().first == "WateringCan")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -328,7 +342,7 @@ components::items::WateringCan* parse<components::items::WateringCan> (boost::pr
|
|||||||
template <>
|
template <>
|
||||||
components::items::Weapon* parse<components::items::Weapon> (boost::property_tree::ptree& root)
|
components::items::Weapon* parse<components::items::Weapon> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Weapon")
|
if (root.front().first == "Weapon")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -341,10 +355,48 @@ components::items::Weapon* parse<components::items::Weapon> (boost::property_tre
|
|||||||
return weapon;
|
return weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
components::plants::Plant* parse<components::plants::Plant> (boost::property_tree::ptree& root)
|
||||||
|
{
|
||||||
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
|
if (root.front().first == "Plant")
|
||||||
|
root = root.front().second;
|
||||||
|
|
||||||
|
// Parse
|
||||||
|
components::plants::Plant* plant = new components::plants::Plant();
|
||||||
|
plant->needsWater = root.get<bool>("<xmlattr>.needsWater");
|
||||||
|
plant->daysWithoutWater = root.get<uint32_t>("<xmlattr>.daysWithoutWater", 0);
|
||||||
|
plant->maxDaysWithoutWater = root.get<uint32_t>("<xmlattr>.maxDaysWithoutWater", 2);
|
||||||
|
plant->state = root.get<size_t>("<xmlattr>.state", 0);
|
||||||
|
plant->stateDays = root.get<uint32_t>("<xmlattr>.stateDays", 0);
|
||||||
|
|
||||||
|
for (auto child : root)
|
||||||
|
if (child.first == "State")
|
||||||
|
{
|
||||||
|
int32_t length = child.second.get<int32_t>("<xmlattr>.len", -1);
|
||||||
|
plant->stateLengths.push_back(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return plant;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
components::plants::Seed* parse<components::plants::Seed> (boost::property_tree::ptree& root)
|
||||||
|
{
|
||||||
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
|
if (root.front().first == "Seed")
|
||||||
|
root = root.front().second;
|
||||||
|
|
||||||
|
// Parse
|
||||||
|
components::plants::Seed* seed = new components::plants::Seed();
|
||||||
|
seed->plantName = root.get<std::string>("<xmlattr>.plantName");
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
components::player::PlayerInventory* parse<components::player::PlayerInventory> (boost::property_tree::ptree& root)
|
components::player::PlayerInventory* parse<components::player::PlayerInventory> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "PlayerInventory")
|
if (root.front().first == "PlayerInventory")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -358,7 +410,7 @@ components::player::PlayerInventory* parse<components::player::PlayerInventory>
|
|||||||
template <>
|
template <>
|
||||||
components::player::PlayerMovement* parse<components::player::PlayerMovement> (boost::property_tree::ptree& root)
|
components::player::PlayerMovement* parse<components::player::PlayerMovement> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "PlayerMovement")
|
if (root.front().first == "PlayerMovement")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -374,7 +426,7 @@ components::player::PlayerMovement* parse<components::player::PlayerMovement> (b
|
|||||||
template <>
|
template <>
|
||||||
graphics::MapRenderer* parse<graphics::MapRenderer> (boost::property_tree::ptree& root)
|
graphics::MapRenderer* parse<graphics::MapRenderer> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "MapRenderer")
|
if (root.front().first == "MapRenderer")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -385,7 +437,7 @@ graphics::MapRenderer* parse<graphics::MapRenderer> (boost::property_tree::ptree
|
|||||||
template <>
|
template <>
|
||||||
graphics::SpriteRenderer* parse<graphics::SpriteRenderer> (boost::property_tree::ptree& root)
|
graphics::SpriteRenderer* parse<graphics::SpriteRenderer> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "SpriteRenderer")
|
if (root.front().first == "SpriteRenderer")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -399,7 +451,7 @@ graphics::SpriteRenderer* parse<graphics::SpriteRenderer> (boost::property_tree:
|
|||||||
template <>
|
template <>
|
||||||
model::GameObject* parse<model::GameObject> (boost::property_tree::ptree& root)
|
model::GameObject* parse<model::GameObject> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "GameObject")
|
if (root.front().first == "GameObject")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -418,6 +470,9 @@ model::GameObject* parse<model::GameObject> (boost::property_tree::ptree& root)
|
|||||||
else if (child.first == "Camera")
|
else if (child.first == "Camera")
|
||||||
gameObj->addComponent(parse<components::basic::Camera>(child.second));
|
gameObj->addComponent(parse<components::basic::Camera>(child.second));
|
||||||
|
|
||||||
|
else if (child.first == "Grid")
|
||||||
|
gameObj->addComponent(parse<components::basic::Grid>(child.second));
|
||||||
|
|
||||||
else if (child.first == "Sprite")
|
else if (child.first == "Sprite")
|
||||||
gameObj->addComponent(parse<components::basic::Sprite>(child.second));
|
gameObj->addComponent(parse<components::basic::Sprite>(child.second));
|
||||||
|
|
||||||
@ -449,6 +504,13 @@ model::GameObject* parse<model::GameObject> (boost::property_tree::ptree& root)
|
|||||||
else if (child.first == "Weapon")
|
else if (child.first == "Weapon")
|
||||||
gameObj->addComponent(parse<components::items::Weapon>(child.second));
|
gameObj->addComponent(parse<components::items::Weapon>(child.second));
|
||||||
|
|
||||||
|
// Components::plants
|
||||||
|
else if (child.first == "Plant")
|
||||||
|
gameObj->addComponent(parse<components::plants::Plant>(child.second));
|
||||||
|
|
||||||
|
else if (child.first == "Seed")
|
||||||
|
gameObj->addComponent(parse<components::plants::Seed>(child.second));
|
||||||
|
|
||||||
// Components::player
|
// Components::player
|
||||||
else if (child.first == "PlayerInventory")
|
else if (child.first == "PlayerInventory")
|
||||||
gameObj->addComponent(parse<components::player::PlayerInventory>(child.second));
|
gameObj->addComponent(parse<components::player::PlayerInventory>(child.second));
|
||||||
@ -457,12 +519,15 @@ model::GameObject* parse<model::GameObject> (boost::property_tree::ptree& root)
|
|||||||
gameObj->addComponent(parse<components::player::PlayerMovement>(child.second));
|
gameObj->addComponent(parse<components::player::PlayerMovement>(child.second));
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
else if (child.first == "Map")
|
|
||||||
gameObj->addComponent(parse<components::Map>(child.second));
|
|
||||||
|
|
||||||
else if (child.first == "DebugController")
|
else if (child.first == "DebugController")
|
||||||
gameObj->addComponent(parse<components::DebugController>(child.second));
|
gameObj->addComponent(parse<components::DebugController>(child.second));
|
||||||
|
|
||||||
|
else if (child.first == "GameTime")
|
||||||
|
gameObj->addComponent(parse<components::GameTime>(child.second));
|
||||||
|
|
||||||
|
else if (child.first == "Map")
|
||||||
|
gameObj->addComponent(parse<components::Map>(child.second));
|
||||||
|
|
||||||
// Graphics
|
// Graphics
|
||||||
else if (child.first == "MapRenderer")
|
else if (child.first == "MapRenderer")
|
||||||
gameObj->addComponent(parse<graphics::MapRenderer>(child.second));
|
gameObj->addComponent(parse<graphics::MapRenderer>(child.second));
|
||||||
@ -479,7 +544,7 @@ model::GameObject* parse<model::GameObject> (boost::property_tree::ptree& root)
|
|||||||
template <>
|
template <>
|
||||||
model::Configuration* parse<model::Configuration> (boost::property_tree::ptree& root)
|
model::Configuration* parse<model::Configuration> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Configuration")
|
if (root.front().first == "Configuration")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -492,7 +557,7 @@ model::Configuration* parse<model::Configuration> (boost::property_tree::ptree&
|
|||||||
template <>
|
template <>
|
||||||
model::Scene* parse<model::Scene> (boost::property_tree::ptree& root)
|
model::Scene* parse<model::Scene> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "Scene")
|
if (root.front().first == "Scene")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
@ -515,7 +580,7 @@ model::Scene* parse<model::Scene> (boost::property_tree::ptree& root)
|
|||||||
template<>
|
template<>
|
||||||
model::TileSet* parse<model::TileSet> (boost::property_tree::ptree& root)
|
model::TileSet* parse<model::TileSet> (boost::property_tree::ptree& root)
|
||||||
{
|
{
|
||||||
// Ensure we are on the model::Scene node (property tree seems to add root of its own)
|
// Ensure we are on the correct node (property tree seems to add root of its own)
|
||||||
if (root.front().first == "TileSet")
|
if (root.front().first == "TileSet")
|
||||||
root = root.front().second;
|
root = root.front().second;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <components/basic/Sprite.h>
|
#include <components/basic/Sprite.h>
|
||||||
#include <components/basic/Transform.h>
|
#include <components/basic/Transform.h>
|
||||||
#include <components/DebugController.h>
|
#include <components/DebugController.h>
|
||||||
|
#include <components/GameTime.h>
|
||||||
#include <components/items/Axe.h>
|
#include <components/items/Axe.h>
|
||||||
#include <components/items/Giftable.h>
|
#include <components/items/Giftable.h>
|
||||||
#include <components/items/Hoe.h>
|
#include <components/items/Hoe.h>
|
||||||
@ -22,6 +23,8 @@
|
|||||||
#include <components/items/WateringCan.h>
|
#include <components/items/WateringCan.h>
|
||||||
#include <components/items/Weapon.h>
|
#include <components/items/Weapon.h>
|
||||||
#include <components/Map.h>
|
#include <components/Map.h>
|
||||||
|
#include <components/plants/Plant.h>
|
||||||
|
#include <components/plants/Seed.h>
|
||||||
#include <components/player/PlayerInventory.h>
|
#include <components/player/PlayerInventory.h>
|
||||||
#include <components/player/PlayerMovement.h>
|
#include <components/player/PlayerMovement.h>
|
||||||
#include <graphics/MapRenderer.h>
|
#include <graphics/MapRenderer.h>
|
||||||
@ -62,6 +65,9 @@ namespace storage {
|
|||||||
template <>
|
template <>
|
||||||
components::DebugController* parse<components::DebugController> (boost::property_tree::ptree& root);
|
components::DebugController* parse<components::DebugController> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
components::GameTime* parse<components::GameTime> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
components::items::Axe* parse<components::items::Axe> (boost::property_tree::ptree& root);
|
components::items::Axe* parse<components::items::Axe> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
@ -86,6 +92,12 @@ namespace storage {
|
|||||||
template <>
|
template <>
|
||||||
components::items::Weapon* parse<components::items::Weapon> (boost::property_tree::ptree& root);
|
components::items::Weapon* parse<components::items::Weapon> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
components::plants::Plant* parse<components::plants::Plant> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
components::plants::Seed* parse<components::plants::Seed> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
components::player::PlayerInventory* parse<components::player::PlayerInventory> (boost::property_tree::ptree& root);
|
components::player::PlayerInventory* parse<components::player::PlayerInventory> (boost::property_tree::ptree& root);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user