Rename to GameDB and GameDB::Level.
This commit is contained in:
parent
c46927ea10
commit
a20d701096
23 changed files with 142 additions and 151 deletions
|
@ -7,9 +7,9 @@ template<typename Comp>
|
|||
int number_left() {
|
||||
int count = 0;
|
||||
|
||||
Game::current_world()->query<components::Position, Comp>(
|
||||
GameDB::current_world()->query<components::Position, Comp>(
|
||||
[&](const auto ent, auto&, auto&) {
|
||||
if(ent != Game::current().player) {
|
||||
if(ent != GameDB::current().player) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
|
@ -19,15 +19,15 @@ int number_left() {
|
|||
|
||||
template<typename Comp>
|
||||
Pathing compute_paths() {
|
||||
auto& walls_original = Game::current().map->$walls;
|
||||
auto& walls_original = GameDB::current().map->$walls;
|
||||
auto walls_copy = walls_original;
|
||||
|
||||
Pathing paths{matrix::width(walls_copy), matrix::height(walls_copy)};
|
||||
|
||||
Game::current().world->query<components::Position>(
|
||||
GameDB::current().world->query<components::Position>(
|
||||
[&](const auto ent, auto& position) {
|
||||
if(ent != Game::current().player) {
|
||||
if(Game::current().world->has<Comp>(ent)) {
|
||||
if(ent != GameDB::current().player) {
|
||||
if(GameDB::current().world->has<Comp>(ent)) {
|
||||
paths.set_target(position.location);
|
||||
} else {
|
||||
// this will mark that spot as a wall so we don't path there temporarily
|
||||
|
@ -89,7 +89,7 @@ void Autowalker::process_combat() {
|
|||
}
|
||||
|
||||
Point Autowalker::get_current_position() {
|
||||
return Game::player_position().location;
|
||||
return GameDB::player_position().location;
|
||||
}
|
||||
|
||||
void Autowalker::path_fail(Matrix& bad_paths, Point pos) {
|
||||
|
@ -110,7 +110,7 @@ bool Autowalker::path_player(Pathing& paths, Point& target_out) {
|
|||
}
|
||||
}
|
||||
|
||||
if(!Game::current().map->can_move(target_out)) {
|
||||
if(!GameDB::current().map->can_move(target_out)) {
|
||||
path_fail(paths.$paths, target_out);
|
||||
return false;
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void Autowalker::process_move(Pathing& paths) {
|
|||
// what are we aiming at?
|
||||
auto aimed_at = fsm.$main_ui.camera_aim();
|
||||
|
||||
if(aimed_at && Game::current_world()->has<components::InventoryItem>(aimed_at)) {
|
||||
if(aimed_at && GameDB::current_world()->has<components::InventoryItem>(aimed_at)) {
|
||||
// NOTE: if we're aiming at an item then pick it up
|
||||
// for now just loot it then close to get it off the map
|
||||
send_event(gui::Event::LOOT_ITEM);
|
||||
|
@ -349,8 +349,8 @@ void Autowalker::send_event(gui::Event ev) {
|
|||
}
|
||||
|
||||
bool Autowalker::player_health_good() {
|
||||
auto world = Game::current_world();
|
||||
auto combat = world->get<components::Combat>(Game::the_player());
|
||||
auto world = GameDB::current_world();
|
||||
auto combat = world->get<components::Combat>(GameDB::the_player());
|
||||
return float(combat.hp) / float(combat.max_hp) > 0.5f;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,6 @@ struct LevelScaling {
|
|||
int map_height=20;
|
||||
};
|
||||
|
||||
struct LevelManager {
|
||||
public:
|
||||
std::vector<GameLevel> levels;
|
||||
size_t current_level = 0;
|
||||
};
|
||||
|
||||
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
|
||||
{
|
||||
auto world = make_shared<DinkyECS::World>();
|
||||
|
@ -35,10 +29,16 @@ inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World>
|
|||
return world;
|
||||
}
|
||||
|
||||
namespace Game {
|
||||
namespace GameDB {
|
||||
using std::shared_ptr, std::string, std::make_shared;
|
||||
|
||||
shared_ptr<LevelManager> LMGR;
|
||||
struct LevelDB {
|
||||
public:
|
||||
std::vector<GameDB::Level> levels;
|
||||
size_t current_level = 0;
|
||||
};
|
||||
|
||||
shared_ptr<LevelDB> LDB;
|
||||
bool initialized = false;
|
||||
|
||||
void init() {
|
||||
|
@ -46,7 +46,7 @@ namespace Game {
|
|||
textures::init();
|
||||
|
||||
if(!initialized) {
|
||||
LMGR = make_shared<LevelManager>();
|
||||
LDB = make_shared<LevelDB>();
|
||||
initialized = true;
|
||||
new_level(NULL);
|
||||
}
|
||||
|
@ -54,18 +54,18 @@ namespace Game {
|
|||
|
||||
LevelScaling scale_level() {
|
||||
return {
|
||||
INITIAL_MAP_W + int(LMGR->current_level * 2),
|
||||
INITIAL_MAP_H + int(LMGR->current_level * 2)
|
||||
INITIAL_MAP_W + int(LDB->current_level * 2),
|
||||
INITIAL_MAP_H + int(LDB->current_level * 2)
|
||||
};
|
||||
}
|
||||
|
||||
shared_ptr<DinkyECS::World> current_world() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return current().world;
|
||||
}
|
||||
|
||||
shared_ptr<gui::BossFightUI> create_bossfight() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto prev_world = current_world();
|
||||
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
|
||||
auto world = clone_load_world(prev_world);
|
||||
|
@ -73,7 +73,7 @@ namespace Game {
|
|||
|
||||
// BUG: the jank is too strong here
|
||||
auto boss_names = config.bosses.keys();
|
||||
auto& level_name = boss_names[LMGR->current_level % boss_names.size()];
|
||||
auto& level_name = boss_names[LDB->current_level % boss_names.size()];
|
||||
auto& boss_data = config.bosses[level_name];
|
||||
|
||||
auto boss_id = world->entity();
|
||||
|
@ -83,7 +83,7 @@ namespace Game {
|
|||
}
|
||||
|
||||
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto world = clone_load_world(prev_world);
|
||||
|
||||
auto scaling = scale_level();
|
||||
|
@ -94,71 +94,65 @@ namespace Game {
|
|||
WorldBuilder builder(*map, *collision);
|
||||
builder.generate(*world);
|
||||
|
||||
size_t index = LMGR->levels.size();
|
||||
size_t index = LDB->levels.size();
|
||||
|
||||
auto player = world->get_the<Player>();
|
||||
|
||||
LMGR->levels.emplace_back(index, player.entity, map, world,
|
||||
LDB->levels.emplace_back(index, player.entity, map, world,
|
||||
make_shared<LightRender>(map->tiles()), collision);
|
||||
|
||||
dbc::check(index == LMGR->levels.size() - 1, "Level index is not the same as LMGR->levels.size() - 1, off by one error");
|
||||
dbc::check(index == LDB->levels.size() - 1, "Level index is not the same as LDB->levels.size() - 1, off by one error");
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
GameLevel& create_level() {
|
||||
Level& create_level() {
|
||||
dbc::log("current_level");
|
||||
size_t level = new_level(current_world());
|
||||
dbc::check(level == LMGR->current_level + 1, "new level index is wrong");
|
||||
dbc::check(level == LDB->current_level + 1, "new level index is wrong");
|
||||
auto& the_level = next();
|
||||
dbc::check(level == LMGR->current_level, "level didn't update?!");
|
||||
dbc::check(level == LDB->current_level, "level didn't update?!");
|
||||
return the_level;
|
||||
}
|
||||
|
||||
GameLevel &next() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(LMGR->current_level < LMGR->levels.size(), "attempt to get next level when at end");
|
||||
LMGR->current_level++;
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
Level &next() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
dbc::check(LDB->current_level < LDB->levels.size(), "attempt to get next level when at end");
|
||||
LDB->current_level++;
|
||||
return LDB->levels.at(LDB->current_level);
|
||||
}
|
||||
|
||||
GameLevel &previous() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(LMGR->current_level > 0, "attempt to go to previous level when at 0");
|
||||
LMGR->current_level--;
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
Level &previous() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
dbc::check(LDB->current_level > 0, "attempt to go to previous level when at 0");
|
||||
LDB->current_level--;
|
||||
return LDB->levels.at(LDB->current_level);
|
||||
}
|
||||
|
||||
GameLevel ¤t() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LMGR->levels.at(LMGR->current_level);
|
||||
Level ¤t() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return LDB->levels.at(LDB->current_level);
|
||||
}
|
||||
|
||||
size_t current_index() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LMGR->current_level;
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return LDB->current_level;
|
||||
}
|
||||
|
||||
GameLevel &get(size_t index) {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
return LMGR->levels.at(index);
|
||||
}
|
||||
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named) {
|
||||
(void)named;
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::sentinel("THIS IS BROKEN");
|
||||
Level &get(size_t index) {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return LDB->levels.at(index);
|
||||
}
|
||||
|
||||
components::Position& player_position() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto world = current_world();
|
||||
auto& player = world->get_the<components::Player>();
|
||||
return world->get<components::Position>(player.entity);
|
||||
}
|
||||
|
||||
DinkyECS::Entity the_player() {
|
||||
dbc::check(initialized, "Forgot to call Game::init()");
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
return current().player;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,29 +12,28 @@ namespace components {
|
|||
struct Position;
|
||||
}
|
||||
|
||||
struct GameLevel {
|
||||
|
||||
namespace GameDB {
|
||||
struct Level {
|
||||
size_t index;
|
||||
DinkyECS::Entity player;
|
||||
std::shared_ptr<Map> map = nullptr;
|
||||
std::shared_ptr<DinkyECS::World> world = nullptr;
|
||||
std::shared_ptr<lighting::LightRender> lights = nullptr;
|
||||
std::shared_ptr<SpatialMap> collision = nullptr;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
namespace Game {
|
||||
std::shared_ptr<gui::BossFightUI> create_bossfight();
|
||||
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world);
|
||||
GameLevel& create_level();
|
||||
Level& create_level();
|
||||
|
||||
void init();
|
||||
GameLevel &next();
|
||||
GameLevel &previous();
|
||||
GameLevel ¤t();
|
||||
Level &next();
|
||||
Level &previous();
|
||||
Level ¤t();
|
||||
size_t current_index();
|
||||
std::shared_ptr<DinkyECS::World> current_world();
|
||||
GameLevel &get(size_t index);
|
||||
DinkyECS::Entity spawn_enemy(const std::string& named);
|
||||
Level &get(size_t index);
|
||||
components::Position& player_position();
|
||||
DinkyECS::Entity the_player();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void CombatUI::init() {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
using guecs::THEME;
|
||||
$gui.set<Background>($gui.MAIN, {$gui.$parser, THEME.DARK_MID});
|
||||
auto& the_belt = world->get_the<ritual::Belt>();
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace gui {
|
|||
|
||||
void DebugUI::render(sf::RenderWindow& window) {
|
||||
if(active) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto player = level.world->get_the<components::Player>();
|
||||
auto player_combat = level.world->get<components::Combat>(player.entity);
|
||||
auto map = level.map;
|
||||
|
@ -76,7 +76,7 @@ namespace gui {
|
|||
active = !active;
|
||||
|
||||
if(active) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
// it's on now, enable things
|
||||
auto player = level.world->get_the<components::Player>();
|
||||
auto& player_combat = level.world->get<components::Combat>(player.entity);
|
||||
|
|
16
gui/fsm.cpp
16
gui/fsm.cpp
|
@ -53,7 +53,7 @@ namespace gui {
|
|||
$combat_ui.init();
|
||||
$status_ui.init();
|
||||
|
||||
$boss_fight_ui = Game::create_bossfight();
|
||||
$boss_fight_ui = GameDB::create_bossfight();
|
||||
$boss_fight_ui->init();
|
||||
|
||||
$map_ui.init();
|
||||
|
@ -96,7 +96,7 @@ namespace gui {
|
|||
|
||||
void FSM::ROTATING(Event) {
|
||||
if(auto aim = $main_ui.play_rotate()) {
|
||||
auto& player_pos = Game::player_position();
|
||||
auto& player_pos = GameDB::player_position();
|
||||
player_pos.aiming_at = *aim;
|
||||
state(State::IDLE);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ namespace gui {
|
|||
|
||||
void FSM::COMBAT_ROTATE(Event) {
|
||||
if(auto aim = $main_ui.play_rotate()) {
|
||||
auto& player_pos = Game::player_position();
|
||||
auto& player_pos = GameDB::player_position();
|
||||
player_pos.aiming_at = *aim;
|
||||
state(State::IN_COMBAT);
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void FSM::try_move(int dir, bool strafe) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
using enum State;
|
||||
// prevent moving into occupied space
|
||||
Point move_to = $main_ui.plan_move(dir, strafe);
|
||||
|
@ -356,7 +356,7 @@ namespace gui {
|
|||
event(Event::LOOT_OPEN);
|
||||
break;
|
||||
case KEY::Z: {
|
||||
auto& player_pos = Game::player_position();
|
||||
auto& player_pos = GameDB::player_position();
|
||||
System::distribute_loot({player_pos.aiming_at});
|
||||
} break;
|
||||
case KEY::X:
|
||||
|
@ -430,7 +430,7 @@ namespace gui {
|
|||
|
||||
void FSM::handle_world_events() {
|
||||
using eGUI = Events::GUI;
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
|
||||
while(world->has_event<eGUI>()) {
|
||||
auto [evt, entity, data] = world->recv<eGUI>();
|
||||
|
@ -540,14 +540,14 @@ namespace gui {
|
|||
|
||||
void FSM::next_level() {
|
||||
dbc::log("current_level: Yep, next is called...");
|
||||
Game::create_level();
|
||||
GameDB::create_level();
|
||||
|
||||
$status_ui.update_level();
|
||||
$combat_ui.update_level();
|
||||
$main_ui.update_level();
|
||||
$loot_ui.update_level();
|
||||
|
||||
$boss_fight_ui = Game::create_bossfight();
|
||||
$boss_fight_ui = GameDB::create_bossfight();
|
||||
$boss_fight_ui->init();
|
||||
|
||||
run_systems();
|
||||
|
|
|
@ -5,14 +5,14 @@ namespace guecs {
|
|||
|
||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event) {
|
||||
return {[&, gui_id, event](auto){
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
world->send<Events::GUI>(event, gui_id, {});
|
||||
}};
|
||||
}
|
||||
|
||||
Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) {
|
||||
return {[&, event, data](auto){
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
world->send<Events::GUI>(event, gui_id, data);
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace gui {
|
|||
using namespace guecs;
|
||||
|
||||
LootUI::LootUI() :
|
||||
$temp_loot(Game::current_world()->entity()),
|
||||
$temp_loot(GameDB::current_world()->entity()),
|
||||
$target($temp_loot)
|
||||
{
|
||||
$gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200,
|
||||
|
@ -21,7 +21,7 @@ namespace gui {
|
|||
"[=item_12| =item_13|=item_14|=item_15 ]"
|
||||
"[ =take_all | =close| =destroy]");
|
||||
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
world->set<inventory::Model>($temp_loot, {});
|
||||
world->make_constant($temp_loot);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void LootUI::update() {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
|
||||
dbc::check(world->has<inventory::Model>($target),
|
||||
"update called but $target isn't in world");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::init() {
|
||||
auto& player_position = Game::player_position();
|
||||
auto& player_position = GameDB::player_position();
|
||||
auto player = player_position.location;
|
||||
|
||||
$rayview->init_shaders();
|
||||
|
@ -32,7 +32,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
DinkyECS::Entity MainUI::camera_aim() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
// what happens if there's two things at that spot
|
||||
if(level.collision->something_there($rayview->aiming_at)) {
|
||||
return level.collision->get($rayview->aiming_at);
|
||||
|
@ -90,7 +90,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::dead_entity(DinkyECS::Entity entity) {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
if(world->has<components::Sprite>(entity)) {
|
||||
auto &sprite = world->get<components::Sprite>(entity);
|
||||
$rayview->update_sprite(entity, sprite);
|
||||
|
@ -98,8 +98,8 @@ namespace gui {
|
|||
}
|
||||
|
||||
void MainUI::update_level() {
|
||||
auto& level = Game::current();
|
||||
auto& player_position = Game::player_position();
|
||||
auto& level = GameDB::current();
|
||||
auto& player_position = GameDB::player_position();
|
||||
auto player = player_position.location;
|
||||
|
||||
$rayview->update_level(level);
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace gui {
|
|||
bool $needs_render = true;
|
||||
sf::Clock $clock;
|
||||
sf::RenderWindow& $window;
|
||||
GameLevel $level;
|
||||
OverlayUI $overlay_ui;
|
||||
std::shared_ptr<Raycaster> $rayview;
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ namespace gui {
|
|||
$map_sprite($map_render->getTexture()),
|
||||
$map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT))
|
||||
{
|
||||
auto world = Game::current_world();
|
||||
auto player = Game::the_player();
|
||||
auto world = GameDB::current_world();
|
||||
auto player = GameDB::the_player();
|
||||
$player_display = world->get<Tile>(player).display;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace gui {
|
|||
|
||||
gui.set<Clickable>(area, {
|
||||
[&](auto) {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -185,8 +185,8 @@ namespace gui {
|
|||
}
|
||||
|
||||
void UI::complete_combine() {
|
||||
auto world = Game::current_world();
|
||||
auto player = Game::the_player();
|
||||
auto world = GameDB::current_world();
|
||||
auto player = GameDB::the_player();
|
||||
|
||||
if($craft_state.is_combined()) {
|
||||
auto ritual = $ritual_engine.finalize($craft_state);
|
||||
|
@ -249,7 +249,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
::ritual::Blanket& UI::blanket() {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
return world->get_the<::ritual::Blanket>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
void StatusUI::update() {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
auto player = world->get_the<components::Player>();
|
||||
auto& inventory = world->get<inventory::Model>(player.entity);
|
||||
|
||||
|
@ -112,7 +112,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& slot_name = $gui.name_for(gui_id);
|
||||
auto& inventory = level.world->get<inventory::Model>(level.player);
|
||||
|
||||
|
@ -133,7 +133,7 @@ namespace gui {
|
|||
|
||||
// NOTE: do I need this or how does it relate to drop_item?
|
||||
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
||||
auto player = Game::the_player();
|
||||
auto player = GameDB::the_player();
|
||||
auto& slot_name = $gui.name_for(slot_id);
|
||||
System::remove_from_container(player, slot_name);
|
||||
update();
|
||||
|
@ -141,7 +141,7 @@ namespace gui {
|
|||
|
||||
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
|
||||
if(gui_a != gui_b) {
|
||||
auto player = Game::the_player();
|
||||
auto player = GameDB::the_player();
|
||||
auto& a_name = $gui.name_for(gui_a);
|
||||
auto& b_name = $gui.name_for(gui_b);
|
||||
System::inventory_swap(player, a_name, b_name);
|
||||
|
@ -151,7 +151,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
bool StatusUI::occupied(guecs::Entity slot) {
|
||||
auto player = Game::the_player();
|
||||
auto player = GameDB::the_player();
|
||||
return System::inventory_occupied(player, $gui.name_for(slot));
|
||||
}
|
||||
}
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -16,7 +16,7 @@ int main(int argc, char* argv[]) {
|
|||
guecs::init(&backend);
|
||||
ai::init("assets/ai.json");
|
||||
animation::init();
|
||||
Game::init();
|
||||
GameDB::init();
|
||||
|
||||
if(DEBUG_BUILD) sound::mute(true);
|
||||
|
||||
|
|
|
@ -422,7 +422,7 @@ void Raycaster::update_sprite(DinkyECS::Entity ent, components::Sprite& sprite)
|
|||
$sprites.insert_or_assign(ent, sprite_txt);
|
||||
}
|
||||
|
||||
void Raycaster::update_level(GameLevel level) {
|
||||
void Raycaster::update_level(GameDB::Level& level) {
|
||||
$sprites.clear();
|
||||
$sprite_order.clear();
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ struct Raycaster {
|
|||
std::unordered_map<DinkyECS::Entity, textures::SpriteTexture> $sprites;
|
||||
SortedEntities $sprite_order;
|
||||
|
||||
GameLevel $level;
|
||||
GameDB::Level $level;
|
||||
Matrix $tiles;
|
||||
Matrix $walls;
|
||||
std::vector<double> $zbuffer; // width
|
||||
|
@ -59,7 +59,7 @@ struct Raycaster {
|
|||
return ((y) * $width) + (x);
|
||||
}
|
||||
|
||||
void update_level(GameLevel level);
|
||||
void update_level(GameDB::Level& level);
|
||||
void update_sprite(DinkyECS::Entity ent, components::Sprite& sprite);
|
||||
void init_shaders();
|
||||
void apply_sprite_effect(std::shared_ptr<sf::Shader> effect, float width, float height);
|
||||
|
|
56
systems.cpp
56
systems.cpp
|
@ -33,7 +33,7 @@ void System::set_position(World& world, SpatialMap& collision, Entity entity, Po
|
|||
}
|
||||
|
||||
void System::lighting() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& light = *level.lights;
|
||||
auto& world = *level.world;
|
||||
auto& map = *level.map;
|
||||
|
@ -57,15 +57,15 @@ void System::lighting() {
|
|||
}
|
||||
|
||||
void System::generate_paths() {
|
||||
auto& level = Game::current();
|
||||
const auto &player_pos = Game::player_position();
|
||||
auto& level = GameDB::current();
|
||||
const auto &player_pos = GameDB::player_position();
|
||||
|
||||
level.map->set_target(player_pos.location);
|
||||
level.map->make_paths();
|
||||
}
|
||||
|
||||
void System::enemy_ai_initialize() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto& map = *level.map;
|
||||
|
||||
|
@ -93,10 +93,10 @@ void System::enemy_ai_initialize() {
|
|||
}
|
||||
|
||||
void System::enemy_pathing() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto& map = *level.map;
|
||||
const auto &player_pos = Game::player_position();
|
||||
const auto &player_pos = GameDB::player_position();
|
||||
|
||||
world.query<Position, Motion>([&](auto ent, auto &position, auto &motion) {
|
||||
if(ent != level.player) {
|
||||
|
@ -135,7 +135,7 @@ inline void move_entity(SpatialMap &collider, Map &game_map, Position &position,
|
|||
}
|
||||
|
||||
void System::motion() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
level.world->query<Position, Motion>(
|
||||
[&](auto ent, auto &position, auto &motion) {
|
||||
// don't process entities that don't move
|
||||
|
@ -146,7 +146,7 @@ void System::motion() {
|
|||
}
|
||||
|
||||
void System::distribute_loot(Position target_pos) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto& config = world.get_the<GameConfig>();
|
||||
int inventory_count = Random::uniform(0, 3);
|
||||
|
@ -171,7 +171,7 @@ void System::distribute_loot(Position target_pos) {
|
|||
}
|
||||
|
||||
void System::death() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto player = world.get_the<Player>();
|
||||
std::vector<Entity> dead_things;
|
||||
|
@ -229,7 +229,7 @@ inline void animate_entity(World &world, Entity entity) {
|
|||
}
|
||||
|
||||
void System::combat(int attack_id) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& collider = *level.collision;
|
||||
auto& world = *level.world;
|
||||
auto& the_belt = world.get_the<ritual::Belt>();
|
||||
|
@ -237,7 +237,7 @@ void System::combat(int attack_id) {
|
|||
if(!the_belt.has(attack_id)) return;
|
||||
|
||||
auto& ritual = the_belt.get(attack_id);
|
||||
const auto& player_pos = Game::player_position();
|
||||
const auto& player_pos = GameDB::player_position();
|
||||
auto& player_combat = world.get<Combat>(level.player);
|
||||
|
||||
// this is guaranteed to not return the given position
|
||||
|
@ -286,10 +286,10 @@ void System::combat(int attack_id) {
|
|||
|
||||
|
||||
void System::collision() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& collider = *level.collision;
|
||||
auto& world = *level.world;
|
||||
const auto& player_pos = Game::player_position();
|
||||
const auto& player_pos = GameDB::player_position();
|
||||
|
||||
// this is guaranteed to not return the given position
|
||||
auto [found, nearby] = collider.neighbors(player_pos.location);
|
||||
|
@ -319,7 +319,7 @@ void System::collision() {
|
|||
* from the world for say, putting into a container or inventory.
|
||||
*/
|
||||
void System::remove_from_world(Entity entity) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& item_pos = level.world->get<Position>(entity);
|
||||
level.collision->remove(item_pos.location, entity);
|
||||
// if you don't do this you get the bug that you can pickup
|
||||
|
@ -328,10 +328,10 @@ void System::remove_from_world(Entity entity) {
|
|||
}
|
||||
|
||||
void System::pickup() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto& collision = *level.collision;
|
||||
auto pos = Game::player_position();
|
||||
auto pos = GameDB::player_position();
|
||||
|
||||
if(!collision.something_there(pos.aiming_at)) return;
|
||||
|
||||
|
@ -393,8 +393,8 @@ void System::device(World &world, Entity actor, Entity item) {
|
|||
}
|
||||
|
||||
void System::plan_motion(Position move_to) {
|
||||
auto& level = Game::current();
|
||||
auto& player_pos = Game::player_position();
|
||||
auto& level = GameDB::current();
|
||||
auto& player_pos = GameDB::player_position();
|
||||
|
||||
player_pos.aiming_at = move_to.aiming_at;
|
||||
|
||||
|
@ -405,7 +405,7 @@ void System::plan_motion(Position move_to) {
|
|||
|
||||
|
||||
void System::player_status() {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& combat = level.world->get<Combat>(level.player);
|
||||
float percent = float(combat.hp) / float(combat.max_hp);
|
||||
|
||||
|
@ -423,7 +423,7 @@ void System::player_status() {
|
|||
}
|
||||
|
||||
std::shared_ptr<sf::Shader> System::sprite_effect(Entity entity) {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
if(world->has<SpriteEffect>(entity)) {
|
||||
auto& se = world->get<SpriteEffect>(entity);
|
||||
|
||||
|
@ -450,10 +450,10 @@ Entity System::spawn_item(World& world, const std::string& name) {
|
|||
}
|
||||
|
||||
void System::drop_item(Entity item) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto& map = *level.map;
|
||||
auto player_pos = Game::player_position();
|
||||
auto player_pos = GameDB::player_position();
|
||||
|
||||
dbc::check(map.can_move(player_pos.location), "impossible, the player can't be in a wall");
|
||||
|
||||
|
@ -470,7 +470,7 @@ void System::drop_item(Entity item) {
|
|||
|
||||
// NOTE: I think pickup and this need to be different
|
||||
bool System::place_in_container(Entity cont_id, const std::string& name, Entity world_entity) {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
auto& container = world->get<inventory::Model>(cont_id);
|
||||
|
||||
if(container.has(world_entity)) {
|
||||
|
@ -490,7 +490,7 @@ bool System::place_in_container(Entity cont_id, const std::string& name, Entity
|
|||
}
|
||||
|
||||
void System::remove_from_container(Entity cont_id, const std::string& slot_id) {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
auto& container = world->get<inventory::Model>(cont_id);
|
||||
auto entity = container.get(slot_id);
|
||||
container.remove(entity);
|
||||
|
@ -498,7 +498,7 @@ void System::remove_from_container(Entity cont_id, const std::string& slot_id) {
|
|||
|
||||
|
||||
void System::inventory_swap(Entity container_id, const std::string& a_name, const std::string &b_name) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
dbc::check(a_name != b_name, "Attempt to inventory swap the same slot, you should check this and avoid calling me.");
|
||||
|
||||
auto& inventory = level.world->get<inventory::Model>(container_id);
|
||||
|
@ -509,14 +509,14 @@ void System::inventory_swap(Entity container_id, const std::string& a_name, cons
|
|||
}
|
||||
|
||||
bool System::inventory_occupied(Entity container_id, const std::string& name) {
|
||||
auto world = Game::current_world();
|
||||
auto world = GameDB::current_world();
|
||||
auto& inventory = world->get<inventory::Model>(container_id);
|
||||
return inventory.has(name);
|
||||
}
|
||||
|
||||
|
||||
void System::draw_map(Matrix& grid, EntityGrid& entity_map) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
Map &map = *level.map;
|
||||
Matrix &fow = level.lights->$fow;
|
||||
|
@ -606,7 +606,7 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture
|
|||
}
|
||||
|
||||
bool System::use_item(const string& slot_name) {
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& world = *level.world;
|
||||
auto& inventory = world.get<inventory::Model>(level.player);
|
||||
auto& player_combat = world.get<Combat>(level.player);
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
using namespace lighting;
|
||||
|
||||
TEST_CASE("lighting a map works", "[lighting]") {
|
||||
Game::init();
|
||||
auto& level = Game::current();
|
||||
GameDB::init();
|
||||
auto& level = GameDB::current();
|
||||
auto& map = *level.map;
|
||||
|
||||
Point light1, light2;
|
||||
|
|
|
@ -16,9 +16,9 @@ json load_test_data(const string &fname) {
|
|||
}
|
||||
|
||||
TEST_CASE("camera control", "[map]") {
|
||||
Game::init();
|
||||
GameDB::init();
|
||||
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
auto& map = *level.map;
|
||||
|
||||
Point center = map.center_camera({10,10}, 5, 5);
|
||||
|
@ -34,10 +34,10 @@ TEST_CASE("camera control", "[map]") {
|
|||
}
|
||||
|
||||
TEST_CASE("map placement test", "[map-fail]") {
|
||||
Game::init();
|
||||
GameDB::init();
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
auto& level = Game::create_level();
|
||||
auto& level = GameDB::create_level();
|
||||
|
||||
for(size_t rnum = 0; rnum < level.map->room_count(); rnum++) {
|
||||
Point pos;
|
||||
|
@ -79,9 +79,9 @@ TEST_CASE("dijkstra algo test", "[map]") {
|
|||
}
|
||||
|
||||
TEST_CASE("map image test", "[map]") {
|
||||
Game::init();
|
||||
GameDB::init();
|
||||
|
||||
auto& level = Game::current();
|
||||
auto& level = GameDB::current();
|
||||
Matrix map_tiles = matrix::make(7,7);
|
||||
EntityGrid entity_map;
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ using std::string, std::shared_ptr;
|
|||
using matrix::Matrix;
|
||||
|
||||
std::shared_ptr<Map> make_map() {
|
||||
Game::init();
|
||||
return Game::current().map;
|
||||
GameDB::init();
|
||||
return GameDB::current().map;
|
||||
}
|
||||
|
||||
TEST_CASE("basic matrix iterator", "[matrix]") {
|
||||
|
@ -259,7 +259,7 @@ TEST_CASE("prototype circle algorithm", "[matrix]") {
|
|||
TEST_CASE("viewport iterator", "[matrix]") {
|
||||
components::init();
|
||||
textures::init();
|
||||
Game::init();
|
||||
GameDB::init();
|
||||
size_t width = Random::uniform<size_t>(20, 22);
|
||||
size_t height = Random::uniform<size_t>(21, 25);
|
||||
shared_ptr<Map> map = make_map();
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace arena {
|
|||
|
||||
void FSM::START(Event ) {
|
||||
run_systems();
|
||||
dbc::sentinel("THIS IS FUCKED");
|
||||
$level = $level_mgr.current();
|
||||
|
||||
auto entity_id = $level_mgr.spawn_enemy($enemy_name);
|
||||
|
|
|
@ -29,8 +29,6 @@ namespace arena {
|
|||
std::string $enemy_name;
|
||||
sf::RenderWindow $window;
|
||||
sf::Font $font;
|
||||
LevelManager $level_mgr;
|
||||
GameLevel $level;
|
||||
shared_ptr<arena::ArenaUI> $arena_ui = nullptr;
|
||||
|
||||
FSM(std::string enemy_name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue