Junk items are now transfered to your blanket so you can use them in crafting. No UI for that though.
This commit is contained in:
parent
bc557652ba
commit
1a9e068d02
10 changed files with 86 additions and 53 deletions
|
@ -38,7 +38,6 @@
|
||||||
"foreground": [150, 100, 189],
|
"foreground": [150, 100, 189],
|
||||||
"background": [150, 100, 189]
|
"background": [150, 100, 189]
|
||||||
},
|
},
|
||||||
{"_type": "Loot", "amount": 10},
|
|
||||||
{"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0},
|
{"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0},
|
||||||
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
||||||
],
|
],
|
||||||
|
@ -84,7 +83,6 @@
|
||||||
"foreground": [32, 123, 164],
|
"foreground": [32, 123, 164],
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
{"_type": "Loot", "amount": 10},
|
|
||||||
{"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0},
|
{"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0},
|
||||||
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,14 +17,16 @@ namespace gui {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DinkyECS::Entity CombatUI::make_button(std::string name, std::wstring label, Events::GUI event, int action, const std::string &icon_name,
|
DinkyECS::Entity CombatUI::make_button(
|
||||||
const std::string &sound, const std::string &effect_name)
|
std::string name,
|
||||||
|
Events::GUI event,
|
||||||
|
int action,
|
||||||
|
const std::string &icon_name,
|
||||||
|
const std::string &sound,
|
||||||
|
const std::string &effect_name)
|
||||||
{
|
{
|
||||||
(void)label;
|
|
||||||
auto button = $gui.entity(name);
|
auto button = $gui.entity(name);
|
||||||
$gui.set<Sprite>(button, {icon_name});
|
$gui.set<Sprite>(button, {icon_name});
|
||||||
// $gui.set<Rectangle>(button, {});
|
|
||||||
// $gui.set<Label>(button, {label});
|
|
||||||
$gui.set<Sound>(button, {sound});
|
$gui.set<Sound>(button, {sound});
|
||||||
$gui.set<Effect>(button, {.duration=0.5f, .name=effect_name});
|
$gui.set<Effect>(button, {.duration=0.5f, .name=effect_name});
|
||||||
$gui.set<Clickable>(button,
|
$gui.set<Clickable>(button,
|
||||||
|
@ -40,22 +42,21 @@ namespace gui {
|
||||||
for(int slot = 0; slot < 4; slot++) {
|
for(int slot = 0; slot < 4; slot++) {
|
||||||
if(the_belt.has(slot)) {
|
if(the_belt.has(slot)) {
|
||||||
std::string name = fmt::format("button_{}", slot);
|
std::string name = fmt::format("button_{}", slot);
|
||||||
std::wstring label = fmt::format(L"Attack {}", slot+1);
|
|
||||||
auto& ritual = the_belt.get(slot);
|
auto& ritual = the_belt.get(slot);
|
||||||
|
|
||||||
using enum ritual::Element;
|
using enum ritual::Element;
|
||||||
|
|
||||||
switch(ritual.element) {
|
switch(ritual.element) {
|
||||||
case FIRE:
|
case FIRE:
|
||||||
make_button(name, label, Events::GUI::ATTACK,
|
make_button(name, Events::GUI::ATTACK,
|
||||||
slot, "broken_yoyo-64", "fireball_01", "flame");
|
slot, "broken_yoyo-64", "fireball_01", "flame");
|
||||||
break;
|
break;
|
||||||
case LIGHTNING:
|
case LIGHTNING:
|
||||||
make_button(name, label, Events::GUI::ATTACK,
|
make_button(name, Events::GUI::ATTACK,
|
||||||
slot, "pocket_watch-64", "electric_shock_01", "lightning");
|
slot, "pocket_watch-64", "electric_shock_01", "lightning");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
make_button(name, label, Events::GUI::ATTACK,
|
make_button(name, Events::GUI::ATTACK,
|
||||||
slot, "severed_finger-64", "punch_cartoony", "ui_shader");
|
slot, "severed_finger-64", "punch_cartoony", "ui_shader");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ namespace gui {
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
void update_level(GameLevel &level);
|
void update_level(GameLevel &level);
|
||||||
bool mouse(float x, float y, bool hover);
|
bool mouse(float x, float y, bool hover);
|
||||||
DinkyECS::Entity make_button(std::string name, std::wstring label,
|
DinkyECS::Entity make_button(std::string name, Events::GUI event,
|
||||||
Events::GUI event, int action, const std::string &icon_name,
|
int action, const std::string &icon_name,
|
||||||
const std::string &sound, const std::string &effect_name);
|
const std::string &sound, const std::string &effect_name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ namespace components {
|
||||||
void configure(ComponentMap& component_map) {
|
void configure(ComponentMap& component_map) {
|
||||||
components::enroll<BossFight>(component_map);
|
components::enroll<BossFight>(component_map);
|
||||||
components::enroll<Combat>(component_map);
|
components::enroll<Combat>(component_map);
|
||||||
components::enroll<Loot>(component_map);
|
|
||||||
components::enroll<Position>(component_map);
|
components::enroll<Position>(component_map);
|
||||||
components::enroll<Weapon>(component_map);
|
components::enroll<Weapon>(component_map);
|
||||||
components::enroll<Curative>(component_map);
|
components::enroll<Curative>(component_map);
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "json_mods.hpp"
|
#include "json_mods.hpp"
|
||||||
#include "goap.hpp"
|
#include "goap.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace components {
|
namespace components {
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
|
@ -31,10 +30,6 @@ namespace components {
|
||||||
bool random=false;
|
bool random=false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Loot {
|
|
||||||
int amount;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Tile {
|
struct Tile {
|
||||||
wchar_t display;
|
wchar_t display;
|
||||||
std::array<uint8_t, 3> foreground;
|
std::array<uint8_t, 3> foreground;
|
||||||
|
@ -152,7 +147,6 @@ namespace components {
|
||||||
ENROLL_COMPONENT(Curative, hp);
|
ENROLL_COMPONENT(Curative, hp);
|
||||||
ENROLL_COMPONENT(LightSource, strength, radius);
|
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||||
ENROLL_COMPONENT(Weapon, damage);
|
ENROLL_COMPONENT(Weapon, damage);
|
||||||
ENROLL_COMPONENT(Loot, amount);
|
|
||||||
ENROLL_COMPONENT(Position, location.x, location.y);
|
ENROLL_COMPONENT(Position, location.x, location.y);
|
||||||
ENROLL_COMPONENT(EnemyConfig, ai_script, ai_start_name, ai_goal_name);
|
ENROLL_COMPONENT(EnemyConfig, ai_script, ai_start_name, ai_goal_name);
|
||||||
ENROLL_COMPONENT(Personality, hearing_distance, tough);
|
ENROLL_COMPONENT(Personality, hearing_distance, tough);
|
||||||
|
|
|
@ -30,21 +30,7 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RitualUI::init() {
|
void RitualUI::init() {
|
||||||
auto& blanket = $level.world->get_the<ritual::Blanket>();
|
update_items();
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
blanket.contents.query<ritual::JunkItem>([&](const auto, auto& item) {
|
|
||||||
std::string slot = fmt::format("inv_slot{}", i++);
|
|
||||||
std::string sprite_name = fmt::format("{}-64", item);
|
|
||||||
|
|
||||||
auto button = $gui.entity(slot);
|
|
||||||
$gui.set<Sprite>(button, {sprite_name});
|
|
||||||
$gui.set<Effect>(button, {0.4f});
|
|
||||||
$gui.set<Sound>(button, {"ui_click"});
|
|
||||||
$gui.set<Clickable>(button, {
|
|
||||||
[&](auto ent, auto){ inv_slot_clicked(ent); }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
auto circle = $gui.entity("circle_area");
|
auto circle = $gui.entity("circle_area");
|
||||||
$gui.set<Effect>(circle, {0.4f});
|
$gui.set<Effect>(circle, {0.4f});
|
||||||
|
@ -85,7 +71,8 @@ namespace gui {
|
||||||
bs.sprite->setPosition({float(x), float(y)});
|
bs.sprite->setPosition({float(x), float(y)});
|
||||||
}
|
}
|
||||||
|
|
||||||
$engine.set_state($blanket, "has_magick", true);
|
// BUG: get the actual thing they clicked on
|
||||||
|
$engine.set_state($craft_state, "has_magick", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RitualUI::reset_inv_positions() {
|
void RitualUI::reset_inv_positions() {
|
||||||
|
@ -110,13 +97,16 @@ namespace gui {
|
||||||
animation::rotate(*bs.sprite, 20.0);
|
animation::rotate(*bs.sprite, 20.0);
|
||||||
|
|
||||||
// finalize here ritual here
|
// finalize here ritual here
|
||||||
$engine.plan($blanket);
|
$engine.plan($craft_state);
|
||||||
|
|
||||||
if($blanket.is_combined()) {
|
if($craft_state.is_combined()) {
|
||||||
// add it to the belt
|
// add it to the belt
|
||||||
auto ritual = $engine.finalize($blanket);
|
auto ritual = $engine.finalize($craft_state);
|
||||||
|
// remove the items from the blanket now
|
||||||
|
|
||||||
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
auto& the_belt = $level.world->get_the<ritual::Belt>();
|
||||||
the_belt.equip(0, ritual);
|
the_belt.equip(0, ritual);
|
||||||
|
|
||||||
$level.world->send<Events::GUI>(Events::GUI::NEW_RITUAL, $level.player, {});
|
$level.world->send<Events::GUI>(Events::GUI::NEW_RITUAL, $level.player, {});
|
||||||
reset_inv_positions();
|
reset_inv_positions();
|
||||||
} else {
|
} else {
|
||||||
|
@ -129,21 +119,42 @@ namespace gui {
|
||||||
return $gui.mouse(x, y, hover);
|
return $gui.mouse(x, y, hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RitualUI::update_items() {
|
||||||
|
auto& blanket = $level.world->get_the<ritual::Blanket>();
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
blanket.contents.query<ritual::JunkItem>([&](const auto, auto& item) {
|
||||||
|
std::string slot = fmt::format("inv_slot{}", i++);
|
||||||
|
auto button = $gui.entity(slot);
|
||||||
|
std::string sprite_name = fmt::format("{}-64", item);
|
||||||
|
|
||||||
|
if($gui.has<Clickable>(button)) {
|
||||||
|
$gui.set<Sprite>(button, {sprite_name});
|
||||||
|
} else {
|
||||||
|
$gui.set<Sprite>(button, {sprite_name});
|
||||||
|
$gui.set<Effect>(button, {0.4f});
|
||||||
|
$gui.set<Sound>(button, {"ui_click"});
|
||||||
|
$gui.set<Clickable>(button, {
|
||||||
|
[&](auto ent, auto){ inv_slot_clicked(ent); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void RitualUI::toggle() {
|
void RitualUI::toggle() {
|
||||||
using enum RitualUIState;
|
using enum RitualUIState;
|
||||||
|
|
||||||
if($ritual_state == OPEN) {
|
if($ritual_state == OPEN) {
|
||||||
$ritual_state = CLOSING;
|
$ritual_state = CLOSING;
|
||||||
} else if($ritual_state == CLOSED) {
|
} else if($ritual_state == CLOSED) {
|
||||||
$blanket = $engine.start();
|
update_items();
|
||||||
|
$gui.init();
|
||||||
|
$craft_state = $engine.start();
|
||||||
$ritual_state = OPENING;
|
$ritual_state = OPENING;
|
||||||
$ritual_anim.play();
|
$ritual_anim.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* WARNING: This is really not the greatest way to do this.
|
|
||||||
* look in status_ui.update_level()
|
|
||||||
* */
|
|
||||||
void RitualUI::update() {
|
void RitualUI::update() {
|
||||||
dbc::log("RITUAL UPDATE NOT IMPLEMENTED");
|
dbc::log("RITUAL UPDATE NOT IMPLEMENTED");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace gui {
|
||||||
sf::IntRect $ritual_closed_rect{{0,0},{380,720}};
|
sf::IntRect $ritual_closed_rect{{0,0},{380,720}};
|
||||||
sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}};
|
sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}};
|
||||||
ritual::Engine $engine;
|
ritual::Engine $engine;
|
||||||
ritual::CraftingState $blanket;
|
ritual::CraftingState $craft_state;
|
||||||
RitualUIState $ritual_state = RitualUIState::CLOSED;
|
RitualUIState $ritual_state = RitualUIState::CLOSED;
|
||||||
textures::SpriteTexture $ritual_ui;
|
textures::SpriteTexture $ritual_ui;
|
||||||
components::Animation $ritual_anim;
|
components::Animation $ritual_anim;
|
||||||
|
@ -34,6 +34,7 @@ namespace gui {
|
||||||
void render(sf::RenderWindow &window);
|
void render(sf::RenderWindow &window);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
void update_items();
|
||||||
void ritual_circle_clicked(DinkyECS::Entity ent);
|
void ritual_circle_clicked(DinkyECS::Entity ent);
|
||||||
void inv_slot_clicked(DinkyECS::Entity ent);
|
void inv_slot_clicked(DinkyECS::Entity ent);
|
||||||
void reset_inv_positions();
|
void reset_inv_positions();
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "ai.hpp"
|
#include "ai.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "dinkyecs.hpp"
|
#include "dinkyecs.hpp"
|
||||||
#include "components.hpp"
|
|
||||||
|
|
||||||
namespace ritual {
|
namespace ritual {
|
||||||
enum class Element {
|
enum class Element {
|
||||||
|
@ -73,6 +72,10 @@ namespace ritual {
|
||||||
|
|
||||||
using JunkItem = std::string;
|
using JunkItem = std::string;
|
||||||
|
|
||||||
|
struct JunkPile {
|
||||||
|
std::vector<JunkItem> contents;
|
||||||
|
};
|
||||||
|
|
||||||
struct Blanket {
|
struct Blanket {
|
||||||
DinkyECS::World contents;
|
DinkyECS::World contents;
|
||||||
|
|
||||||
|
|
41
systems.cpp
41
systems.cpp
|
@ -140,6 +140,29 @@ void System::motion(GameLevel &level) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void System::distribute_loot(DinkyECS::World &world, DinkyECS::Entity& ent, nlohmann::json& entity_data) {
|
||||||
|
int inventory_count = entity_data["inventory_count"];
|
||||||
|
world.set<InventoryItem>(ent, {inventory_count, entity_data});
|
||||||
|
// use the inventory_level to fill the blanket with new items
|
||||||
|
|
||||||
|
Config config("assets/rituals.json");
|
||||||
|
ritual::JunkPile pile;
|
||||||
|
auto& junk = config["junk"];
|
||||||
|
|
||||||
|
ritual::JunkPile select_from;
|
||||||
|
for(auto& el : junk.items()) {
|
||||||
|
select_from.contents.push_back(el.key());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < inventory_count; i++) {
|
||||||
|
size_t max_junk = select_from.contents.size();
|
||||||
|
auto& item = select_from.contents.at(Random::uniform(size_t(0), max_junk-1));
|
||||||
|
pile.contents.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
world.set<ritual::JunkPile>(ent, pile);
|
||||||
|
}
|
||||||
|
|
||||||
void System::death(GameLevel &level, components::ComponentMap& components) {
|
void System::death(GameLevel &level, components::ComponentMap& components) {
|
||||||
auto &world = *level.world;
|
auto &world = *level.world;
|
||||||
auto player = world.get_the<Player>();
|
auto player = world.get_the<Player>();
|
||||||
|
@ -187,8 +210,7 @@ void System::death(GameLevel &level, components::ComponentMap& components) {
|
||||||
auto entity_data = config.items["GRAVE_STONE"];
|
auto entity_data = config.items["GRAVE_STONE"];
|
||||||
components::configure_entity(components, world, ent, entity_data["components"]);
|
components::configure_entity(components, world, ent, entity_data["components"]);
|
||||||
if(entity_data["inventory_count"] > 0) {
|
if(entity_data["inventory_count"] > 0) {
|
||||||
// right here use a std::any that's already converted instead?
|
System::distribute_loot(world, ent, entity_data);
|
||||||
world.set<InventoryItem>(ent, {entity_data["inventory_count"], entity_data});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,17 +315,20 @@ void System::collision(GameLevel &level) {
|
||||||
world.remove<LightSource>(entity);
|
world.remove<LightSource>(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(world.has<ritual::JunkPile>(entity)) {
|
||||||
|
auto& pile = world.get<ritual::JunkPile>(entity);
|
||||||
|
auto& blanket = world.get_the<ritual::Blanket>();
|
||||||
|
for(auto& junk : pile.contents) {
|
||||||
|
fmt::println("adding {} to blanket", junk);
|
||||||
|
blanket.add(junk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(world.has<Weapon>(entity)) {
|
if(world.has<Weapon>(entity)) {
|
||||||
inventory.add(item);
|
inventory.add(item);
|
||||||
world.remove<Weapon>(entity);
|
world.remove<Weapon>(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(world.has<Loot>(entity)) {
|
|
||||||
auto &loot = world.get<Loot>(entity);
|
|
||||||
inventory.gold += loot.amount;
|
|
||||||
world.remove<Loot>(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(world.has<Curative>(entity)) {
|
if(world.has<Curative>(entity)) {
|
||||||
inventory.add(item);
|
inventory.add(item);
|
||||||
world.remove<Curative>(entity);
|
world.remove<Curative>(entity);
|
||||||
|
|
|
@ -24,5 +24,6 @@ namespace System {
|
||||||
|
|
||||||
std::shared_ptr<sf::Shader> sprite_effect(GameLevel &level, DinkyECS::Entity entity);
|
std::shared_ptr<sf::Shader> sprite_effect(GameLevel &level, DinkyECS::Entity entity);
|
||||||
void player_status(GameLevel &level);
|
void player_status(GameLevel &level);
|
||||||
|
void distribute_loot(DinkyECS::World &world, DinkyECS::Entity& ent, nlohmann::json& entity_data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue