a bunch of changes
This commit is contained in:
parent
1e0dfc4570
commit
8f01039689
20 changed files with 577 additions and 120 deletions
|
|
@ -22,66 +22,6 @@ enum LayerConfig{
|
|||
Temporary //Tmp
|
||||
};
|
||||
|
||||
inline std::string ToStringYaml(LayerConfig cfg){
|
||||
if(cfg == Common){
|
||||
return "Cmn";
|
||||
} else if(cfg == Paint){
|
||||
return "Pnt";
|
||||
} else if(cfg == Rainmaker) {
|
||||
return "Vlf";
|
||||
} else if(cfg == Tower) {
|
||||
return "Vgl";
|
||||
} else if(cfg == Area) {
|
||||
return "Var";
|
||||
} else if(cfg == Night) {
|
||||
return "Night";
|
||||
} else if(cfg == Day) {
|
||||
return "Day";
|
||||
} else if(cfg == Temporary) {
|
||||
return "Tmp";
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string ToString(LayerConfig cfg){
|
||||
if(cfg == Common){
|
||||
return "Common";
|
||||
} else if(cfg == Paint){
|
||||
return "Paint";
|
||||
} else if(cfg == Rainmaker) {
|
||||
return "Rainmaker";
|
||||
} else if(cfg == Tower) {
|
||||
return "Tower";
|
||||
} else if(cfg == Area) {
|
||||
return "Area";
|
||||
} else if(cfg == Night) {
|
||||
return "Night";
|
||||
} else if(cfg == Day) {
|
||||
return "Day";
|
||||
} else if(cfg == Temporary) {
|
||||
return "Temporary";
|
||||
}
|
||||
}
|
||||
|
||||
inline LayerConfig ToLayerConfig(std::string cfg){
|
||||
if(cfg == "Cmn"){
|
||||
return Common;
|
||||
} else if(cfg == "Pnt"){
|
||||
return Paint;
|
||||
} else if(cfg == "Vlf") {
|
||||
return Rainmaker;
|
||||
} else if(cfg == "Vgl") {
|
||||
return Tower;
|
||||
} else if(cfg == "Var") {
|
||||
return Area;
|
||||
} else if(cfg == "Night") {
|
||||
return Night;
|
||||
} else if(cfg == "Day") {
|
||||
return Day;
|
||||
} else if(cfg == "Tmp") {
|
||||
return Temporary;
|
||||
} else return Temporary;
|
||||
}
|
||||
|
||||
class Element{
|
||||
public:
|
||||
Element() = default;
|
||||
|
|
@ -106,11 +46,11 @@ public:
|
|||
std::map<std::string,std::string> OtherOptions = std::map<std::string,std::string>();
|
||||
|
||||
bool IsLinkDest = false;
|
||||
void YamlInsert(YAML::Emitter &Emitter);
|
||||
void YamlInsert(YAML::Emitter &Emitter,bool compiled = false);
|
||||
|
||||
virtual ~Element() = default;
|
||||
protected:
|
||||
virtual void YamlInsertBody(YAML::Emitter &Emitter);
|
||||
virtual void YamlInsertBody(YAML::Emitter &Emitter,bool compiled = false);
|
||||
};
|
||||
|
||||
#endif //SPOONTOOL_ELEMENT_H
|
||||
|
|
@ -18,18 +18,14 @@ namespace Teams{
|
|||
constexpr long Enemy = 1;
|
||||
constexpr long Neutral = 2;
|
||||
|
||||
constexpr std::array<long,3> AllOptions = {Player,Neutral,Enemy};
|
||||
|
||||
inline constexpr std::string TeamToText(long team) {
|
||||
inline long flipTeam(long team){
|
||||
switch(team){
|
||||
case 0:
|
||||
return "Player";
|
||||
case 1:
|
||||
return "Enemy";
|
||||
case 2:
|
||||
return "Neutral";
|
||||
case Player:
|
||||
return Enemy;
|
||||
case Enemy:
|
||||
return Player;
|
||||
default:
|
||||
return "Invalid";
|
||||
return team;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -77,10 +73,11 @@ struct LevelObject: public Element{
|
|||
LevelObject(const YAML::Node &ObjNode);
|
||||
|
||||
protected:
|
||||
void YamlInsertBody(YAML::Emitter &Emitter) override;
|
||||
void YamlInsertBody(YAML::Emitter &Emitter,bool compiled = false) override;
|
||||
public:
|
||||
long Team;
|
||||
long DropId;
|
||||
bool m_isStatic;
|
||||
|
||||
~LevelObject() = default;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,11 +8,17 @@
|
|||
#include<boost/filesystem.hpp>
|
||||
#include<LevelObject.h>
|
||||
#include<Rail.h>
|
||||
#include<filesystem>
|
||||
|
||||
struct FieldOptions{
|
||||
std::string m_fieldName = "Fld_Unk";
|
||||
|
||||
};
|
||||
|
||||
struct Map {
|
||||
//STREEFUNCS
|
||||
Map();
|
||||
//Loads file from custom map format
|
||||
Map(boost::filesystem::path file);
|
||||
|
||||
void Save(boost::filesystem::path FileLocation);
|
||||
|
||||
|
|
@ -20,16 +26,19 @@ struct Map {
|
|||
|
||||
void Export(boost::filesystem::path YamlOut);
|
||||
|
||||
std::vector<LevelObject> Objects;
|
||||
std::list<LevelObject> Objects;
|
||||
|
||||
std::vector<Rail> Rails;
|
||||
std::list<Rail> Rails;
|
||||
|
||||
std::filesystem::path m_filePath;
|
||||
|
||||
FieldOptions m_fieldOptions;
|
||||
|
||||
Element* GetElementById(std::string id);
|
||||
|
||||
|
||||
};
|
||||
|
||||
Map ConvertFromYaml(boost::filesystem::path File);
|
||||
|
||||
|
||||
|
||||
#endif //SPOONTOOL_MAP_H
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ struct Rail: public Element{
|
|||
~Rail() override = default;
|
||||
|
||||
protected:
|
||||
void YamlInsertBody(YAML::Emitter &Emitter) override;
|
||||
void YamlInsertBody(YAML::Emitter &Emitter,bool compiled = false) override;
|
||||
};
|
||||
|
||||
#endif //SPOONTOOL_RAIL_H
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ struct RailPoint: public Element{
|
|||
|
||||
protected:
|
||||
|
||||
void YamlInsertBody(YAML::Emitter &Emitter) override;
|
||||
void YamlInsertBody(YAML::Emitter &Emitter,bool compiled = false) override;
|
||||
public:
|
||||
|
||||
std::vector<Vector3> m_controlPoints = std::vector<Vector3>();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
#include <iomanip>
|
||||
|
||||
Element::Element(const YAML::Node &ObjNode,std::list<std::string> PropertyBlockList) {
|
||||
|
||||
PropertyBlockList.emplace_back("Id");
|
||||
PropertyBlockList.emplace_back("UnitConfigName");
|
||||
PropertyBlockList.emplace_back("LayerConfigName");
|
||||
|
|
@ -76,13 +75,13 @@ Element::Element(const YAML::Node &ObjNode,std::list<std::string> PropertyBlockL
|
|||
|
||||
}
|
||||
|
||||
void Element::YamlInsert(YAML::Emitter &Emitter) {
|
||||
void Element::YamlInsert(YAML::Emitter &Emitter,bool compiled) {
|
||||
Emitter << YAML::BeginMap;
|
||||
YamlInsertBody(Emitter);
|
||||
YamlInsertBody(Emitter,compiled);
|
||||
Emitter << YAML::EndMap;
|
||||
}
|
||||
|
||||
void Element::YamlInsertBody(YAML::Emitter &Emitter) {
|
||||
void Element::YamlInsertBody(YAML::Emitter &Emitter,bool compiled) {
|
||||
Emitter << YAML::Key << "Id" << YAML::Value << Name;
|
||||
|
||||
TF.InsertIntoYaml(Emitter);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
#include<LevelObject.h>
|
||||
#include<SpecialObjectParamVersions/All.h>
|
||||
|
||||
LevelObject::LevelObject(const YAML::Node &ObjNode): Element(ObjNode,{"Team","DropId"}) {
|
||||
LevelObject::LevelObject(const YAML::Node &ObjNode): Element(ObjNode,{"Team","DropId","IsStatic"}) {
|
||||
Team = ObjNode["Team"].as<long>(-1);
|
||||
DropId = ObjNode["DropId"].as<long>(DropId::Default);
|
||||
m_isStatic = ObjNode["IsStatic"].as<bool>(false);
|
||||
|
||||
}
|
||||
|
||||
void LevelObject::YamlInsertBody(YAML::Emitter &Emitter) {
|
||||
void LevelObject::YamlInsertBody(YAML::Emitter &Emitter,bool compiled) {
|
||||
Element::YamlInsertBody(Emitter);
|
||||
Emitter << YAML::Key << "Team" << YAML::Value << YAML::LocalTag("l") << Team;
|
||||
Emitter << YAML::Key << "DropId" << YAML::Value << YAML::LocalTag("l") << DropId;
|
||||
if(!compiled){
|
||||
Emitter << YAML::Key << "IsStatic" << YAML::Value << m_isStatic;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,76 @@ Map::Map(): Objects(), Rails() {
|
|||
|
||||
}
|
||||
|
||||
void Map::Save(boost::filesystem::path FileLocation) {
|
||||
Map::Map(boost::filesystem::path file): Objects(), Rails(), m_fieldOptions() {
|
||||
|
||||
YAML::Node MapYaml = YAML::LoadFile(file.generic_string());
|
||||
|
||||
auto FldOpts = MapYaml["MapGenInfo"];
|
||||
|
||||
m_fieldOptions.m_fieldName = FldOpts["FldName"].as<std::string>();
|
||||
|
||||
auto ObjList = MapYaml["Objects"];
|
||||
|
||||
if(!ObjList.IsSequence()) throw std::runtime_error("Something went Wrong!");
|
||||
|
||||
|
||||
for (YAML::iterator it = ObjList.begin(); it != ObjList.end(); it++) {
|
||||
const YAML::Node& obj = *it;
|
||||
|
||||
Objects.push_back(LevelObject(obj));
|
||||
}
|
||||
|
||||
auto RailList = MapYaml["Rails"];
|
||||
|
||||
if(!RailList.IsSequence()) throw std::runtime_error("Failed to load map:\n\tRail list isn't a sequence");
|
||||
|
||||
for (YAML::iterator it = RailList.begin(); it != RailList.end(); it++) {
|
||||
const YAML::Node& obj = *it;
|
||||
|
||||
Rail newObj(obj);
|
||||
|
||||
Rails.push_back(newObj);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::Save(boost::filesystem::path FileLocation) {
|
||||
YAML::Emitter Emitter;
|
||||
|
||||
Emitter << YAML::BeginMap;
|
||||
//Emitter << YAML::
|
||||
|
||||
Emitter << YAML::Key << "MapGenInfo" << YAML::BeginMap;
|
||||
{
|
||||
Emitter << YAML::Key << "FldName" << YAML::Value << m_fieldOptions.m_fieldName;
|
||||
}
|
||||
Emitter << YAML::EndMap;
|
||||
|
||||
Emitter << YAML::Key << "Objects" << YAML::BeginSeq;
|
||||
|
||||
for(auto& obj: Objects){
|
||||
obj.YamlInsert(Emitter);
|
||||
}
|
||||
//Objs
|
||||
Emitter << YAML::EndSeq;
|
||||
|
||||
Emitter << YAML::Key << "Rails" << YAML::BeginSeq;
|
||||
|
||||
for(auto obj: Rails){
|
||||
obj.YamlInsert(Emitter);
|
||||
}
|
||||
Emitter << YAML::EndSeq;
|
||||
//main document
|
||||
Emitter << YAML::EndMap;
|
||||
|
||||
std::ofstream file(FileLocation.string());
|
||||
|
||||
std::string str = Emitter.c_str();
|
||||
|
||||
boost::algorithm::replace_all(str,"~","null");
|
||||
|
||||
file << str;
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
void Map::Export(boost::filesystem::path YamlOut) {
|
||||
|
|
@ -36,7 +104,7 @@ void Map::Export(boost::filesystem::path YamlOut) {
|
|||
Emitter << YAML::Key << "Objs" << YAML::BeginSeq;
|
||||
|
||||
for(auto& obj: Objects){
|
||||
obj.YamlInsert(Emitter);
|
||||
obj.YamlInsert(Emitter,true);
|
||||
}
|
||||
//Objs
|
||||
Emitter << YAML::EndSeq;
|
||||
|
|
@ -44,7 +112,7 @@ void Map::Export(boost::filesystem::path YamlOut) {
|
|||
Emitter << YAML::Key << "Rails" << YAML::BeginSeq;
|
||||
|
||||
for(auto obj: Rails){
|
||||
obj.YamlInsert(Emitter);
|
||||
obj.YamlInsert(Emitter,true);
|
||||
}
|
||||
Emitter << YAML::EndSeq;
|
||||
|
||||
|
|
@ -104,6 +172,8 @@ Map ConvertFromYaml(boost::filesystem::path File){
|
|||
|
||||
auto RailList = RootNode["Rails"];
|
||||
|
||||
if(!RailList.IsSequence()) throw std::runtime_error("Something went Wrong!");
|
||||
|
||||
for (YAML::iterator it = RailList.begin(); it != RailList.end(); it++) {
|
||||
const YAML::Node& obj = *it;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Rail::Rail(const Vector3 &Position) {
|
|||
Points.emplace_back(Position);
|
||||
}
|
||||
|
||||
void Rail::YamlInsertBody(YAML::Emitter &Emitter) {
|
||||
void Rail::YamlInsertBody(YAML::Emitter &Emitter,bool compiled) {
|
||||
Element::YamlInsertBody(Emitter);
|
||||
|
||||
Emitter << YAML::Key << "RailPoints" << YAML::BeginSeq;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ RailPoint::RailPoint(const Vector3 &pos) {
|
|||
m_controlPoints.push_back(pos);
|
||||
}
|
||||
|
||||
void RailPoint::YamlInsertBody(YAML::Emitter &Emitter) {
|
||||
void RailPoint::YamlInsertBody(YAML::Emitter &Emitter,bool compiled) {
|
||||
Element::YamlInsertBody(Emitter);
|
||||
Emitter << YAML::Key << "ControlPoints" << YAML::BeginSeq;
|
||||
for(auto ctrlPoint: m_controlPoints){
|
||||
|
|
|
|||
Loading…
Reference in a new issue