extracting strings from Lua tables friendlier to MSVC

This commit is contained in:
devZoGok
2024-06-15 11:48:29 +03:00
parent a8643010d4
commit 362532ddf0
5 changed files with 56 additions and 24 deletions
+6 -1
View File
@@ -69,7 +69,12 @@ namespace battleship{
string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Cursors/";
sol::state_view SOL_LUA_VIEW = generateView();
string p1[]{basePath + (string)SOL_LUA_VIEW["pointerTex"]}, p2[]{basePath + (string)SOL_LUA_VIEW["attackTex"]}, p3[]{basePath + (string)SOL_LUA_VIEW["garrisonTex"]};
string pt = SOL_LUA_VIEW["pointerTex"],
at = SOL_LUA_VIEW["attackTex"],
gt = SOL_LUA_VIEW["garrisonTex"],
p1[]{basePath + pt},
p2[]{basePath + at},
p3[]{basePath + gt};
pointerTex = new Texture(p1, 1, false);
attackTex = new Texture(p2, 1, false);
garrisonTex = new Texture(p3, 1, false);
+33 -15
View File
@@ -66,17 +66,25 @@ namespace battleship{
Vector2 size = Vector2(sizeTable["x"], sizeTable["y"]);
//TODO factor out repetetive optional lua key checks
string nk = "name";
string name = "", nk = "name";
sol::optional<string> nameOpt = guiTable[nk];
string name = (nameOpt != sol::nullopt ? (string)guiTable[nk] : "");
if(nameOpt != sol::nullopt) name = guiTable[nk];
ButtonType type = (ButtonType)guiTable["buttonType"];
string ipk = "imagePath";
string imagePath = "", ipk = "imagePath";
sol::optional<string> pathOpt = guiTable[ipk];
string imagePath = (pathOpt != sol::nullopt ? texBasePath + (string)guiTable[ipk] : "");
bool texturingEnabled = (imagePath != "");
bool texturingEnabled = false;
if(pathOpt != sol::nullopt){
imagePath = texBasePath;
imagePath += guiTable[ipk];
bool texturingEnabled = true;
}
Button *button = nullptr;
string guiScreen = "";
switch(type){
case SINGLE_PLAYER:
@@ -232,16 +240,19 @@ namespace battleship{
button = new TradeButton(pos, size, name, (int)guiTable["trigger"], imagePath, (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::SELL_RESEARCH);
break;
case ACTIVE_GAME_STATE:
button = new ActiveStateButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
guiScreen = guiTable["guiScreen"];
button = new ActiveStateButton(pos, size, guiScreen, name, (int)guiTable["trigger"], imagePath);
break;
case PLAYER_TRADE:
button = new PlayerTradeButton(pos, size, (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
guiScreen = guiTable["guiScreen"];
button = new PlayerTradeButton(pos, size, guiScreen, name, (int)guiTable["trigger"], imagePath);
break;
case TRADING_SCREEN:{
int lid = guiTable["dependencies"][1]["id"];
Listbox *listbox = (Listbox*)guiElements[lid].second;
guiScreen = guiTable["guiScreen"];
button = new TradingScreenButton(pos, size, listbox, (int)SOL_LUA_STATE["playerId"], (string)guiTable["guiScreen"], name, (int)guiTable["trigger"], imagePath);
button = new TradingScreenButton(pos, size, listbox, (int)SOL_LUA_STATE["playerId"], guiScreen, name, (int)guiTable["trigger"], imagePath);
break;
}
case TRADE_OFFER:
@@ -451,19 +462,24 @@ namespace battleship{
Material *mat = new Material(root->getLibPath() + "gui");
mat->setTransparent(true);
string ipk = "imagePath";
bool texturingEnabled = false;
string imagePath = "", ipk = "imagePath";
sol::optional<string> pathOpt = guiTable[ipk];
string imagePath = (pathOpt != sol::nullopt ? (string)guiTable[ipk] : "");
bool texturingEnabled = (imagePath != "");
string nk = "name";
if(pathOpt != sol::nullopt){
imagePath = guiTable[ipk];
texturingEnabled = true;
}
string name = "", nk = "name";
sol::optional<string> nameOpt = guiTable[nk];
string name = (nameOpt != sol::nullopt ? (string)guiTable[nk] : "");
if(nameOpt != sol::nullopt) name = guiTable[nk];
mat->addBoolUniform("texturingEnabled", texturingEnabled);
if(texturingEnabled){
string p[]{texBasePath + (string)guiTable[ipk]};
string p[]{texBasePath + imagePath};
Texture *tex = new Texture(p, 1, false);
mat->addTexUniform("diffuseMap", tex, false);
}
@@ -500,7 +516,9 @@ namespace battleship{
sol::table colorTable = guiTable["color"];
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["w"]));
Text *text = new Text(fontBasePath + (string)guiTable["font"], (wstring)guiTable["text"], guiTable["fontFirstChar"], guiTable["fontLastChar"]);
string font = guiTable["font"];
wstring entry = guiTable["text"];
Text *text = new Text(fontBasePath + font, entry, guiTable["fontFirstChar"], guiTable["fontLastChar"]);
text->setMaterial(mat);
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
+2 -1
View File
@@ -135,7 +135,8 @@ namespace battleship{
generateView().script_file(gm->getPath() + f);
guiManager->readLuaScreenScript("inGame.lua", activeState->getButtons());
AssetManager::getSingleton()->load(gm->getPath() + (string)generateView()["modelPrefix"], true);
string mp = generateView()["modelPrefix"];
AssetManager::getSingleton()->load(gm->getPath() + mp, true);
vector<GameObject*> gameObjs;
+12 -6
View File
@@ -87,16 +87,20 @@ namespace battleship{
}
void Map::loadTerrainObject(int id){
string texPath = "";
string texPath = "", albedoPath = "";
Quad *quad = nullptr;
Node *node = nullptr;
sol::state_view SOL_LUA_STATE = generateView();
if(id == -1){
string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/";
texPath = basePath + (string)SOL_LUA_STATE[mapTable]["terrain"]["albedo"];
string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/";
albedoPath = SOL_LUA_STATE[mapTable]["terrain"]["albedo"];
texPath = basePath + albedoPath;
string modelPath = SOL_LUA_STATE[mapTable]["terrain"]["model"];
string terrainFile = basePath + modelPath;
string terrainFile = basePath + (string)SOL_LUA_STATE[mapTable]["terrain"]["model"];
AssetManager::getSingleton()->load(terrainFile);
node = (Model*)((new Model(terrainFile))->getChild(0));
@@ -106,7 +110,8 @@ namespace battleship{
}
else{
sol::table waterBodyTable = SOL_LUA_STATE[mapTable]["waterbodies"][id + 1], posTable = waterBodyTable["pos"];
texPath = GameManager::getSingleton()->getPath() + "Textures/Water/" + (string)waterBodyTable["albedo"];
albedoPath = waterBodyTable["albedo"];
texPath = GameManager::getSingleton()->getPath() + "Textures/Water/" + albedoPath;
quad = new Quad(Vector3(waterBodyTable["size"]["x"], waterBodyTable["size"]["y"], 1), true);
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
@@ -150,7 +155,8 @@ namespace battleship{
assetManager->load(path + DEFAULT_TEXTURE);
sol::state_view SOL_LUA_VIEW = generateView();
assetManager->load(path + (string)SOL_LUA_VIEW["modelPrefix"], true);
string modelPrefix = SOL_LUA_VIEW["modelPrefix"];
assetManager->load(path + modelPrefix, true);
assetManager->load(path + "Textures/", true);
string playerInd = "players";
+3 -1
View File
@@ -142,9 +142,11 @@ namespace battleship{
unitClass = (UnitClass)unitTable["unitClass"];
type = (UnitType)unitTable["unitType"];
guiScreen = "";
string gsk = "guiScreen";
sol::optional<string> nameOpt = unitTable[gsk];
guiScreen = (nameOpt != sol::nullopt ? (string)unitTable[gsk] : "");
if(nameOpt != sol::nullopt) guiScreen = unitTable[gsk];
string tblName = "garrisonCapacity";
sol::optional<sol::table> gc = unitTable[tblName];