diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index 2c3f646..dbcb4ab 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp @@ -23,6 +23,7 @@ https://github.com/sago007/saland #include "GameRegion.hpp" #include "GameItems.hpp" +#include "Prefabs.hpp" #include GameRegion::GameRegion() { @@ -156,7 +157,8 @@ void GameRegion::Init(int x, int y, const std::string& worldName, bool forceRese physicsBox.reset(new b2World(gravity)); world.managed_bodies.clear(); world.init(physicsBox, loadMap); - + ScanPrefabs("prefabs01"); + liqudHandler["water"].blockingLayer = world.blockingLayer; liqudHandler["water"].blockingLayer_overlay_1 = world.blockingLayer_overlay_1; liqudHandler["lava"].blockingLayer = world.blockingLayer; diff --git a/src/saland/Prefabs.cpp b/src/saland/Prefabs.cpp new file mode 100644 index 0000000..e14780c --- /dev/null +++ b/src/saland/Prefabs.cpp @@ -0,0 +1,46 @@ +/* +=========================================================================== + * Saland Adventures +Copyright (C) 2014-2021 Poul Sander + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +Source information and contacts persons can be found at +https://github.com/salandgame/saland +=========================================================================== +*/ + +#include "Prefabs.hpp" +#include "../sago/SagoMisc.hpp" +#include "../sagotmx/tmx_struct.h" + + +std::vector prefabs; + +void ScanPrefabs(const std::string& filename) { + std::string mapFileName = "maps/"+filename+".tmx"; + std::string tmx_file = sago::GetFileContent(mapFileName); + sago::tiled::TileMap tm = sago::tiled::string2tilemap(tmx_file); + for (const auto& t : tm.object_groups) { + std::cout << "Prefab object group: " << t.name << "\n"; + for (const auto& o : t.objects) { + Prefab p; + p.filename = filename; + p.name = o.name; + p.topx = o.x/32; + p.topy = o.y/32; + std::cout << "Prefab: " << p.name << " " << p.filename << " (" << p.topx << ", " << p.topy << ")\n"; + } + } +} \ No newline at end of file diff --git a/src/saland/Prefabs.hpp b/src/saland/Prefabs.hpp new file mode 100644 index 0000000..f7b5624 --- /dev/null +++ b/src/saland/Prefabs.hpp @@ -0,0 +1,37 @@ +/* +=========================================================================== + * Saland Adventures +Copyright (C) 2014-2021 Poul Sander + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +Source information and contacts persons can be found at +https://github.com/salandgame/saland +=========================================================================== +*/ + +#include +#include + +void ScanPrefabs(const std::string& filename); + +struct Prefab { + std::string name; + + std::string filename = ""; + int topx = 0; + int topy = 0; + int width = 1; + int height = 1; +}; \ No newline at end of file