diff options
author | Aki <please@ignore.pl> | 2023-01-11 09:24:43 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-01-11 09:24:43 +0100 |
commit | 8f76e26c4dfe07079295dee8ca7d58696f532195 (patch) | |
tree | 9bcae74ed643d0a782573a4a6f1b9ab7e8577cb9 | |
parent | 586adb53ecbbf4eff924fd145cd0f5a72797e021 (diff) | |
download | kurator-8f76e26c4dfe07079295dee8ca7d58696f532195.zip kurator-8f76e26c4dfe07079295dee8ca7d58696f532195.tar.gz kurator-8f76e26c4dfe07079295dee8ca7d58696f532195.tar.bz2 |
Battle scenario is now generated with the specified loadout
-rw-r--r-- | kurator/src/ScenarioEditor.cpp | 55 | ||||
-rw-r--r-- | kurator/src/ScenarioEditor.h | 12 |
2 files changed, 42 insertions, 25 deletions
diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp index 29e275e..5570730 100644 --- a/kurator/src/ScenarioEditor.cpp +++ b/kurator/src/ScenarioEditor.cpp @@ -9,6 +9,7 @@ #include <kurator/campaign/Scenario.h> #include <kurator/campaign/scenarios.h> #include <kurator/universe.h> +#include <kurator/universe/Repository.h> #include "Battle.h" #include "Session.h" @@ -20,15 +21,14 @@ namespace kurator ScenarioEditor::ScenarioEditor(std::shared_ptr<Session> _session) : session {std::move(_session)}, - teams {2}, - anvils {3}, - warbringers {2}, - eclipses {3}, - distance {12000} + repository {universe::load_json("resources/universe")}, + battle {}, + frame {}, + loadout {}, + loadout_editor{repository, loadout} { + loadout.type = repository->ship_type("Anvil"); // access to default/first? regenerate(); - loadout_editor.repo = universe::load_json("resources/universe"); - loadout_editor.loadout.type = loadout_editor.repo->ship_type("Anvil"); // access to default or first? } @@ -36,14 +36,10 @@ void ScenarioEditor::update(float) { frame.update(); - loadout_editor.show(); + if (loadout_editor.show()) + regenerate(); if (ImGui::Begin("Scenario Editor")) { bool update = false; - update |= ImGui::SliderInt("Teams", &teams, 2, 6); - update |= ImGui::SliderInt("Anvils", &anvils, 0, 20); - update |= ImGui::SliderInt("Warbringers", &warbringers, 0, 20); - update |= ImGui::SliderInt("Eclipses", &eclipses, 0, 20); - update |= ImGui::SliderFloat("Distance", &distance, 10000, 20000); if (update) regenerate(); if (ImGui::Button("Start")) @@ -77,44 +73,67 @@ ScenarioEditor::start_battle() void ScenarioEditor::regenerate() { - auto scenario = campaign::scenarios::example(teams, anvils, warbringers, eclipses, distance); + int id = 0; + campaign::Scenario scenario {"Player Encounter", 12000, {}}; + for (int i = 0; i < 2; ++i) { + for (int n = 0; n < 5; ++n) + scenario.ships.push_back(campaign::ShipConfig{{id++}, i, loadout}); + } battle = std::make_shared<Battle>(session, std::move(scenario)); frame.reset(battle); } -void +LoadoutEditor::LoadoutEditor(std::shared_ptr<universe::Repository> _repo, campaign::Loadout& _loadout) : + repo {std::move(_repo)}, + loadout {_loadout} +{ +} + + +bool LoadoutEditor::show() { + bool changed = false; ImGui::PushID(this); if (ImGui::Begin("Loadout Editor")) { if (ImGui::BeginCombo("Ship Type", loadout.type.name.c_str())) { repo->for_ship_types([&](const auto& type){ - if (ImGui::Selectable(type.name.c_str(), loadout.type.name == type.name)) + if (ImGui::Selectable(type.name.c_str(), loadout.type.name == type.name)) { loadout.type = type; + changed = true; + } }); ImGui::EndCombo(); } auto it = loadout.turrets.begin(); while (it != loadout.turrets.end()) { ImGui::PushID(it - loadout.turrets.begin()); + ImGui::Indent(); const bool removed = ImGui::Button("-"); ImGui::SameLine(); if (ImGui::BeginCombo("Turret Type", it->name.c_str())) { repo->for_turret_types([&](const auto& type){ - if (ImGui::Selectable(type.name.c_str(), it->name == type.name)) + if (ImGui::Selectable(type.name.c_str(), it->name == type.name)) { *it = type; + changed = true; + } }); ImGui::EndCombo(); } it = removed ? loadout.turrets.erase(it) : std::next(it); + changed |= removed; + ImGui::Unindent(); ImGui::PopID(); } - if (ImGui::Button("Add Turret")) + if (ImGui::Button("Add Turret")) { loadout.turrets.push_back(repo->turret_type("ChargeLaser")); // access to default or first? + changed = true; + } } ImGui::End(); ImGui::PopID(); + return changed; } diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h index d8a7a72..85efbd0 100644 --- a/kurator/src/ScenarioEditor.h +++ b/kurator/src/ScenarioEditor.h @@ -16,9 +16,10 @@ namespace kurator struct LoadoutEditor { + LoadoutEditor(std::shared_ptr<universe::Repository> _repo, campaign::Loadout& _loadout); std::shared_ptr<universe::Repository> repo; - campaign::Loadout loadout; - void show(); + campaign::Loadout& loadout; + bool show(); }; @@ -32,13 +33,10 @@ public: private: void regenerate(); std::shared_ptr<Session> session; - int teams; - int anvils; - int warbringers; - int eclipses; - float distance; + std::shared_ptr<universe::Repository> repository; std::shared_ptr<Scene> battle; SceneFrame frame; + campaign::Loadout loadout; LoadoutEditor loadout_editor; }; |