From 0c803f99e8133f3ac9f0923b34dfe8d4d7ec966c Mon Sep 17 00:00:00 2001 From: historic_bruno Date: Thu, 9 Jun 2011 23:47:20 +0000 Subject: [PATCH] This was SVN commit r9609. --- build/premake/premake.lua | 1 + source/graphics/MapReader.cpp | 12 +++++++--- source/simulation2/Simulation2.cpp | 10 +++++++- source/simulation2/Simulation2.h | 10 ++++++++ .../AtlasUI/ScenarioEditor/ScenarioEditor.h | 2 ++ .../AtlasUI/ScenarioEditor/SectionLayout.cpp | 2 ++ .../GameInterface/Handlers/MapHandlers.cpp | 24 +++++++++++++++++-- source/tools/atlas/GameInterface/Messages.h | 7 +++++- 8 files changed, 61 insertions(+), 7 deletions(-) diff --git a/build/premake/premake.lua b/build/premake/premake.lua index 1ad7aee023..1675d55b68 100644 --- a/build/premake/premake.lua +++ b/build/premake/premake.lua @@ -823,6 +823,7 @@ function setup_atlas_packages() "ScenarioEditor/Sections/Environment", "ScenarioEditor/Sections/Map", "ScenarioEditor/Sections/Object", + "ScenarioEditor/Sections/Player", "ScenarioEditor/Sections/Terrain", "ScenarioEditor/Sections/Trigger", "ScenarioEditor/Tools", diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 0ac2d8d5ed..a17f266b6c 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -848,6 +848,9 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time) { XMBElementList entities = parent.GetChildNodes(); + CSimulation2& sim = *m_MapReader.pSimulation2; + CmpPtr cmpPlayerManager(sim.GetSimContext(), SYSTEM_ENTITY); + while (entity_idx < entities.Count) { // all new state at this scope and below doesn't need to be @@ -903,12 +906,15 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time) debug_warn(L"Invalid map XML data"); } - CSimulation2& sim = *m_MapReader.pSimulation2; entity_id_t ent = sim.AddEntity(TemplateName, EntityUid); if (ent == INVALID_ENTITY) - LOGERROR(L"Failed to load entity template '%ls'", TemplateName.c_str()); - else { + LOGERROR(L"Failed to load entity template '%ls'", TemplateName.c_str()); + } + else if (cmpPlayerManager->GetPlayerByID(PlayerID) != INVALID_ENTITY) + { // Don't add entities with invalid player IDs + // TODO: Is a warning OK or should it just silently fail? + CmpPtr cmpPosition(sim, ent); if (!cmpPosition.null()) { diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index d6d49d23f2..b2ae52d8c1 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -592,8 +592,16 @@ std::vector CSimulation2::GetCivData() std::string CSimulation2::GetPlayerDefaults() { - VfsPath path = VfsPath(L"simulation/data/player_defaults.json"); + return ReadJSON(L"simulation/data/player_defaults.json"); +} +std::string CSimulation2::GetMapSizes() +{ + return ReadJSON(L"simulation/data/map_sizes.json"); +} + +std::string CSimulation2::ReadJSON(VfsPath path) +{ std::string data; if (!VfsFileExists(path)) diff --git a/source/simulation2/Simulation2.h b/source/simulation2/Simulation2.h index 61f51d6248..585df6b194 100644 --- a/source/simulation2/Simulation2.h +++ b/source/simulation2/Simulation2.h @@ -226,9 +226,19 @@ public: */ std::string GetPlayerDefaults(); + /** + * Get map sizes data + * + * @return string containing JSON format data + */ + std::string GetMapSizes(); + private: CSimulation2Impl* m; + // Helper for reading JSON files + std::string ReadJSON(VfsPath path); + NONCOPYABLE(CSimulation2); }; diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h index bc84c4ee7b..f0d4d6e1a5 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h @@ -64,6 +64,7 @@ public: ScriptInterface& GetScriptInterface() const { return m_ScriptInterface; } Observable& GetObjectSettings() { return m_ObjectSettings; } + Observable& GetMapSettings() { return m_MapSettings; } ToolManager& GetToolManager() { return m_ToolManager; } @@ -77,6 +78,7 @@ private: SectionLayout m_SectionLayout; Observable m_ObjectSettings; + Observable m_MapSettings; void SetOpenFilename(const wxString& filename); wxString m_OpenFilename; diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp index 27688bc6cd..ebcf5700ba 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp @@ -31,6 +31,7 @@ #include "Sections/Cinematic/Cinematic.h" #include "Sections/Map/Map.h" #include "Sections/Object/Object.h" +#include "Sections/Player/Player.h" #include "Sections/Terrain/Terrain.h" #include "Sections/Trigger/Trigger.h" @@ -288,6 +289,7 @@ void SectionLayout::Build(ScenarioEditor& scenarioEditor) m_PageMappings.insert(std::make_pair(L###classname, (int)m_SidebarBook->GetPageCount()-1)); ADD_SIDEBAR(MapSidebar, _T("map.png"), _("Map")); + ADD_SIDEBAR(PlayerSidebar, _T("player.png"), _("Player")); ADD_SIDEBAR(TerrainSidebar, _T("terrain.png"), _("Terrain")); ADD_SIDEBAR(ObjectSidebar, _T("object.png"), _("Object")); ADD_SIDEBAR(EnvironmentSidebar, _T("environment.png"), _("Environment")); diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index e743d4f9b1..4d959a56a1 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -139,11 +139,31 @@ QUERYHANDLER(GetMapSettings) msg->settings = g_Game->GetSimulation2()->GetMapSettingsString(); } -MESSAGEHANDLER(SetMapSettings) +QUERYHANDLER(GetMapSizes) { - g_Game->GetSimulation2()->SetMapSettings(*msg->settings); + msg->sizes = g_Game->GetSimulation2()->GetMapSizes(); } +BEGIN_COMMAND(SetMapSettings) +{ + void Do() + { + Redo(); + } + + void Undo() + { + // TODO + debug_warn(L"Can't undo SetMapSettings"); + } + + void Redo() + { + g_Game->GetSimulation2()->SetMapSettings(*msg->settings); + } +}; +END_COMMAND(SetMapSettings) + QUERYHANDLER(GetRMSData) { msg->data = g_Game->GetSimulation2()->GetRMSData(); diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index d995ecc814..06cc0d73a3 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -152,7 +152,12 @@ QUERY(GetMapSettings, ((std::string, settings)) ); -MESSAGE(SetMapSettings, +QUERY(GetMapSizes, + , + ((std::string, sizes)) + ); + +COMMAND(SetMapSettings, NOMERGE, ((std::string, settings)) );