Added overworld map connection point reading to TMXParser.
This commit is contained in:
parent
b89311a657
commit
76136a3f68
@ -20,7 +20,7 @@ struct ClassInfo{
|
||||
class classutils{
|
||||
public:
|
||||
static inline Class StringToClass(std::string className){
|
||||
std::vector<std::string>classList=DATA["class_list"].GetValues();
|
||||
const std::vector<std::string>&classList=DATA["class_list"].GetValues();
|
||||
auto it=std::find(classList.begin(),classList.end(),className);
|
||||
int element=std::distance(classList.begin(),it);
|
||||
return Class(1<<element); //Yes...It's bitwise flags, who in god's name knows why I did this.
|
||||
|
@ -31,7 +31,7 @@ void Menu::InitializeClassSelectionWindow(){
|
||||
MenuComponent*confirmButton=new MenuComponent(CLASS_SELECTION,{{outlineSize.x+4-navigationButtonSize.x-2,outlineSize.y+4-navigationButtonSize.y-2},navigationButtonSize},"Confirm",[](MenuFuncData data){
|
||||
std::string selectedClass=data.component->S(A::CLASS_SELECTION);
|
||||
data.game->ChangePlayerClass(classutils::StringToClass(selectedClass));
|
||||
GameState::ChangeState(States::GAME_RUN);
|
||||
GameState::ChangeState(States::OVERWORLD_MAP);
|
||||
});
|
||||
confirmButton->disabled=true;
|
||||
classSelectionWindow->AddComponent("Confirm",confirmButton);
|
||||
|
12
Crawler/ConnectionPoint.h
Normal file
12
Crawler/ConnectionPoint.h
Normal file
@ -0,0 +1,12 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
struct ConnectionPoint{
|
||||
vf2d pos;
|
||||
std::string map;
|
||||
std::string unlockCondition;
|
||||
std::array<int,4>neighbors; //Indices into the connectionPoint array.
|
||||
ConnectionPoint(vf2d pos,std::string map,std::string unlockCondition)
|
||||
:pos(pos),map(map),unlockCondition(unlockCondition){
|
||||
neighbors.fill(-1);
|
||||
}
|
||||
};
|
@ -154,9 +154,8 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
|
||||
levelTime+=fElapsedTime;
|
||||
GameState::STATE->OnUserUpdate(this);
|
||||
RenderWorld(GetElapsedTime());
|
||||
RenderHud();
|
||||
RenderMenu();
|
||||
GameState::STATE->Draw(this);
|
||||
RenderMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -269,6 +269,7 @@
|
||||
<ClInclude Include="Class.h" />
|
||||
<ClInclude Include="ClassInfo.h" />
|
||||
<ClInclude Include="config.h" />
|
||||
<ClInclude Include="ConnectionPoint.h" />
|
||||
<ClInclude Include="Crawler.h" />
|
||||
<ClInclude Include="DamageNumber.h" />
|
||||
<ClInclude Include="DEFINES.h" />
|
||||
@ -350,6 +351,7 @@
|
||||
<ClCompile Include="SlimeKing.cpp" />
|
||||
<ClCompile Include="State_GameRun.cpp" />
|
||||
<ClCompile Include="State_MainMenu.cpp" />
|
||||
<ClCompile Include="State_OverworldMap.cpp" />
|
||||
<ClCompile Include="TestMenu.cpp" />
|
||||
<ClCompile Include="TestSubMenu.cpp" />
|
||||
<ClCompile Include="Thief.cpp" />
|
||||
|
@ -210,6 +210,9 @@
|
||||
<ClInclude Include="Toggleable.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ConnectionPoint.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Player.cpp">
|
||||
@ -359,6 +362,9 @@
|
||||
<ClCompile Include="MenuAnimatedIconButton.h">
|
||||
<Filter>Header Files\Interface</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="State_OverworldMap.cpp">
|
||||
<Filter>Source Files\Game States</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
void GameState::Initialize(){
|
||||
NEW_STATE(States::GAME_RUN,State_GameRun);
|
||||
NEW_STATE(States::OVERWORLD_MAP,State_OverworldMap);
|
||||
NEW_STATE(States::MAIN_MENU,State_MainMenu);
|
||||
|
||||
GameState::ChangeState(States::MAIN_MENU);
|
||||
|
@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include "ConnectionPoint.h"
|
||||
|
||||
class Crawler;
|
||||
|
||||
namespace States{
|
||||
enum State{
|
||||
GAME_RUN,
|
||||
OVERWORLD_MAP,
|
||||
MAIN_MENU,
|
||||
};
|
||||
};
|
||||
@ -36,6 +38,14 @@ class State_GameRun:public GameState{
|
||||
virtual void Draw(Crawler*game)override;
|
||||
};
|
||||
|
||||
class State_OverworldMap:public GameState{
|
||||
public:
|
||||
static std::vector<ConnectionPoint>connections;
|
||||
virtual void OnStateChange(GameState*prevState)override;
|
||||
virtual void OnUserUpdate(Crawler*game)override;
|
||||
virtual void Draw(Crawler*game)override;
|
||||
};
|
||||
|
||||
class State_MainMenu:public GameState{
|
||||
virtual void OnStateChange(GameState*prevState)override;
|
||||
virtual void OnUserUpdate(Crawler*game)override;
|
||||
|
@ -31,5 +31,5 @@ void State_GameRun::OnUserUpdate(Crawler*game){
|
||||
game->UpdateCamera(game->GetElapsedTime());
|
||||
};
|
||||
void State_GameRun::Draw(Crawler*game){
|
||||
|
||||
game->RenderHud();
|
||||
};
|
19
Crawler/State_OverworldMap.cpp
Normal file
19
Crawler/State_OverworldMap.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "GameState.h"
|
||||
#include "Crawler.h"
|
||||
#include "DEFINES.h"
|
||||
#include "Menu.h"
|
||||
#include "Item.h"
|
||||
|
||||
INCLUDE_MONSTER_LIST
|
||||
|
||||
std::vector<ConnectionPoint>State_OverworldMap::connections;
|
||||
|
||||
void State_OverworldMap::OnStateChange(GameState*prevState){
|
||||
Menu::CloseAllMenus();
|
||||
};
|
||||
void State_OverworldMap::OnUserUpdate(Crawler*game){
|
||||
|
||||
};
|
||||
void State_OverworldMap::Draw(Crawler*game){
|
||||
|
||||
};
|
@ -2,6 +2,7 @@
|
||||
#include "olcPixelGameEngine.h"
|
||||
#include "olcUTIL_Geometry2D.h"
|
||||
#include <sstream>
|
||||
#include "GameState.h"
|
||||
|
||||
using namespace olc;
|
||||
|
||||
@ -57,6 +58,20 @@ struct Map{
|
||||
friend std::ostream& operator << (std::ostream& os, std::vector<XMLTag>& rhs);
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class TMXParser{
|
||||
public:
|
||||
Map GetData();
|
||||
@ -69,13 +84,16 @@ class TMXParser{
|
||||
int monsterPropertyTagCount=-1;
|
||||
XMLTag monsterTag;
|
||||
XMLTag spawnerLinkTag;
|
||||
StagePlate*currentStagePlate;
|
||||
std::vector<XMLTag>accumulatedMonsterTags;
|
||||
std::map<int,StagePlate>stagePlates;
|
||||
bool infiniteMap=false;
|
||||
public:
|
||||
TMXParser(std::string file);
|
||||
};
|
||||
|
||||
typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
//#define TMX_PARSER_SETUP //Toggle for code-writing.
|
||||
|
||||
#ifdef TMX_PARSER_SETUP
|
||||
#undef TMX_PARSER_SETUP
|
||||
@ -114,6 +132,22 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
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}){}
|
||||
@ -222,23 +256,29 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
|
||||
XMLTag newTag=ReadNextTag();
|
||||
|
||||
if (newTag.tag=="map") {
|
||||
if (newTag.tag=="object"&&newTag.data["type"]!="StagePlate") {
|
||||
currentStagePlate=nullptr;
|
||||
}
|
||||
|
||||
if (newTag.tag=="map"){
|
||||
if(stoi(newTag.data["infinite"])==1){
|
||||
infiniteMap=true;
|
||||
return;
|
||||
}
|
||||
parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"]),stoi(newTag.data["tilewidth"]),stoi(newTag.data["tileheight"])};
|
||||
} else
|
||||
if (newTag.tag=="tileset") {
|
||||
if (newTag.tag=="tileset"){
|
||||
parsedMapInfo.TilesetData.push_back(newTag);
|
||||
} else
|
||||
if (newTag.tag=="layer") {
|
||||
if (newTag.tag=="layer"){
|
||||
LayerTag l = {newTag};
|
||||
parsedMapInfo.LayerData.push_back(l);
|
||||
}else
|
||||
if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup") {
|
||||
parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag};
|
||||
prevSpawner=newTag.GetInteger("id");
|
||||
if(newTag.GetInteger("id")!=0){
|
||||
parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag};
|
||||
prevSpawner=newTag.GetInteger("id");
|
||||
}
|
||||
} else
|
||||
if (newTag.tag=="property"&&newTag.data["name"]=="Optimize"&&newTag.data["value"]=="true") {
|
||||
parsedMapInfo.MapData.optimized=true;
|
||||
@ -250,10 +290,7 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2};
|
||||
} else
|
||||
if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end()
|
||||
&&newTag.data.find("x")!=newTag.data.end()
|
||||
&&newTag.data.find("y")!=newTag.data.end()
|
||||
&&newTag.data.find("width")!=newTag.data.end()
|
||||
&&newTag.data.find("height")!=newTag.data.end()){
|
||||
&&(newTag.data["type"]=="LowerZone"||newTag.data["type"]=="UpperZone")){
|
||||
//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()){
|
||||
std::vector<geom2d::rect<int>>&zones=parsedMapInfo.ZoneData[newTag.data["type"]];
|
||||
@ -280,7 +317,16 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
monsterTag.data["spawnerLink"]=spawnerLinkTag.data["value"];
|
||||
accumulatedMonsterTags.push_back(monsterTag);
|
||||
monsterPropertyTagCount=-1;
|
||||
} else {
|
||||
} 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"]};
|
||||
}else{
|
||||
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n";
|
||||
}
|
||||
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"\n"<<"=============\n";
|
||||
@ -354,6 +400,30 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
|
||||
std::sort(parsedMapInfo.TilesetData.begin(),parsedMapInfo.TilesetData.end(),[](XMLTag&t1,XMLTag&t2){return t1.GetInteger("firstgid")<t2.GetInteger("firstgid");});
|
||||
|
||||
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;
|
||||
idToIndexMap[plate.tag.GetInteger("id")]=State_OverworldMap::connections.size();
|
||||
ConnectionPoint newConnection={{plate.tag.GetFloat("x"),plate.tag.GetFloat("y")},plate.properties["Map"].value,plate.properties["Unlock Condition"].value};
|
||||
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){
|
||||
std::array<int,4>;
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
|
||||
}
|
||||
#endif
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 2407
|
||||
#define VERSION_BUILD 2428
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -578,6 +578,7 @@
|
||||
<properties>
|
||||
<property name="Connection 1" type="object" value="9"/>
|
||||
<property name="Connection 2" type="object" value="0"/>
|
||||
<property name="Connection 3" type="object" value="0"/>
|
||||
<property name="Map" propertytype="Level" value="CAMPAIGN_1_3"/>
|
||||
<property name="Unlock Condition" propertytype="Level" value="CAMPAIGN_1_2"/>
|
||||
</properties>
|
||||
@ -597,6 +598,8 @@
|
||||
</object>
|
||||
<object id="9" name="Stage 4" type="StagePlate" x="172" y="580" width="44" height="16">
|
||||
<properties>
|
||||
<property name="Connection 1" type="object" value="0"/>
|
||||
<property name="Connection 2" type="object" value="0"/>
|
||||
<property name="Map" propertytype="Level" value="CAMPAIGN_1_4"/>
|
||||
<property name="Unlock Condition" propertytype="Level" value="CAMPAIGN_1_3"/>
|
||||
</properties>
|
||||
|
@ -82,8 +82,6 @@ Removed unused "range" facility in TileTransformView
|
||||
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
|
||||
|
||||
namespace olc
|
||||
{
|
||||
class TransformedView : public olc::PGEX
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user