Now floor drops always work by having a drop against a wall just drop at your feet. Closes #77.
This commit is contained in:
parent
1788b8fb28
commit
694ee210d6
8 changed files with 30 additions and 38 deletions
|
@ -111,8 +111,8 @@ namespace gui {
|
||||||
switch(ev) {
|
switch(ev) {
|
||||||
case AIM_CLICK: {
|
case AIM_CLICK: {
|
||||||
// take from inventory, drop on floor
|
// take from inventory, drop on floor
|
||||||
bool worked = throw_on_floor($status_ui.$gui, true);
|
throw_on_floor($status_ui.$gui, true);
|
||||||
if(worked) END(CLOSE);
|
END(CLOSE);
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT: {
|
case INV_SELECT: {
|
||||||
auto drop_id = std::any_cast<guecs::Entity>(data);
|
auto drop_id = std::any_cast<guecs::Entity>(data);
|
||||||
|
@ -137,8 +137,8 @@ namespace gui {
|
||||||
break;
|
break;
|
||||||
case AIM_CLICK: {
|
case AIM_CLICK: {
|
||||||
// THIS IS PUT IT BACK ON THE FLOOR
|
// THIS IS PUT IT BACK ON THE FLOOR
|
||||||
bool worked = throw_on_floor($loot_ui.$gui, false);
|
throw_on_floor($loot_ui.$gui, false);
|
||||||
if(worked) END(CLOSE);
|
END(CLOSE);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
handle_mouse(ev, $loot_ui.$gui);
|
handle_mouse(ev, $loot_ui.$gui);
|
||||||
|
@ -282,29 +282,23 @@ namespace gui {
|
||||||
* Dropping on the ground is only possible from the
|
* Dropping on the ground is only possible from the
|
||||||
* status_ui for now.
|
* status_ui for now.
|
||||||
*/
|
*/
|
||||||
bool DNDLoot::throw_on_floor(guecs::UI& gui, bool from_status) {
|
void DNDLoot::throw_on_floor(guecs::UI& gui, bool from_status) {
|
||||||
dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set");
|
dbc::check($grab_source != std::nullopt, "attempt to commit_drop but no grab_source set");
|
||||||
dbc::check(gui.has<guecs::GrabSource>(*$grab_source),
|
dbc::check(gui.has<guecs::GrabSource>(*$grab_source),
|
||||||
"StatusUI doesn't actually have that GrabSource in the gui.");
|
"StatusUI doesn't actually have that GrabSource in the gui.");
|
||||||
|
|
||||||
auto& grab = gui.get<guecs::GrabSource>(*$grab_source);
|
auto& grab = gui.get<guecs::GrabSource>(*$grab_source);
|
||||||
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
if(from_status) {
|
if(from_status) {
|
||||||
result = $status_ui.drop_item(grab.world_entity);
|
$status_ui.drop_item(grab.world_entity);
|
||||||
} else {
|
} else {
|
||||||
result = $loot_ui.drop_item(grab.world_entity);
|
$loot_ui.drop_item(grab.world_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result) {
|
|
||||||
grab.commit();
|
grab.commit();
|
||||||
clear_grab();
|
clear_grab();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If I refactored everything to use a levelmanager module then
|
* If I refactored everything to use a levelmanager module then
|
||||||
* this and many other things could go away. Access to $level is
|
* this and many other things could go away. Access to $level is
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace gui {
|
||||||
std::optional<guecs::Entity> source_id, guecs::Entity drop_id);
|
std::optional<guecs::Entity> source_id, guecs::Entity drop_id);
|
||||||
|
|
||||||
bool hold_item(guecs::UI& gui, guecs::Entity gui_id);
|
bool hold_item(guecs::UI& gui, guecs::Entity gui_id);
|
||||||
bool throw_on_floor(guecs::UI& gui, bool from_status);
|
void throw_on_floor(guecs::UI& gui, bool from_status);
|
||||||
|
|
||||||
void clear_grab();
|
void clear_grab();
|
||||||
|
|
||||||
|
|
|
@ -127,10 +127,9 @@ namespace gui {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LootUI::drop_item(DinkyECS::Entity item_id) {
|
void LootUI::drop_item(DinkyECS::Entity item_id) {
|
||||||
bool dropped = System::drop_item($level, item_id);
|
System::drop_item($level, item_id);
|
||||||
if(dropped) update();
|
update();
|
||||||
return dropped;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LootUI::mouse(float x, float y, bool hover) {
|
bool LootUI::mouse(float x, float y, bool hover) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace gui {
|
||||||
void remove_slot(guecs::Entity slot_id);
|
void remove_slot(guecs::Entity slot_id);
|
||||||
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
||||||
void add_loose_item(DinkyECS::Entity entity);
|
void add_loose_item(DinkyECS::Entity entity);
|
||||||
bool drop_item(DinkyECS::Entity item_id);
|
void drop_item(DinkyECS::Entity item_id);
|
||||||
bool occupied(guecs::Entity gui_id);
|
bool occupied(guecs::Entity gui_id);
|
||||||
void swap(guecs::Entity gui_a, guecs::Entity gui_b);
|
void swap(guecs::Entity gui_a, guecs::Entity gui_b);
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,10 +114,9 @@ namespace gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StatusUI::drop_item(DinkyECS::Entity item_id) {
|
void StatusUI::drop_item(DinkyECS::Entity item_id) {
|
||||||
bool dropped = System::drop_item($level, item_id);
|
System::drop_item($level, item_id);
|
||||||
if(dropped) update();
|
update();
|
||||||
return dropped;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: do I need this or how does it relate to drop_item?
|
// NOTE: do I need this or how does it relate to drop_item?
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace gui {
|
||||||
|
|
||||||
void remove_slot(guecs::Entity slot_id);
|
void remove_slot(guecs::Entity slot_id);
|
||||||
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
||||||
bool drop_item(DinkyECS::Entity item_id);
|
void drop_item(DinkyECS::Entity item_id);
|
||||||
|
|
||||||
void swap(guecs::Entity gui_a, guecs::Entity gui_b);
|
void swap(guecs::Entity gui_a, guecs::Entity gui_b);
|
||||||
bool occupied(guecs::Entity slot);
|
bool occupied(guecs::Entity slot);
|
||||||
|
|
18
systems.cpp
18
systems.cpp
|
@ -439,24 +439,24 @@ Entity System::spawn_item(World& world, const std::string& name) {
|
||||||
return item_id;
|
return item_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool System::drop_item(GameLevel& level, Entity item) {
|
void System::drop_item(GameLevel& level, Entity item) {
|
||||||
auto& world = *level.world;
|
auto& world = *level.world;
|
||||||
auto& map = *level.map;
|
auto& map = *level.map;
|
||||||
auto& collision = *level.collision;
|
auto& collision = *level.collision;
|
||||||
|
|
||||||
auto player_pos = world.get<Position>(level.player);
|
auto player_pos = world.get<Position>(level.player);
|
||||||
|
|
||||||
Position pos{player_pos.aiming_at.x, player_pos.aiming_at.y};
|
dbc::check(map.can_move(player_pos.location), "impossible, the player can't be in a wall");
|
||||||
|
|
||||||
if(map.can_move(pos.location)) {
|
Position drop_spot = {player_pos.aiming_at.x, player_pos.aiming_at.y};
|
||||||
world.set<Position>(item, pos);
|
|
||||||
collision.insert(pos.location, item, false);
|
// if they're aiming at a wall then drop at their feet
|
||||||
|
if(!map.can_move(drop_spot.location)) drop_spot = player_pos;
|
||||||
|
|
||||||
|
world.set<Position>(item, drop_spot);
|
||||||
|
collision.insert(drop_spot.location, item, false);
|
||||||
level.world->not_constant(item);
|
level.world->not_constant(item);
|
||||||
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, item, {});
|
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, item, {});
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: I think pickup and this need to be different
|
// NOTE: I think pickup and this need to be different
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace System {
|
||||||
void device(World &world, Entity actor, Entity item);
|
void device(World &world, Entity actor, Entity item);
|
||||||
void plan_motion(World& world, Position move_to);
|
void plan_motion(World& world, Position move_to);
|
||||||
Entity spawn_item(World& world, const string& name);
|
Entity spawn_item(World& world, const string& name);
|
||||||
bool drop_item(GameLevel& level, Entity item);
|
void drop_item(GameLevel& level, Entity item);
|
||||||
|
|
||||||
void enemy_ai(GameLevel &level);
|
void enemy_ai(GameLevel &level);
|
||||||
void combat(GameLevel& level, int attack_id);
|
void combat(GameLevel& level, int attack_id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue