generated from sigonasr2/CPlusPlusProjectTemplate
Load/Saving of triggers is a go
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
4d7118f065
commit
23d50ad3c2
Binary file not shown.
35
main.cpp
35
main.cpp
@ -15,6 +15,7 @@
|
||||
#include "battleproperty.h"
|
||||
#include "map.h"
|
||||
#include "SeasonI.h"
|
||||
#include "trigger.h"
|
||||
|
||||
//#include "test/test.h"
|
||||
|
||||
@ -190,6 +191,8 @@ std::vector<std::vector<TILE*>> MAP2={};
|
||||
std::vector<std::vector<TILE*>> MAP3={};
|
||||
std::vector<std::vector<TILE*>> MAP4={};
|
||||
std::vector<std::vector<TILE*>> MAP5={}; //Collision Layer
|
||||
std::vector<Trigger*> TRIGGERS={};
|
||||
std::map<TriggerName::Trigger,Trigger*> Trigger::TRIGGERLIST={};
|
||||
std::map<std::string,Decal*> SPRITES;
|
||||
std::map<std::string,Animation*> ANIMATIONS={};
|
||||
std::map<int,Object*> OBJ_INFO={};
|
||||
@ -229,7 +232,6 @@ bool SeasonI::OnUserCreate(){
|
||||
SetupObjectInfo();
|
||||
SetupEncounters();
|
||||
SetupBattleProperties();
|
||||
|
||||
SetGameFlag(Flag::TEST_FLAG1,false);
|
||||
SetGameFlag(Flag::TEST_FLAG2,false);
|
||||
SetGameFlag(Flag::TEST_FLAG3,false);
|
||||
@ -791,6 +793,7 @@ void SeasonI::LoadMap(Map*map) {
|
||||
delete OBJECTS[i];
|
||||
}
|
||||
OBJECTS.clear();
|
||||
TRIGGERS.clear();
|
||||
for (int i=0;i<4;i++) {
|
||||
PARTY_MEMBER_OBJ[i]=nullptr;
|
||||
PARTY_MEMBER_ID[i]=0;
|
||||
@ -801,10 +804,13 @@ void SeasonI::LoadMap(Map*map) {
|
||||
if (MAP_WIDTH==-1) {
|
||||
MAP_WIDTH=data.length()/2;
|
||||
}
|
||||
if (data.find("OBJECT")!=std::string::npos||data.find("ENCOUNTER")!=std::string::npos) {
|
||||
if (data.find("OBJECT")!=std::string::npos||data.find("ENCOUNTER")!=std::string::npos
|
||||
||data.find("TRIGGER")!=std::string::npos) {
|
||||
int marker=data.find_first_of(';');
|
||||
int lastMarker=marker;
|
||||
std::stringstream split1((data.find("OBJECT")!=std::string::npos)?data.substr(6,marker-6):data.substr(9,marker-9));
|
||||
std::stringstream split1((data.find("OBJECT")!=std::string::npos)?data.substr(6,marker-6):
|
||||
(data.find("ENCOUNTER")!=std::string::npos)?data.substr(9,marker-9):
|
||||
(data.find("TRIGGER")!=std::string::npos)?data.substr(7,marker-7):"");
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
@ -846,6 +852,19 @@ void SeasonI::LoadMap(Map*map) {
|
||||
LoadEncounter(map,{x,y},pct,id,rand()%100<pct);
|
||||
|
||||
printf("Encounter %d (%d%c) Loaded.\n",id,pct,'%');
|
||||
} else
|
||||
if (data.find("TRIGGER")!=std::string::npos) {
|
||||
marker=data.find_first_of(';',marker+1);
|
||||
std::stringstream split4(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
int size_x,size_y;
|
||||
split4>>size_x;
|
||||
std::stringstream split5(data.substr(lastMarker+1,marker-lastMarker-1));
|
||||
lastMarker=marker;
|
||||
split5>>size_y;
|
||||
TRIGGERS.push_back(new Trigger({(int)x,(int)y},{size_x,size_y},id));
|
||||
map->triggers.push_back(Trigger::TRIGGERLIST[(TriggerName::Trigger)id]);
|
||||
printf("Trigger %d Loaded.\n",id);
|
||||
}
|
||||
} else {
|
||||
std::vector<TILE*> tiles;
|
||||
@ -968,6 +987,14 @@ void SeasonI::SaveMap(Map*map) {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<map->triggers.size();i++) {
|
||||
f.put('\n');
|
||||
const std::string trigger="TRIGGER"+std::to_string(map->triggers[i]->GetPosX())+";"+std::to_string(map->triggers[i]->GetPosY())+";"+";"+std::to_string(map->triggers[i]->GetID())+std::to_string(map->triggers[i]->GetSizeX())+";"+std::to_string(map->triggers[i]->GetSizeY());
|
||||
for (int j=0;j<trigger.length();j++) {
|
||||
f.put(trigger[j]);
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
f2.close();
|
||||
f3.close();
|
||||
@ -4283,7 +4310,7 @@ std::string SeasonI::Wrap(std::string str,int width,bool proportional,vd2d scale
|
||||
} else {
|
||||
word = str.substr(0,str.find(" "));
|
||||
}
|
||||
vi2d newSize = (proportional?GetTextSizeProp(newStr+(newStr.size()>0?" ":"")+word):GetTextSize(newStr+(newStr.size()>0?" ":"")+word))*scale;
|
||||
vi2d newSize = vd2d(proportional?GetTextSizeProp(newStr+(newStr.size()>0?" ":"")+word):GetTextSize(newStr+(newStr.size()>0?" ":"")+word))*scale;
|
||||
if (newSize.x>width) {
|
||||
newStr+="\n"+word;
|
||||
} else {
|
||||
|
||||
2
map.h
2
map.h
@ -2,6 +2,7 @@
|
||||
#define MAP_H
|
||||
#include "pixelGameEngine.h"
|
||||
#include "encounters.h"
|
||||
#include "trigger.h"
|
||||
|
||||
using namespace olc;
|
||||
|
||||
@ -14,6 +15,7 @@ class Map{
|
||||
std::string l5filename;
|
||||
Decal*tileset;
|
||||
std::vector<Encounter*> encounters;
|
||||
std::vector<Trigger*> triggers;
|
||||
Map(std::string fname,std::string layer2_fname,std::string layer3_fname,std::string layer4_fname,std::string layer5_fname,Decal*tileset) {
|
||||
this->filename=fname;
|
||||
this->l2filename=layer2_fname;
|
||||
|
||||
42
trigger.h
Normal file
42
trigger.h
Normal file
@ -0,0 +1,42 @@
|
||||
#include "pixelGameEngine.h"
|
||||
|
||||
using namespace olc;
|
||||
|
||||
namespace TriggerName{
|
||||
enum Trigger{
|
||||
START_CUTSCENE_1
|
||||
};
|
||||
}
|
||||
|
||||
class Trigger{
|
||||
vi2d pos;
|
||||
vi2d size;
|
||||
int id;
|
||||
public:
|
||||
Trigger(vi2d pos,vi2d size,int id)
|
||||
:pos(pos),size(size),id(id){}
|
||||
bool IsInside(vd2d point) {
|
||||
return point>pos&&point<pos+size;
|
||||
}
|
||||
vi2d GetPos() {
|
||||
return pos;
|
||||
}
|
||||
vi2d GetSize() {
|
||||
return size;
|
||||
}
|
||||
int GetPosX() {
|
||||
return pos.x;
|
||||
}
|
||||
int GetPosY() {
|
||||
return pos.y;
|
||||
}
|
||||
int GetSizeX() {
|
||||
return size.x;
|
||||
}
|
||||
int GetSizeY() {
|
||||
return size.y;
|
||||
}
|
||||
int GetID() {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user