Skip to content

Commit

Permalink
Merge branch 'master' into update-stonesense-authors
Browse files Browse the repository at this point in the history
  • Loading branch information
realSquidCoder authored Jan 19, 2025
2 parents fa38844 + bc62251 commit 47ad84f
Show file tree
Hide file tree
Showing 45 changed files with 1,528 additions and 1,537 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ SET(PROJECT_HDRS
DumpInfo.h
FluidConfiguration.h
GameBuildings.h
GameConfiguration.h
GameState.h
GroundMaterialConfiguration.h
GUI.h
ItemConfiguration.h
Expand All @@ -67,6 +69,7 @@ SET(PROJECT_HDRS
SpriteColors.h
SpriteMaps.h
SpriteObjects.h
StonesenseState.h
Tile.h
TileCondition.h
TileDirection.h
Expand Down
8 changes: 4 additions & 4 deletions ColorConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "ColorConfiguration.h"
#include "ContentLoader.h"
#include <vector>

using namespace DFHack;
using namespace df::enums;
#include "ColorConfiguration.h"
#include "ContentLoader.h"
#include "StonesenseState.h"

using std::string;
using std::vector;
Expand Down Expand Up @@ -109,6 +108,7 @@ bool addSingleColorConfig( TiXmlElement* elemRoot)
if(elementType.compare( "colors" ) == 0) {
//parse colors
TiXmlElement* elemColor = elemRoot->FirstChildElement("color");
auto& contentLoader = stonesenseState.contentLoader;
while( elemColor ) {
parseColorElement( elemColor, contentLoader->colorConfigs, contentLoader->materialColorConfigs);
elemColor = elemColor->NextSiblingElement("color");
Expand Down
7 changes: 3 additions & 4 deletions ConditionalSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#include "Tile.h"
#include "GameBuildings.h"
#include "GUI.h"

using namespace DFHack;
using namespace df::enums;
#include "GameState.h"
#include "StonesenseState.h"

/* RootTile */

Expand Down Expand Up @@ -95,7 +94,7 @@ RotationTile::~RotationTile(void)

bool RotationTile::copyToTile(Tile* b)
{
int index = ssState.Rotation;
int index = stonesenseState.ssState.Rotation;
size_t max = children.size();
if (max == 0) {
return false;
Expand Down
60 changes: 27 additions & 33 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include "common.h"
#include "commonTypes.h"
#include "Config.h"
#include "GameConfiguration.h"
#include "GameState.h"
#include "StonesenseState.h"

using std::string;

using namespace DFHack;
using namespace df::enums;

namespace {
string parseStrFromLine(string keyword, string line)
{
Expand All @@ -33,43 +33,37 @@ namespace {

int parseIntFromLine(string keyword, string line)
{
int retVal = 0;
string trimString = "";
trimString += "[";
trimString += keyword;
trimString += ":";
int length = (int)trimString.length();
auto tmp = parseStrFromLine(keyword, line);
return tmp.empty() ? 0 : atoi(tmp.c_str());
}
}

std::optional<std::string> trim_line(std::string line)
{
if (line.empty())
return std::nullopt;

if (line.compare(0, length, trimString) == 0) {
line.replace(0, length, "");
line.replace(line.length() - 1, 1, "");
retVal = atoi(line.c_str());
}
if (!line.starts_with("["))
return std::nullopt;

return retVal;
}
if (line.ends_with("\r"))
line.resize(line.size() - 1);

if (!line.ends_with("]"))
return std::nullopt;

return std::optional{ line };
}

namespace {
void parseConfigLine(string line)
{
if (line.empty()) {
return;
}
char c = line[0];
if (c != '[') {
return;
}
auto l = trim_line(line);
if (!l) return;
line = *l;

//some systems don't remove the \r char as a part of the line change:
if (line.size() > 0 && line[line.size() - 1] == '\r') {
line.resize(line.size() - 1);
}

c = line[line.length() - 1];
if (c != ']') {
return;
}
auto& ssConfig = stonesenseState.ssConfig;
auto& ssState = stonesenseState.ssState;

if (line.find("[CLOSEONESC") != string::npos) {
string result = parseStrFromLine("CLOSEONESC", line);
Expand Down Expand Up @@ -836,7 +830,7 @@ bool loadConfigFile()
parseConfigLine( line );
}
// update allegro colors loaded from file
ssConfig.colors.update();
stonesenseState.ssConfig.colors.update();
//close file, etc.
myfile.close();
return true;
Expand Down
4 changes: 4 additions & 0 deletions Config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#pragma once
#include <optional>
#include <string>

#include "common.h"

constexpr auto KEYMOD_NONE = 0;
Expand All @@ -9,3 +12,4 @@ struct action_name_mapper {
};

bool loadConfigFile();
std::optional<std::string> trim_line(std::string line);
6 changes: 2 additions & 4 deletions Constructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include "Constructions.h"
#include "WorldSegment.h"

using namespace DFHack;
using namespace df::enums;

using std::vector;

void changeConstructionMaterials(WorldSegment* segment, vector<df::construction>* allConstructions)
Expand All @@ -17,7 +14,7 @@ void changeConstructionMaterials(WorldSegment* segment, vector<df::construction>
if( !b ) {
continue;
}
if (b->tileMaterial() != tiletype_material::CONSTRUCTION)
if (b->tileMaterial() != df::tiletype_material::CONSTRUCTION)
continue;
//don't assign invalid material indexes
//if(construct->mat_idx != -1){
Expand All @@ -40,6 +37,7 @@ bool readConstructionsToTile( Tile* b, const Stonesense_Building* building )

switch(building->construction_type)
{
using df::construction_type;
case construction_type::Fortification:
constructedTiletype = df::tiletype::ConstructedFortification;
break;
Expand Down
19 changes: 8 additions & 11 deletions ContentBuildingReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "df/world.h"
#include "df/world_raws.h"

using namespace DFHack;
using namespace df::enums;

using std::string;

int parseConditionNode(ConditionalNode* node, TiXmlElement* elemCondition, bool silent);
Expand Down Expand Up @@ -280,6 +277,7 @@ bool parseSpriteNode(SpriteNode* node, TiXmlElement* elemParent)

bool addSingleBuildingConfig( TiXmlElement* elemRoot, std::vector<std::unique_ptr<BuildingConfiguration>>*knownBuildings)
{
using df::building_type;
const char* strName = elemRoot->Attribute("name");
const char* strGameID = elemRoot->Attribute("game_type");
const char* strGameSub = elemRoot->Attribute("game_subtype");
Expand All @@ -289,7 +287,7 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, std::vector<std::unique_p
contentError("<building> node must have name and game_type attributes",elemRoot);
return false;
}
building_type::building_type main_type = BUILDINGTYPE_NA;
df::building_type main_type = BUILDINGTYPE_NA;
int subtype = INVALID_INDEX;
string game_type_s;
FOR_ENUM_ITEMS(building_type,i) {
Expand Down Expand Up @@ -329,7 +327,7 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, std::vector<std::unique_p
contentError("<building> unknown game_subtype value",elemRoot);
return false;
}
if(subtype == furnace_type::Custom) {
if(subtype == df::furnace_type::Custom) {
needs_custom = true;
}
break;
Expand Down Expand Up @@ -400,7 +398,7 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, std::vector<std::unique_p
contentError("<building> unknown game_subtype value",elemRoot);
return false;
}
if(subtype == workshop_type::Custom) {
if(subtype == df::workshop_type::Custom) {
needs_custom = true;
}
break;
Expand All @@ -418,11 +416,10 @@ bool addSingleBuildingConfig( TiXmlElement* elemRoot, std::vector<std::unique_p
}
else if (strGameCustom && strGameCustom[0])
{
for (size_t i = 0; i < df::global::world->raws.buildings.all.size(); i++)
{
if (strcmp(strGameCustom, df::global::world->raws.buildings.all[i]->code.c_str()) == 0)
custom = i;
}
auto& bld = df::global::world->raws.buildings.all;
auto it = std::find_if(bld.begin(), bld.end(), [&](auto b) { return b->code == strGameCustom; });
if (it != bld.end())
custom = it - bld.begin();
if (custom == -1)
{
contentWarning("<building> game_custom attribute is invalid", elemRoot);
Expand Down
Loading

0 comments on commit 47ad84f

Please sign in to comment.