bool CLocalizationDatabase::Load(const char *pFilename, IStorage *pStorage, IConsole *pConsole) { // empty string means unload if(pFilename[0] == 0) { m_Strings.clear(); m_CurrentVersion = 0; return true; } IOHANDLE IoHandle = pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL); if(!IoHandle) return false; char aBuf[256]; str_format(aBuf, sizeof(aBuf), "loaded '%s'", pFilename); pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf); m_Strings.clear(); CLineReader LineReader; LineReader.Init(IoHandle); char *pLine; while((pLine = LineReader.Get())) { if(!str_length(pLine)) continue; if(pLine[0] == '#') // skip comments continue; char *pReplacement = LineReader.Get(); if(!pReplacement) { pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "unexpected end of file"); break; } if(pReplacement[0] != '=' || pReplacement[1] != '=' || pReplacement[2] != ' ') { str_format(aBuf, sizeof(aBuf), "malform replacement line for '%s'", pLine); pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf); continue; } pReplacement += 3; AddString(pLine, pReplacement); } m_CurrentVersion = ++m_VersionCounter; return true; }
int CTeeFiles::TeeFileScan(const char *pName, int IsDir, int DirType, void *pUser) { CTeeFiles *pSelf = (CTeeFiles*)pUser; int l = str_length(pName); if(l < 4 || IsDir || str_comp(pName+l-4, ".tee") != 0) return 0; char aBuf[512]; char aFileName[41]; char aFilePath[512]; char aTeeEntry[NUM_TEE_ENTRIES][32]; str_format(aFilePath, sizeof(aFilePath), "xclient/teefiles/%s", pName); str_format(aFileName, sizeof(aFileName), pName); IOHANDLE File = pSelf->Storage()->OpenFile(aFilePath, IOFLAG_READ, IStorage::TYPE_SAVE); if(File) { char *pLine; CLineReader lr; lr.Init(File); for(int i = 0; i < NUM_TEE_ENTRIES; i++) { if(!(pLine = lr.Get())) { str_format(aBuf, sizeof(aBuf), "failed to read '%s' at line %d", aFileName, i); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); io_close(File); mem_zero(aTeeEntry[i], sizeof(aTeeEntry[i])); break; } str_format(aTeeEntry[i], sizeof(aTeeEntry[i]), pLine); } io_close(File); } else { str_format(aBuf, sizeof(aBuf), "failed to open '%s'", aFileName); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); return 1; } CTee Tee; str_format(Tee.m_aFilename, sizeof(Tee.m_aFilename), aFileName); str_format(Tee.m_aName, sizeof(Tee.m_aName), aTeeEntry[TEE_NAME]); str_format(Tee.m_aClan, sizeof(Tee.m_aClan), aTeeEntry[TEE_CLAN]); str_format(Tee.m_aSkin, sizeof(Tee.m_aSkin), aTeeEntry[TEE_SKIN]); Tee.m_UseCustomColor = str_toint(aTeeEntry[TEE_USECUSTOMCOLOR]); Tee.m_ColorBody = str_toint(aTeeEntry[TEE_COLORBODY]); Tee.m_ColorFeet = str_toint(aTeeEntry[TEE_COLORFEET]); Tee.m_Country = str_toint(aTeeEntry[TEE_COUNTRY]); pSelf->m_aTees.add(Tee); return 0; }
virtual int Load() { if(!m_pStorage) return -1; // try to open file IOHANDLE File = m_pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE); if(!File) return -1; CLineReader LineReader; LineReader.Init(File); while(1) { CMasterInfo Info = {{0}}; const char *pLine = LineReader.Get(); if(!pLine) break; // parse line char aAddrStr[NETADDR_MAXSTRSIZE]; if(sscanf(pLine, "%127s %47s", Info.m_aHostname, aAddrStr) == 2 && net_addr_from_str(&Info.m_Addr, aAddrStr) == 0) { Info.m_Addr.port = 8300; bool Added = false; for(int i = 0; i < MAX_MASTERSERVERS; ++i) if(str_comp(m_aMasterServers[i].m_aHostname, Info.m_aHostname) == 0) { m_aMasterServers[i] = Info; Added = true; break; } if(!Added) { for(int i = 0; i < MAX_MASTERSERVERS; ++i) if(m_aMasterServers[i].m_Addr.type == NETTYPE_INVALID) { m_aMasterServers[i] = Info; Added = true; break; } } if(!Added) break; } } io_close(File); return 0; }
void CConsole::ExecuteFile(const char *pFilename) { // make sure that this isn't being executed already for(CExecFile *pCur = m_pFirstExec; pCur; pCur = pCur->m_pPrev) if(str_comp(pFilename, pCur->m_pFilename) == 0) return; if(!m_pStorage) m_pStorage = Kernel()->RequestInterface<IStorage>(); if(!m_pStorage) return; // push this one to the stack CExecFile ThisFile; CExecFile *pPrev = m_pFirstExec; ThisFile.m_pFilename = pFilename; ThisFile.m_pPrev = m_pFirstExec; m_pFirstExec = &ThisFile; // exec the file IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL); char aBuf[256]; if(File) { char *pLine; CLineReader lr; str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename); Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); lr.Init(File); while((pLine = lr.Get())) ExecuteLine(pLine); io_close(File); } else { str_format(aBuf, sizeof(aBuf), "failed to open '%s'", pFilename); Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); } m_pFirstExec = pPrev; }
void LoadPaths(const char *pArgv0) { // check current directory IOHANDLE File = io_open("storage.cfg", IOFLAG_READ); if(!File) { // check usable path in argv[0] unsigned int Pos = ~0U; for(unsigned i = 0; pArgv0[i]; i++) if(pArgv0[i] == '/' || pArgv0[i] == '\\') Pos = i; if(Pos < MAX_PATH_LENGTH) { char aBuffer[MAX_PATH_LENGTH]; str_copy(aBuffer, pArgv0, Pos+1); str_append(aBuffer, "/storage.cfg", sizeof(aBuffer)); File = io_open(aBuffer, IOFLAG_READ); } if(Pos >= MAX_PATH_LENGTH || !File) { dbg_msg("storage", "couldn't open storage.cfg"); return; } } char *pLine; CLineReader LineReader; LineReader.Init(File); while((pLine = LineReader.Get())) { const char *pLineWithoutPrefix = str_startswith(pLine, "add_path "); if(pLineWithoutPrefix) { AddPath(pLineWithoutPrefix); } } io_close(File); if(!m_NumPaths) dbg_msg("storage", "no paths found in storage.cfg"); }
virtual int Load() { CLineReader LineReader; IOHANDLE File; int Count = 0; if(!m_pStorage) return -1; // try to open file File = m_pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE); if(!File) return -1; LineReader.Init(File); while(1) { CMasterInfo Info = {{0}}; const char *pLine = LineReader.Get(); if(!pLine) break; // parse line char aAddrStr[NETADDR_MAXSTRSIZE]; if(sscanf(pLine, "%s %s", Info.m_aHostname, aAddrStr) == 2 && net_addr_from_str(&Info.m_Addr, aAddrStr) == 0) { Info.m_Addr.port = 8300; if(Count != MAX_MASTERSERVERS) { m_aMasterServers[Count] = Info; Count++; } //else // dbg_msg("engine/mastersrv", "warning: skipped master server '%s' due to limit of %d", pLine, MAX_MASTERSERVERS); } //else // dbg_msg("engine/mastersrv", "warning: couldn't parse master server '%s'", pLine); } io_close(File); return 0; }
void CCountryFlags::LoadCountryflagsIndexfile() { IOHANDLE File = Storage()->OpenFile("countryflags/index.txt", IOFLAG_READ, IStorage::TYPE_ALL); if(!File) { Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", "couldn't open index file"); return; } char aOrigin[128]; CLineReader LineReader; LineReader.Init(File); char *pLine; while((pLine = LineReader.Get())) { if(!str_length(pLine) || pLine[0] == '#') // skip empty lines and comments continue; str_copy(aOrigin, pLine, sizeof(aOrigin)); char *pReplacement = LineReader.Get(); if(!pReplacement) { Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", "unexpected end of index file"); break; } if(pReplacement[0] != '=' || pReplacement[1] != '=' || pReplacement[2] != ' ') { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "malform replacement for index '%s'", aOrigin); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf); continue; } int CountryCode = str_toint(pReplacement+3); if(CountryCode < CODE_LB || CountryCode > CODE_UB) { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "country code '%i' not within valid code range [%i..%i]", CountryCode, CODE_LB, CODE_UB); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf); continue; } // load the graphic file char aBuf[128]; str_format(aBuf, sizeof(aBuf), "countryflags/%s.png", aOrigin); CImageInfo Info; if(!Graphics()->LoadPNG(&Info, aBuf, IStorage::TYPE_ALL)) { char aMsg[128]; str_format(aMsg, sizeof(aMsg), "failed to load '%s'", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aMsg); continue; } // add entry CCountryFlag CountryFlag; CountryFlag.m_CountryCode = CountryCode; str_copy(CountryFlag.m_aCountryCodeString, aOrigin, sizeof(CountryFlag.m_aCountryCodeString)); CountryFlag.m_Texture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0); mem_free(Info.m_pData); str_format(aBuf, sizeof(aBuf), "loaded country flag '%s'", aOrigin); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "countryflags", aBuf); m_aCountryFlags.add(CountryFlag); } io_close(File); mem_zero(m_CodeIndexLUT, sizeof(m_CodeIndexLUT)); for(int i = 0; i < m_aCountryFlags.size(); ++i) m_CodeIndexLUT[max(0, (m_aCountryFlags[i].m_CountryCode-CODE_LB)%CODE_RANGE)] = i+1; }
void Process(IStorageTW *pStorage, const char *pMapName, const char *pConfigName) { IOHANDLE File = pStorage->OpenFile(pConfigName, IOFLAG_READ, IStorageTW::TYPE_ALL); array<char *> aLines; char *pSettings = NULL; if(!File) { dbg_msg("config_store", "config '%s' not found", pConfigName); return; } CLineReader LineReader; LineReader.Init(File); char *pLine; int TotalLength = 0; while((pLine = LineReader.Get())) { int Length = str_length(pLine) + 1; char *pCopy = (char *)mem_alloc(Length, 1); mem_copy(pCopy, pLine, Length); aLines.add(pCopy); TotalLength += Length; } pSettings = (char *)mem_alloc(TotalLength, 1); int Offset = 0; for(int i = 0; i < aLines.size(); i++) { int Length = str_length(aLines[i]) + 1; mem_copy(pSettings + Offset, aLines[i], Length); Offset += Length; mem_free(aLines[i]); } CDataFileReader Reader; Reader.Open(pStorage, pMapName, IStorageTW::TYPE_ALL); CDataFileWriter Writer; Writer.Init(); int SettingsIndex = Reader.NumData(); bool FoundInfo = false; for(int i = 0; i < Reader.NumItems(); i++) { int TypeID; int ItemID; int *pData = (int *)Reader.GetItem(i, &TypeID, &ItemID); // GetItemSize returns item size including header, remove that. int Size = Reader.GetItemSize(i) - sizeof(int) * 2; CMapItemInfoSettings MapInfo; if(TypeID == MAPITEMTYPE_INFO && ItemID == 0) { FoundInfo = true; CMapItemInfoSettings *pInfo = (CMapItemInfoSettings *)pData; if(Size >= (int)sizeof(CMapItemInfoSettings)) { MapInfo = *pInfo; pData = (int *)&MapInfo; Size = sizeof(MapInfo); if(pInfo->m_Settings > -1) { SettingsIndex = pInfo->m_Settings; char *pMapSettings = (char *)Reader.GetData(SettingsIndex); int DataSize = Reader.GetUncompressedDataSize(SettingsIndex); if(DataSize == TotalLength && mem_comp(pSettings, pMapSettings, DataSize) == 0) { dbg_msg("config_store", "configs coincide, not updating map"); return; } Reader.UnloadData(pInfo->m_Settings); } else { MapInfo = *pInfo; MapInfo.m_Settings = SettingsIndex; pData = (int *)&MapInfo; Size = sizeof(MapInfo); } } else { *(CMapItemInfo *)&MapInfo = *(CMapItemInfo *)pInfo; MapInfo.m_Settings = SettingsIndex; pData = (int *)&MapInfo; Size = sizeof(MapInfo); } } Writer.AddItem(TypeID, ItemID, Size, pData); } if(!FoundInfo) { CMapItemInfoSettings Info; Info.m_Version = 1; Info.m_Author = -1; Info.m_MapVersion = -1; Info.m_Credits = -1; Info.m_License = -1; Info.m_Settings = SettingsIndex; Writer.AddItem(MAPITEMTYPE_INFO, 0, sizeof(Info), &Info); } for(int i = 0; i < Reader.NumData() || i == SettingsIndex; i++) { if(i == SettingsIndex) { Writer.AddData(TotalLength, pSettings); continue; } unsigned char *pData = (unsigned char *)Reader.GetData(i); int Size = Reader.GetUncompressedDataSize(i); Writer.AddData(Size, pData); Reader.UnloadData(i); } Reader.Close(); if(!Writer.OpenFile(pStorage, pMapName)) { dbg_msg("config_store", "couldn't open map file '%s' for writing", pMapName); return; } Writer.Finish(); dbg_msg("config_store", "imported settings"); }
void CAutoMapper::Load(const char* pTileName) { char aPath[256]; str_format(aPath, sizeof(aPath), "editor/%s.rules", pTileName); IOHANDLE RulesFile = m_pEditor->Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL); if(!RulesFile) return; CLineReader LineReader; LineReader.Init(RulesFile); CConfiguration *pCurrentConf = 0; CRun *pCurrentRun = 0; CIndexRule *pCurrentIndex = 0; char aBuf[256]; // read each line while(char *pLine = LineReader.Get()) { // skip blank/empty lines as well as comments if(str_length(pLine) > 0 && pLine[0] != '#' && pLine[0] != '\n' && pLine[0] != '\r' && pLine[0] != '\t' && pLine[0] != '\v' && pLine[0] != ' ') { if(pLine[0]== '[') { // new configuration, get the name pLine++; CConfiguration NewConf; NewConf.m_StartX = 0; NewConf.m_StartY = 0; NewConf.m_EndX = 0; NewConf.m_EndY = 0; int ConfigurationID = m_lConfigs.add(NewConf); pCurrentConf = &m_lConfigs[ConfigurationID]; str_copy(pCurrentConf->m_aName, pLine, str_length(pLine)); // add start run CRun NewRun; NewRun.m_AutomapCopy = true; int RunID = pCurrentConf->m_aRuns.add(NewRun); pCurrentRun = &pCurrentConf->m_aRuns[RunID]; } else if(str_startswith(pLine, "NewRun")) { // add new run CRun NewRun; NewRun.m_AutomapCopy = true; int RunID = pCurrentConf->m_aRuns.add(NewRun); pCurrentRun = &pCurrentConf->m_aRuns[RunID]; } else if(str_startswith(pLine, "Index") && pCurrentRun) { // new index int ID = 0; char aOrientation1[128] = ""; char aOrientation2[128] = ""; char aOrientation3[128] = ""; sscanf(pLine, "Index %d %127s %127s %127s", &ID, aOrientation1, aOrientation2, aOrientation3); CIndexRule NewIndexRule; NewIndexRule.m_ID = ID; NewIndexRule.m_Flag = 0; NewIndexRule.m_RandomProbability = 1.0; NewIndexRule.m_DefaultRule = true; NewIndexRule.m_SkipEmpty = false; NewIndexRule.m_SkipFull = false; if(str_length(aOrientation1) > 0) { if(!str_comp(aOrientation1, "XFLIP")) NewIndexRule.m_Flag |= TILEFLAG_VFLIP; else if(!str_comp(aOrientation1, "YFLIP")) NewIndexRule.m_Flag |= TILEFLAG_HFLIP; else if(!str_comp(aOrientation1, "ROTATE")) NewIndexRule.m_Flag |= TILEFLAG_ROTATE; } if(str_length(aOrientation2) > 0) { if(!str_comp(aOrientation2, "XFLIP")) NewIndexRule.m_Flag |= TILEFLAG_VFLIP; else if(!str_comp(aOrientation2, "YFLIP")) NewIndexRule.m_Flag |= TILEFLAG_HFLIP; else if(!str_comp(aOrientation2, "ROTATE")) NewIndexRule.m_Flag |= TILEFLAG_ROTATE; } if(str_length(aOrientation3) > 0) { if(!str_comp(aOrientation3, "XFLIP")) NewIndexRule.m_Flag |= TILEFLAG_VFLIP; else if(!str_comp(aOrientation3, "YFLIP")) NewIndexRule.m_Flag |= TILEFLAG_HFLIP; else if(!str_comp(aOrientation3, "ROTATE")) NewIndexRule.m_Flag |= TILEFLAG_ROTATE; } // add the index rule object and make it current int IndexRuleID = pCurrentRun->m_aIndexRules.add(NewIndexRule); pCurrentIndex = &pCurrentRun->m_aIndexRules[IndexRuleID]; } else if(str_startswith(pLine, "Pos") && pCurrentIndex) { int x = 0, y = 0; char aValue[128]; int Value = CPosRule::NORULE; array<CIndexInfo> NewIndexList; sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue); if(!str_comp(aValue, "EMPTY")) { Value = CPosRule::INDEX; CIndexInfo NewIndexInfo = {0, 0, false}; NewIndexList.add(NewIndexInfo); } else if(!str_comp(aValue, "FULL")) { Value = CPosRule::NOTINDEX; CIndexInfo NewIndexInfo1 = {0, 0, false}; //CIndexInfo NewIndexInfo2 = {-1, 0}; NewIndexList.add(NewIndexInfo1); //NewIndexList.add(NewIndexInfo2); } else if(!str_comp(aValue, "INDEX") || !str_comp(aValue, "NOTINDEX")) { if(!str_comp(aValue, "INDEX")) Value = CPosRule::INDEX; else Value = CPosRule::NOTINDEX; int pWord = 4; while(true) { int ID = 0; char aOrientation1[128] = ""; char aOrientation2[128] = ""; char aOrientation3[128] = ""; char aOrientation4[128] = ""; sscanf(str_trim_words(pLine, pWord), "%d %127s %127s %127s %127s", &ID, aOrientation1, aOrientation2, aOrientation3, aOrientation4); CIndexInfo NewIndexInfo; NewIndexInfo.m_ID = ID; NewIndexInfo.m_Flag = 0; NewIndexInfo.m_TestFlag = false; if(!str_comp(aOrientation1, "OR")) { NewIndexList.add(NewIndexInfo); pWord += 2; continue; } else if(str_length(aOrientation1) > 0) { NewIndexInfo.m_TestFlag = true; if(!str_comp(aOrientation1, "XFLIP")) NewIndexInfo.m_Flag = TILEFLAG_VFLIP; else if(!str_comp(aOrientation1, "YFLIP")) NewIndexInfo.m_Flag = TILEFLAG_HFLIP; else if(!str_comp(aOrientation1, "ROTATE")) NewIndexInfo.m_Flag = TILEFLAG_ROTATE; else if(!str_comp(aOrientation1, "NONE")) NewIndexInfo.m_Flag = 0; else NewIndexInfo.m_TestFlag = false; } else { NewIndexList.add(NewIndexInfo); break; } if(!str_comp(aOrientation2, "OR")) { NewIndexList.add(NewIndexInfo); pWord += 3; continue; } else if(str_length(aOrientation2) > 0 && NewIndexInfo.m_Flag != 0) { if(!str_comp(aOrientation2, "XFLIP")) NewIndexInfo.m_Flag |= TILEFLAG_VFLIP; else if(!str_comp(aOrientation2, "YFLIP")) NewIndexInfo.m_Flag |= TILEFLAG_HFLIP; else if(!str_comp(aOrientation2, "ROTATE")) NewIndexInfo.m_Flag |= TILEFLAG_ROTATE; } else { NewIndexList.add(NewIndexInfo); break; } if(!str_comp(aOrientation3, "OR")) { NewIndexList.add(NewIndexInfo); pWord += 4; continue; } else if(str_length(aOrientation3) > 0 && NewIndexInfo.m_Flag != 0) { if(!str_comp(aOrientation3, "XFLIP")) NewIndexInfo.m_Flag |= TILEFLAG_VFLIP; else if(!str_comp(aOrientation3, "YFLIP")) NewIndexInfo.m_Flag |= TILEFLAG_HFLIP; else if(!str_comp(aOrientation3, "ROTATE")) NewIndexInfo.m_Flag |= TILEFLAG_ROTATE; } else { NewIndexList.add(NewIndexInfo); break; } if(!str_comp(aOrientation4, "OR")) { NewIndexList.add(NewIndexInfo); pWord += 5; continue; } else { NewIndexList.add(NewIndexInfo); break; } } } if(Value != CPosRule::NORULE) { CPosRule NewPosRule = {x, y, Value, NewIndexList}; pCurrentIndex->m_aRules.add(NewPosRule); pCurrentConf->m_StartX = min(pCurrentConf->m_StartX, NewPosRule.m_X); pCurrentConf->m_StartY = min(pCurrentConf->m_StartY, NewPosRule.m_Y); pCurrentConf->m_EndX = max(pCurrentConf->m_EndX, NewPosRule.m_X); pCurrentConf->m_EndY = max(pCurrentConf->m_EndY, NewPosRule.m_Y); if(x == 0 && y == 0) { for(int i = 0; i < NewIndexList.size(); ++i) { if(Value == CPosRule::INDEX && NewIndexList[i].m_ID == 0) pCurrentIndex->m_SkipFull = true; else pCurrentIndex->m_SkipEmpty = true; } } } } else if(str_startswith(pLine, "Random") && pCurrentIndex) { float Value; char Specifier = ' '; sscanf(pLine, "Random %f%c", &Value, &Specifier); if(Specifier == '%') { pCurrentIndex->m_RandomProbability = Value / 100.0; } else { pCurrentIndex->m_RandomProbability = 1.0 / Value; } } else if(str_startswith(pLine, "NoDefaultRule") && pCurrentIndex) { pCurrentIndex->m_DefaultRule = false; } else if(!str_comp_num(pLine, "NoLayerCopy", 11) && pCurrentRun) { pCurrentRun->m_AutomapCopy = false; } } } // add default rule for Pos 0 0 if there is none for (int g = 0; g < m_lConfigs.size(); ++g) { for (int h = 0; h < m_lConfigs[g].m_aRuns.size(); ++h) { for(int i = 0; i < m_lConfigs[g].m_aRuns[h].m_aIndexRules.size(); ++i) { CIndexRule *pIndexRule = &m_lConfigs[g].m_aRuns[h].m_aIndexRules[i]; bool Found = false; for(int j = 0; j < pIndexRule->m_aRules.size(); ++j) { CPosRule *pRule = &pIndexRule->m_aRules[j]; if(pRule && pRule->m_X == 0 && pRule->m_Y == 0) { Found = true; break; } } if(!Found && pIndexRule->m_DefaultRule) { array<CIndexInfo> NewIndexList; CIndexInfo NewIndexInfo = {0, 0, false}; NewIndexList.add(NewIndexInfo); CPosRule NewPosRule = {0, 0, CPosRule::NOTINDEX, NewIndexList}; pIndexRule->m_aRules.add(NewPosRule); pIndexRule->m_SkipEmpty = true; pIndexRule->m_SkipFull = false; } if(pIndexRule->m_SkipEmpty && pIndexRule->m_SkipFull) { pIndexRule->m_SkipFull = false; } } } } io_close(RulesFile); str_format(aBuf, sizeof(aBuf),"loaded %s", aPath); m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", aBuf); m_FileLoaded = true; }
void CAutoMapper::Load(const char* pTileName) { char aPath[256]; str_format(aPath, sizeof(aPath), "editor/%s.rules", pTileName); IOHANDLE RulesFile = m_pEditor->Storage()->OpenFile(aPath, IOFLAG_READ, IStorageTW::TYPE_ALL); if(!RulesFile) return; CLineReader LineReader; LineReader.Init(RulesFile); CConfiguration *pCurrentConf = 0; CIndexRule *pCurrentIndex = 0; char aBuf[256]; // read each line while(char *pLine = LineReader.Get()) { // skip blank/empty lines as well as comments if(str_length(pLine) > 0 && pLine[0] != '#' && pLine[0] != '\n' && pLine[0] != '\r' && pLine[0] != '\t' && pLine[0] != '\v' && pLine[0] != ' ') { if(pLine[0]== '[') { // new configuration, get the name pLine++; CConfiguration NewConf; int ID = m_lConfigs.add(NewConf); pCurrentConf = &m_lConfigs[ID]; str_copy(pCurrentConf->m_aName, pLine, str_length(pLine)); } else { if(!str_comp_num(pLine, "Index", 5)) { // new index int ID = 0; char aFlip[128] = ""; sscanf(pLine, "Index %d %127s", &ID, aFlip); CIndexRule NewIndexRule; NewIndexRule.m_ID = ID; NewIndexRule.m_Flag = 0; NewIndexRule.m_RandomValue = 0; NewIndexRule.m_BaseTile = false; if(str_length(aFlip) > 0) { if(!str_comp(aFlip, "XFLIP")) NewIndexRule.m_Flag = TILEFLAG_VFLIP; else if(!str_comp(aFlip, "YFLIP")) NewIndexRule.m_Flag = TILEFLAG_HFLIP; } // add the index rule object and make it current int ArrayID = pCurrentConf->m_aIndexRules.add(NewIndexRule); pCurrentIndex = &pCurrentConf->m_aIndexRules[ArrayID]; } else if(!str_comp_num(pLine, "BaseTile", 8) && pCurrentIndex) { pCurrentIndex->m_BaseTile = true; } else if(!str_comp_num(pLine, "Pos", 3) && pCurrentIndex) { int x = 0, y = 0; char aValue[128]; int Value = CPosRule::EMPTY; bool IndexValue = false; sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue); if(!str_comp(aValue, "FULL")) Value = CPosRule::FULL; else if(!str_comp_num(aValue, "INDEX", 5)) { sscanf(pLine, "Pos %*d %*d INDEX %d", &Value); IndexValue = true; } CPosRule NewPosRule = {x, y, Value, IndexValue}; pCurrentIndex->m_aRules.add(NewPosRule); } else if(!str_comp_num(pLine, "Random", 6) && pCurrentIndex) { sscanf(pLine, "Random %d", &pCurrentIndex->m_RandomValue); } } } } io_close(RulesFile); str_format(aBuf, sizeof(aBuf),"loaded %s", aPath); m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", aBuf); m_FileLoaded = true; }