-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaces texture filename generation etc. with library lookup.
- Loading branch information
Showing
13 changed files
with
217 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <algorithm> | ||
#include <cstring> | ||
|
||
#include "CharacterRaceDefinition.h" | ||
|
||
#include "components/debug/Debug.h" | ||
|
||
CharacterRaceDefinition::CharacterRaceDefinition() | ||
{ | ||
this->provinceID = -1; | ||
std::fill(std::begin(this->singularName), std::end(this->singularName), '\0'); | ||
std::fill(std::begin(this->pluralName), std::end(this->pluralName), '\0'); | ||
} | ||
|
||
void CharacterRaceDefinition::init(int provinceID, const char *singularName, const char *pluralName, | ||
const TextureAsset &maleCharSheetBodyTextureAsset, const std::string &maleCharSheetHeadsFilename, const std::string &maleGameUiHeadsFilename, | ||
const TextureAsset &femaleCharSheetBodyTextureAsset, const std::string &femaleCharSheetHeadsFilename, const std::string &femaleGameUiHeadsFilename) | ||
{ | ||
DebugAssert(provinceID >= 0); | ||
this->provinceID = provinceID; | ||
std::snprintf(std::begin(this->singularName), std::size(this->singularName), "%s", singularName); | ||
std::snprintf(std::begin(this->pluralName), std::size(this->pluralName), "%s", pluralName); | ||
this->maleCharSheetBodyTextureAsset = maleCharSheetBodyTextureAsset; | ||
this->maleCharSheetHeadsFilename = maleCharSheetHeadsFilename; | ||
this->maleGameUiHeadsFilename = maleGameUiHeadsFilename; | ||
this->femaleCharSheetBodyTextureAsset = femaleCharSheetBodyTextureAsset; | ||
this->femaleCharSheetHeadsFilename = femaleCharSheetHeadsFilename; | ||
this->femaleGameUiHeadsFilename = femaleGameUiHeadsFilename; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef CHARACTER_RACE_DEFINITION_H | ||
#define CHARACTER_RACE_DEFINITION_H | ||
|
||
#include <string> | ||
|
||
#include "../Assets/TextureAsset.h" | ||
|
||
struct CharacterRaceDefinition | ||
{ | ||
int provinceID; | ||
char singularName[32]; | ||
char pluralName[32]; | ||
TextureAsset maleCharSheetBodyTextureAsset; | ||
std::string maleCharSheetHeadsFilename; | ||
std::string maleGameUiHeadsFilename; | ||
TextureAsset femaleCharSheetBodyTextureAsset; | ||
std::string femaleCharSheetHeadsFilename; | ||
std::string femaleGameUiHeadsFilename; | ||
|
||
CharacterRaceDefinition(); | ||
|
||
void init(int provinceID, const char *singularName, const char *pluralName, | ||
const TextureAsset &maleCharSheetBodyTextureAsset, const std::string &maleCharSheetHeadsFilename, const std::string &maleGameUiHeadsFilename, | ||
const TextureAsset &femaleCharSheetBodyTextureAsset, const std::string &femaleCharSheetHeadsFilename, const std::string &femaleGameUiHeadsFilename); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "../Assets/ArenaPortraitUtils.h" | ||
#include "../Assets/CityDataFile.h" | ||
#include "../Assets/ExeData.h" | ||
#include "CharacterRaceLibrary.h" | ||
|
||
#include "components/debug/Debug.h" | ||
|
||
void CharacterRaceLibrary::init(const ExeData &exeData) | ||
{ | ||
constexpr int playableRaceCount = CityDataFile::PROVINCE_COUNT - 1; | ||
for (int i = 0; i < playableRaceCount; i++) | ||
{ | ||
const int raceID = i; | ||
DebugAssertIndex(exeData.races.singularNames, raceID); | ||
DebugAssertIndex(exeData.races.pluralNames, raceID); | ||
const std::string &singularName = exeData.races.singularNames[raceID]; | ||
const std::string &pluralName = exeData.races.pluralNames[raceID]; | ||
const TextureAsset maleCharSheetBodyTextureAsset(ArenaPortraitUtils::getBody(true, raceID)); | ||
const std::string maleCharSheetHeadsFilename = ArenaPortraitUtils::getHeads(true, raceID, false); | ||
const std::string maleGameUiHeadsFilename = ArenaPortraitUtils::getHeads(true, raceID, true); | ||
const TextureAsset femaleCharSheetBodyTextureAsset(ArenaPortraitUtils::getBody(false, raceID)); | ||
const std::string femaleCharSheetHeadsFilename = ArenaPortraitUtils::getHeads(false, raceID, false); | ||
const std::string femaleGameUiHeadsFilename = ArenaPortraitUtils::getHeads(false, raceID, true); | ||
|
||
CharacterRaceDefinition raceDef; | ||
raceDef.init(raceID, singularName.c_str(), pluralName.c_str(), maleCharSheetBodyTextureAsset, maleCharSheetHeadsFilename, maleGameUiHeadsFilename, | ||
femaleCharSheetBodyTextureAsset, femaleCharSheetHeadsFilename, femaleGameUiHeadsFilename); | ||
this->defs.emplace_back(std::move(raceDef)); | ||
} | ||
} | ||
|
||
int CharacterRaceLibrary::getDefinitionCount() const | ||
{ | ||
return static_cast<int>(this->defs.size()); | ||
} | ||
|
||
const CharacterRaceDefinition &CharacterRaceLibrary::getDefinition(int index) const | ||
{ | ||
DebugAssertIndex(this->defs, index); | ||
return this->defs[index]; | ||
} | ||
|
||
bool CharacterRaceLibrary::findDefinitionIndexIf(const Predicate &predicate, int *outIndex) const | ||
{ | ||
for (int i = 0; i < static_cast<int>(this->defs.size()); i++) | ||
{ | ||
const CharacterRaceDefinition &def = this->defs[i]; | ||
if (predicate(def)) | ||
{ | ||
*outIndex = i; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool CharacterRaceLibrary::tryGetDefinitionIndex(const CharacterRaceDefinition &def, int *outIndex) const | ||
{ | ||
for (int i = 0; i < static_cast<int>(this->defs.size()); i++) | ||
{ | ||
const CharacterRaceDefinition &charClassDef = this->defs[i]; | ||
if (charClassDef.provinceID == def.provinceID) | ||
{ | ||
*outIndex = i; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef CHARACTER_RACE_LIBRARY_H | ||
#define CHARACTER_RACE_LIBRARY_H | ||
|
||
#include <functional> | ||
#include <vector> | ||
|
||
#include "CharacterRaceDefinition.h" | ||
|
||
#include "components/utilities/Singleton.h" | ||
|
||
class ExeData; | ||
|
||
class CharacterRaceLibrary : public Singleton<CharacterRaceLibrary> | ||
{ | ||
public: | ||
using Predicate = std::function<bool(const CharacterRaceDefinition&)>; | ||
private: | ||
std::vector<CharacterRaceDefinition> defs; | ||
public: | ||
void init(const ExeData &exeData); | ||
|
||
int getDefinitionCount() const; | ||
const CharacterRaceDefinition &getDefinition(int index) const; | ||
bool findDefinitionIndexIf(const Predicate &predicate, int *outIndex) const; | ||
bool tryGetDefinitionIndex(const CharacterRaceDefinition &def, int *outIndex) const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.