The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
495 lines
20 KiB
495 lines
20 KiB
1 year ago
|
#pragma region License
|
||
1 year ago
|
/*
|
||
|
License (OLC-3)
|
||
|
~~~~~~~~~~~~~~~
|
||
|
|
||
11 months ago
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||
1 year ago
|
|
||
|
Redistribution and use in source and binary forms, with or without modification,
|
||
|
are permitted provided that the following conditions are met:
|
||
|
|
||
|
1. Redistributions or derivations of source code must retain the above copyright
|
||
|
notice, this list of conditions and the following disclaimer.
|
||
|
|
||
|
2. Redistributions or derivative works in binary form must reproduce the above
|
||
|
copyright notice. This list of conditions and the following disclaimer must be
|
||
|
reproduced in the documentation and/or other materials provided with the distribution.
|
||
|
|
||
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
||
|
be used to endorse or promote products derived from this software without specific
|
||
|
prior written permission.
|
||
|
|
||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
|
SUCH DAMAGE.
|
||
1 year ago
|
|
||
|
Portions of this software are copyright © 2023 The FreeType
|
||
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||
|
All rights reserved.
|
||
1 year ago
|
*/
|
||
1 year ago
|
#pragma endregion
|
||
1 year ago
|
#pragma once
|
||
|
#include "olcPixelGameEngine.h"
|
||
1 year ago
|
#include "olcUTIL_Geometry2D.h"
|
||
1 year ago
|
#include <sstream>
|
||
1 year ago
|
#include <set>
|
||
1 year ago
|
|
||
|
using namespace olc;
|
||
|
|
||
|
struct XMLTag{
|
||
|
std::string tag;
|
||
|
std::map<std::string,std::string> data;
|
||
1 year ago
|
const std::string FormatTagData(std::map<std::string,std::string>tiles);
|
||
|
friend std::ostream& operator << (std::ostream& os, XMLTag& rhs);
|
||
1 year ago
|
std::string str();
|
||
1 year ago
|
int GetInteger(std::string dataTag);
|
||
1 year ago
|
float GetFloat(std::string dataTag);
|
||
1 year ago
|
double GetDouble(std::string dataTag);
|
||
|
bool GetBool(std::string dataTag);
|
||
12 months ago
|
std::string GetString(std::string dataTag);
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
struct MapTag{
|
||
1 year ago
|
int width=0,height=0;
|
||
1 year ago
|
int tilewidth=0,tileheight=0;
|
||
1 year ago
|
bool optimized=false; //An optimized map will require us to flatten it out and use it as a single tile.
|
||
1 year ago
|
vi2d playerSpawnLocation;
|
||
1 year ago
|
vi2d MapSize; //The number of tiles in width and height of this map.
|
||
|
vi2d TileSize; //How large in pixels the map's tiles are.
|
||
|
MapTag();
|
||
|
MapTag(int width,int height,int tilewidth,int tileheight);
|
||
1 year ago
|
friend std::ostream& operator << (std::ostream& os, MapTag& rhs);
|
||
|
};
|
||
|
|
||
1 year ago
|
struct LayerTag{
|
||
|
XMLTag tag;
|
||
|
std::vector<std::vector<int>> tiles;
|
||
|
std::string str();
|
||
|
};
|
||
|
|
||
|
struct SpawnerTag{
|
||
|
XMLTag ObjectData;
|
||
1 year ago
|
std::vector<XMLTag>monsters;
|
||
1 year ago
|
bool upperLevel=false;
|
||
1 year ago
|
std::string bossNameDisplay;
|
||
1 year ago
|
std::string str();
|
||
|
friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs);
|
||
|
};
|
||
|
|
||
1 year ago
|
struct ZoneData{
|
||
|
geom2d::rect<int>zone;
|
||
|
bool isUpper=false;
|
||
|
};
|
||
|
|
||
1 year ago
|
struct Map{
|
||
1 year ago
|
MapTag MapData;
|
||
1 year ago
|
std::string name;
|
||
1 year ago
|
Renderable*optimizedTile=nullptr;
|
||
1 year ago
|
std::vector<XMLTag> TilesetData;
|
||
1 year ago
|
std::vector<LayerTag> LayerData;
|
||
1 year ago
|
std::string mapType="";
|
||
12 months ago
|
std::set<std::string>spawns;
|
||
1 year ago
|
std::map<int,SpawnerTag> SpawnerData; //Spawn groups have IDs, mobs associate which spawner they are tied to via this ID.
|
||
1 year ago
|
std::map<std::string,std::vector<::ZoneData>> ZoneData;
|
||
1 year ago
|
std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles);
|
||
1 year ago
|
std::string FormatSpawnerData(std::ostream& os, std::map<int,SpawnerTag>tiles);
|
||
1 year ago
|
friend std::ostream& operator << (std::ostream& os, Map& rhs);
|
||
1 year ago
|
friend std::ostream& operator << (std::ostream& os, std::vector<XMLTag>& rhs);
|
||
1 year ago
|
};
|
||
|
|
||
1 year ago
|
struct Property{
|
||
|
std::string name;
|
||
|
std::string value;
|
||
|
int GetInteger();
|
||
|
float GetFloat();
|
||
|
double GetDouble();
|
||
|
bool GetBool();
|
||
|
};
|
||
|
|
||
|
struct StagePlate{
|
||
|
XMLTag tag;
|
||
|
std::map<std::string,Property>properties;
|
||
|
};
|
||
|
|
||
1 year ago
|
class TMXParser{
|
||
|
public:
|
||
|
Map GetData();
|
||
|
private:
|
||
|
Map parsedMapInfo;
|
||
|
bool buildingSpawner=false;
|
||
|
SpawnerTag obj;
|
||
1 year ago
|
int prevSpawner;
|
||
1 year ago
|
ZoneData*prevZoneData=nullptr;
|
||
1 year ago
|
void ParseTag(std::string tag);
|
||
1 year ago
|
int monsterPropertyTagCount=-1;
|
||
|
XMLTag monsterTag;
|
||
|
XMLTag spawnerLinkTag;
|
||
1 year ago
|
StagePlate*currentStagePlate;
|
||
1 year ago
|
std::vector<XMLTag>accumulatedMonsterTags;
|
||
1 year ago
|
std::map<int,StagePlate>stagePlates;
|
||
1 year ago
|
bool infiniteMap=false;
|
||
1 year ago
|
public:
|
||
|
TMXParser(std::string file);
|
||
|
};
|
||
1 year ago
|
|
||
1 year ago
|
//#define TMX_PARSER_SETUP //Toggle for code-writing.
|
||
1 year ago
|
|
||
1 year ago
|
#ifdef TMX_PARSER_SETUP
|
||
|
#undef TMX_PARSER_SETUP
|
||
1 year ago
|
#include "State_OverworldMap.h"
|
||
1 year ago
|
extern bool _DEBUG_MAP_LOAD_INFO;
|
||
1 year ago
|
const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){
|
||
1 year ago
|
std::string displayStr="";
|
||
|
for (std::map<std::string,std::string>::iterator it=data.begin();it!=data.end();it++) {
|
||
|
displayStr+=" "+it->first+": "+it->second+"\n";
|
||
|
}
|
||
|
return displayStr;
|
||
|
}
|
||
1 year ago
|
std::ostream& operator << (std::ostream& os, XMLTag& rhs){
|
||
1 year ago
|
os <<
|
||
|
rhs.tag <<"\n"<<
|
||
|
rhs.FormatTagData(rhs.data) <<"\n";
|
||
1 year ago
|
return os;
|
||
|
}
|
||
1 year ago
|
std::ostream& operator << (std::ostream& os, MapTag& rhs){
|
||
|
os <<
|
||
1 year ago
|
"(width:"<<rhs.width<<", height:"<<rhs.height<<", Tile width:"<<rhs.tilewidth<<", Tile height:"<<rhs.tileheight<<",playerSpawnLocation:"<<rhs.playerSpawnLocation<<")\n";
|
||
1 year ago
|
return os;
|
||
|
}
|
||
1 year ago
|
int XMLTag::GetInteger(std::string dataTag) {
|
||
1 year ago
|
return std::stoi(data[dataTag]);
|
||
|
}
|
||
1 year ago
|
float XMLTag::GetFloat(std::string dataTag) {
|
||
|
return std::stof(data[dataTag]);
|
||
|
}
|
||
1 year ago
|
double XMLTag::GetDouble(std::string dataTag) {
|
||
1 year ago
|
return std::stod(data[dataTag]);
|
||
|
}
|
||
12 months ago
|
std::string XMLTag::GetString(std::string dataTag) {
|
||
|
return data[dataTag];
|
||
|
}
|
||
1 year ago
|
bool XMLTag::GetBool(std::string dataTag) {
|
||
1 year ago
|
if (data[dataTag]=="0"||data[dataTag]=="false") {
|
||
1 year ago
|
return false;
|
||
|
} else {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
1 year ago
|
int Property::GetInteger() {
|
||
|
return std::stoi(value);
|
||
|
}
|
||
|
float Property::GetFloat() {
|
||
|
return std::stof(value);
|
||
|
}
|
||
|
double Property::GetDouble() {
|
||
|
return std::stod(value);
|
||
|
}
|
||
|
bool Property::GetBool() {
|
||
|
if (value=="0") {
|
||
|
return false;
|
||
|
} else {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
1 year ago
|
MapTag::MapTag(){}
|
||
|
MapTag::MapTag(int width,int height,int tilewidth,int tileheight)
|
||
|
:width(width),height(height),tilewidth(tilewidth),tileheight(tileheight),MapSize({width,height}),TileSize({tilewidth,tileheight}){}
|
||
1 year ago
|
std::string XMLTag::str() {
|
||
|
return tag+"\n";
|
||
|
}
|
||
1 year ago
|
std::string LayerTag::str() {
|
||
1 year ago
|
std::string displayStr=tag.tag+"\n"+tag.FormatTagData(tag.data);
|
||
1 year ago
|
displayStr+=" DATA ("+std::to_string(tiles[0].size())+"x"+std::to_string(tiles.size())+" )\n";
|
||
1 year ago
|
return displayStr;
|
||
|
}
|
||
1 year ago
|
std::string SpawnerTag::str() {
|
||
1 year ago
|
std::string displayStr=ObjectData.tag+"\n"+ObjectData.FormatTagData(ObjectData.data);
|
||
1 year ago
|
for(XMLTag&monster:monsters){
|
||
|
displayStr+=" ("+monster.FormatTagData(monster.data)+" )\n";
|
||
1 year ago
|
}
|
||
|
return displayStr;
|
||
|
}
|
||
1 year ago
|
std::ostream& operator << (std::ostream& os, SpawnerTag& rhs) {
|
||
1 year ago
|
os << rhs.str()<<"\n";
|
||
1 year ago
|
return os;
|
||
|
}
|
||
|
std::string Map::FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles) {
|
||
1 year ago
|
std::string displayStr;
|
||
|
for (int i=0;i<LayerData.size();i++) {
|
||
|
displayStr+=LayerData[i].str();
|
||
|
}
|
||
|
return displayStr;
|
||
|
}
|
||
1 year ago
|
std::string Map::FormatSpawnerData(std::ostream& os, std::map<int,SpawnerTag>tiles) {
|
||
1 year ago
|
std::string displayStr;
|
||
1 year ago
|
for (auto key:SpawnerData) {
|
||
|
displayStr+=SpawnerData[key.first].str();
|
||
1 year ago
|
}
|
||
|
return displayStr;
|
||
|
}
|
||
1 year ago
|
std::ostream& operator <<(std::ostream& os, std::vector<XMLTag>& rhs) {
|
||
|
for(XMLTag&tag:rhs){
|
||
|
os <<
|
||
|
tag<<"\n";
|
||
|
}
|
||
|
return os;
|
||
|
}
|
||
1 year ago
|
std::ostream& operator <<(std::ostream& os, Map& rhs) {
|
||
1 year ago
|
os <<
|
||
|
rhs.MapData <<"\n"<<
|
||
|
rhs.TilesetData <<"\n"<<
|
||
1 year ago
|
rhs.FormatLayerData(os,rhs.LayerData) <<"\n"<<
|
||
|
rhs.FormatSpawnerData(os,rhs.SpawnerData)<<"\n";
|
||
1 year ago
|
return os;
|
||
|
}
|
||
|
Map TMXParser::GetData() {
|
||
1 year ago
|
return parsedMapInfo;
|
||
|
}
|
||
1 year ago
|
void TMXParser::ParseTag(std::string tag) {
|
||
1 year ago
|
auto ReadNextTag=[&](){
|
||
|
XMLTag newTag;
|
||
|
//First character is a '<' so we discard it.
|
||
|
tag.erase(0,1); tag.erase(tag.length()-1,1); //Erase the first and last characters in the tag. Now parse by spaces.
|
||
|
std::stringstream s(tag); //Turn it into a string stream to now parse into individual whitespaces.
|
||
|
std::string data;
|
||
|
while (s.good()) {
|
||
|
int quotationMarkCount=0;
|
||
|
bool pastEquals=false;
|
||
|
data="";
|
||
|
bool valid=false;
|
||
|
while(s.good()){
|
||
|
int character=s.get();
|
||
|
if(character=='"'){
|
||
|
quotationMarkCount++;
|
||
|
}
|
||
|
if(character==' '&"ationMarkCount%2==0){
|
||
|
valid=true;
|
||
|
break;
|
||
|
}
|
||
|
data+=character;
|
||
|
if(pastEquals&"ationMarkCount%2==0){
|
||
|
valid=true;
|
||
|
break;
|
||
|
}
|
||
|
if(character=='='&"ationMarkCount%2==0){
|
||
|
pastEquals=true;
|
||
|
}
|
||
1 year ago
|
}
|
||
1 year ago
|
if(valid&&data.length()>0){
|
||
|
if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag.
|
||
|
newTag.tag=data;
|
||
1 year ago
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Tag: "<<newTag.tag<<"\n";
|
||
1 year ago
|
} else {
|
||
|
std::string key = data.substr(0,data.find("="));
|
||
|
std::string value = data.substr(data.find("=")+1,std::string::npos);
|
||
1 year ago
|
|
||
1 year ago
|
//Strip Quotation marks.
|
||
|
value = value.substr(1,std::string::npos);
|
||
|
value = value.substr(0,value.length()-1);
|
||
1 year ago
|
|
||
1 year ago
|
newTag.data[key]=value;
|
||
1 year ago
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
|
||
1 year ago
|
}
|
||
1 year ago
|
}
|
||
1 year ago
|
}
|
||
1 year ago
|
return newTag;
|
||
|
};
|
||
|
|
||
|
XMLTag newTag=ReadNextTag();
|
||
1 year ago
|
|
||
1 year ago
|
if (newTag.tag=="object"&&newTag.data["type"]!="StagePlate"){
|
||
1 year ago
|
currentStagePlate=nullptr;
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
if (newTag.tag=="map"){
|
||
1 year ago
|
if(stoi(newTag.data["infinite"])==1){
|
||
|
infiniteMap=true;
|
||
|
return;
|
||
|
}
|
||
1 year ago
|
parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"]),stoi(newTag.data["tilewidth"]),stoi(newTag.data["tileheight"])};
|
||
1 year ago
|
} else
|
||
1 year ago
|
if (newTag.tag=="tileset"){
|
||
1 year ago
|
parsedMapInfo.TilesetData.push_back(newTag);
|
||
|
} else
|
||
1 year ago
|
if (newTag.tag=="layer"){
|
||
1 year ago
|
LayerTag l = {newTag};
|
||
|
parsedMapInfo.LayerData.push_back(l);
|
||
1 year ago
|
}else
|
||
1 year ago
|
if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup"){
|
||
1 year ago
|
if(newTag.GetInteger("id")!=0){
|
||
|
parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag};
|
||
|
prevSpawner=newTag.GetInteger("id");
|
||
|
}
|
||
1 year ago
|
} else
|
||
1 year ago
|
if(newTag.tag=="property"&&newTag.data["name"]=="Upper?"&&prevZoneData!=nullptr){
|
||
|
prevZoneData->isUpper=newTag.GetBool("value");
|
||
|
}else
|
||
1 year ago
|
if (newTag.tag=="property"&&newTag.data["name"]=="Optimize"&&newTag.data["value"]=="true") {
|
||
|
parsedMapInfo.MapData.optimized=true;
|
||
|
} else
|
||
1 year ago
|
if (newTag.tag=="property"&&newTag.data["name"]=="Boss Title Display") {
|
||
|
parsedMapInfo.SpawnerData[prevSpawner].bossNameDisplay=newTag.data["value"];
|
||
1 year ago
|
} else
|
||
1 year ago
|
if (newTag.tag=="property"&&newTag.data["name"]=="Level Type") {
|
||
|
parsedMapInfo.mapType=newTag.data["value"];
|
||
|
} else
|
||
1 year ago
|
if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") {
|
||
|
parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2};
|
||
|
} else
|
||
1 year ago
|
if (newTag.tag=="object"&&newTag.data["type"]=="Monster") {
|
||
|
monsterTag=newTag;
|
||
|
monsterPropertyTagCount=0;
|
||
|
} else
|
||
|
if (newTag.tag=="property"&&monsterPropertyTagCount==0) {
|
||
|
monsterTag.data["value"]=newTag.data["value"];
|
||
12 months ago
|
parsedMapInfo.spawns.insert(newTag.GetString("value"));
|
||
1 year ago
|
monsterPropertyTagCount++;
|
||
|
} else
|
||
|
if (newTag.tag=="property"&&monsterPropertyTagCount==1) {
|
||
|
spawnerLinkTag=newTag;
|
||
|
monsterTag.data["spawnerLink"]=spawnerLinkTag.data["value"];
|
||
|
accumulatedMonsterTags.push_back(monsterTag);
|
||
|
monsterPropertyTagCount=-1;
|
||
1 year ago
|
} else
|
||
|
if (newTag.tag=="object"&&newTag.data["type"]=="StagePlate") {
|
||
|
if(newTag.GetInteger("id")!=0){
|
||
|
stagePlates[newTag.GetInteger("id")]={newTag};
|
||
|
currentStagePlate=&stagePlates.at(newTag.GetInteger("id"));
|
||
|
}
|
||
|
} else
|
||
|
if(newTag.tag=="property"&¤tStagePlate!=nullptr){
|
||
|
currentStagePlate->properties[newTag.data["name"]]={newTag.data["name"],newTag.data["value"]};
|
||
1 year ago
|
}else
|
||
|
if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end()){
|
||
|
//This is an object with a type that doesn't fit into other categories, we can add it to ZoneData.
|
||
|
if(parsedMapInfo.ZoneData.find(newTag.data["type"])!=parsedMapInfo.ZoneData.end()){
|
||
1 year ago
|
std::vector<ZoneData>&zones=parsedMapInfo.ZoneData.at(newTag.data["type"]);
|
||
|
zones.emplace_back(geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}});
|
||
|
prevZoneData=&zones.back();
|
||
1 year ago
|
} else {
|
||
1 year ago
|
std::vector<ZoneData>&zones=parsedMapInfo.ZoneData[newTag.data["type"]];
|
||
|
zones.emplace_back(geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}});
|
||
|
prevZoneData=&zones.back();
|
||
1 year ago
|
}
|
||
1 year ago
|
}else{
|
||
1 year ago
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n";
|
||
1 year ago
|
}
|
||
1 year ago
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n";
|
||
1 year ago
|
}
|
||
1 year ago
|
TMXParser::TMXParser(std::string file){
|
||
1 year ago
|
std::ifstream f(file,std::ios::in);
|
||
|
|
||
|
std::string accumulator="";
|
||
|
|
||
1 year ago
|
while (f.good()&&!infiniteMap) {
|
||
1 year ago
|
std::string data;
|
||
|
f>>data;
|
||
|
if (data.empty()) continue;
|
||
|
|
||
|
if (accumulator.length()>0) {
|
||
|
accumulator+=" "+data;
|
||
|
//Check if it ends with '>'
|
||
|
if (data[data.length()-1]=='>') {
|
||
|
ParseTag(accumulator);
|
||
|
accumulator="";
|
||
|
}
|
||
|
} else
|
||
|
if (data[0]=='<') {
|
||
|
//Beginning of XML tag.
|
||
|
accumulator=data;
|
||
1 year ago
|
if(accumulator.length()>1&&accumulator.at(1)=='/'){
|
||
|
accumulator=""; //Restart because this is an end tag.
|
||
|
}
|
||
|
if(accumulator.length()>1&&accumulator.find('>')!=std::string::npos){
|
||
|
accumulator=""; //Restart because this tag has nothing in it!
|
||
|
}
|
||
1 year ago
|
} else {
|
||
|
//Start reading in data for this layer.
|
||
|
std::vector<int>rowData;
|
||
|
while (data.find(",")!=std::string::npos) {
|
||
|
std::string datapiece = data.substr(0,data.find(","));
|
||
|
data = data.substr(data.find(",")+1,std::string::npos);
|
||
|
rowData.push_back(stoi(datapiece));
|
||
|
}
|
||
|
if (data.length()) {
|
||
|
rowData.push_back(stoi(data));
|
||
|
}
|
||
|
parsedMapInfo.LayerData[parsedMapInfo.LayerData.size()-1].tiles.push_back(rowData);
|
||
|
}
|
||
|
}
|
||
|
|
||
1 year ago
|
if(infiniteMap){
|
||
1 year ago
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Infinite map detected. Parsing stopped early."<<std::endl;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
for(XMLTag&monster:accumulatedMonsterTags){
|
||
|
parsedMapInfo.SpawnerData[monster.GetInteger("spawnerLink")].monsters.push_back(monster);
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
|
for(auto&spawnerData:parsedMapInfo.SpawnerData){
|
||
|
SpawnerTag&spawner=spawnerData.second;
|
||
|
for(auto&zoneData:parsedMapInfo.ZoneData){
|
||
|
if(zoneData.first=="UpperZone"){
|
||
1 year ago
|
std::vector<ZoneData>&zones=zoneData.second;
|
||
|
for(ZoneData&zone:zones){
|
||
|
if(geom2d::overlaps(zone.zone,geom2d::rect<int>{{spawner.ObjectData.GetInteger("x"),spawner.ObjectData.GetInteger("y")},{spawner.ObjectData.GetInteger("width"),spawner.ObjectData.GetInteger("height")}})){
|
||
1 year ago
|
spawner.upperLevel=true;
|
||
|
goto continueSpawnerLoop;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
continueSpawnerLoop:
|
||
|
continue;
|
||
|
}
|
||
1 year ago
|
|
||
|
std::sort(parsedMapInfo.TilesetData.begin(),parsedMapInfo.TilesetData.end(),[](XMLTag&t1,XMLTag&t2){return t1.GetInteger("firstgid")<t2.GetInteger("firstgid");});
|
||
|
|
||
1 year ago
|
std::map<int,int>idToIndexMap; //Since the original map data relies on IDs decided by Tiled and we are condensing all this data into a vector of connection points, each connection point is going to be in a different ID.
|
||
|
//therefore, we need to convert the Tiled IDs into whatever vector index we insert each connection into for State_OverworldMap::connections.
|
||
|
for(auto key:stagePlates){
|
||
|
StagePlate&plate=key.second;
|
||
1 year ago
|
idToIndexMap[plate.tag.GetInteger("id")]=int(State_OverworldMap::connections.size());
|
||
1 year ago
|
ConnectionPoint newConnection={{{plate.tag.GetFloat("x"),plate.tag.GetFloat("y")},{plate.tag.GetFloat("width"),plate.tag.GetFloat("height")}},plate.properties["Type"].value,plate.tag.data["name"],plate.properties["Map"].value,plate.properties["Unlock Condition"].value,{}};
|
||
1 year ago
|
int iterationCount=0;
|
||
|
for(auto key2:plate.properties){
|
||
|
if(key2.first.starts_with("Connection ")){
|
||
|
newConnection.neighbors[iterationCount]=key2.second.GetInteger();
|
||
|
iterationCount++;
|
||
|
}
|
||
|
}
|
||
|
State_OverworldMap::connections.push_back(newConnection);
|
||
|
}
|
||
|
for(ConnectionPoint&connection:State_OverworldMap::connections){
|
||
|
for(int&val:connection.neighbors){
|
||
|
if(idToIndexMap.count(val)){
|
||
|
val=idToIndexMap.at(val); //Convert from given Tiled ID to indexed ID in State_OverworldMap::connections
|
||
|
}
|
||
|
}
|
||
|
}
|
||
1 year ago
|
for(int counter=0;ConnectionPoint&connection:State_OverworldMap::connections){
|
||
1 year ago
|
for(int val:connection.neighbors){
|
||
|
if(val!=-1){
|
||
|
ConnectionPoint&neighbor=State_OverworldMap::connections.at(val);
|
||
|
//Find a blank slot that is available.
|
||
|
for(int i=0;i<neighbor.neighbors.size();i++){
|
||
|
if(neighbor.neighbors[i]==-1){ //We insert our neighbor pairing here.
|
||
|
neighbor.neighbors[i]=counter;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
counter++;
|
||
|
}
|
||
1 year ago
|
|
||
1 year ago
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
|
||
1 year ago
|
}
|
||
1 year ago
|
#endif
|