Can now load maps from other directories.

This commit is contained in:
sigonasr2 2023-06-22 05:38:44 -07:00
parent 0294fdb8bc
commit e6268b0edc
3 changed files with 21 additions and 11 deletions

View File

@ -29,7 +29,7 @@ Crawler::Crawler()
bool Crawler::OnUserCreate(){
InitializeLevel("assets/maps/Level1.tmx",LEVEL1);
InitializeLevel("assets/maps/Level2.tmx",LEVEL2);
InitializeLevel("assets/maps/1_1_test.tmx",CAMPAIGN_1_1);
InitializeLevel("assets/Campaigns/1_1_test.tmx",CAMPAIGN_1_1);
//Initialize Camera.
camera=Camera2D{WINDOW_SIZE};
@ -133,7 +133,7 @@ bool Crawler::OnUserCreate(){
,{MonsterName::SLIME_BLUE,{(rand()%20/2.f-5)*24,(rand()%20/2.f-5)*24}}
}}));
LoadLevel(LEVEL1);
LoadLevel(CAMPAIGN_1_1);
return true;
}
@ -817,12 +817,16 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
std::string baseDir=mapFile.substr(0,slashMarker+1);
MAP_DATA[map]=level.GetData();
for(XMLTag&tag:MAP_DATA[map].TilesetData){
size_t slashMarkerSourceDir = tag.data["source"].find_last_of('/');
std::string baseSourceDir=tag.data["source"].substr(slashMarkerSourceDir+1);
if(MAP_TILESETS.find("assets/maps/"+baseSourceDir)==MAP_TILESETS.end()){
TSXParser tileset(baseDir+tag.data["source"]);
Renderable*r=new Renderable();
MAP_TILESETS[baseDir+tag.data["source"]]=r;
MAP_TILESETS["assets/maps/"+baseSourceDir]=r;
r->Load("assets/maps/"+tileset.GetData().ImageData.data["source"]);
}
}
}
void Crawler::LoadLevel(MapName map){
currentLevel=map;
@ -836,14 +840,20 @@ vi2d Crawler::GetWorldSize(){
TilesheetData Crawler::GetTileSheet(MapName map,int tileID){
std::vector<XMLTag>&tileData=MAP_DATA[map].TilesetData;
if(tileData.size()==1){
return {*MAP_TILESETS["assets/maps/"+tileData[0].data["source"]],1};
size_t slashMarkerSourceDir = tileData[0].data["source"].find_last_of('/');
std::string baseSourceDir=tileData[0].data["source"].substr(slashMarkerSourceDir+1);
return {*MAP_TILESETS["assets/maps/"+baseSourceDir],1};
} else {
for (int i=1;i<tileData.size();i++){
if(tileID<stoi(tileData[i].data["firstgid"])){
return {*MAP_TILESETS["assets/maps/"+tileData[i-1].data["source"]],stoi(tileData[i-1].data["firstgid"])};
size_t slashMarkerSourceDir = tileData[i-1].data["source"].find_last_of('/');
std::string baseSourceDir=tileData[i-1].data["source"].substr(slashMarkerSourceDir+1);
return {*MAP_TILESETS["assets/maps/"+baseSourceDir],stoi(tileData[i-1].data["firstgid"])};
}
}
return {*MAP_TILESETS["assets/maps/"+tileData[tileData.size()-1].data["source"]],stoi(tileData[tileData.size()-1].data["firstgid"])};
size_t slashMarkerSourceDir = tileData[tileData.size()-1].data["source"].find_last_of('/');
std::string baseSourceDir=tileData[tileData.size()-1].data["source"].substr(slashMarkerSourceDir+1);
return {*MAP_TILESETS["assets/maps/"+baseSourceDir],stoi(tileData[tileData.size()-1].data["firstgid"])};
}
}

View File

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 157
#define VERSION_BUILD 175
#define stringify(a) stringify_(a)
#define stringify_(a) #a

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="186" height="159" tilewidth="24" tileheight="24" infinite="0" nextlayerid="4" nextobjectid="1">
<tileset firstgid="1" source="grass_tiles_24x24.tsx"/>
<tileset firstgid="1" source="../maps/grass_tiles_24x24.tsx"/>
<layer id="1" name="Kachelebene 1" width="186" height="159">
<data encoding="csv">
31,32,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,