Mise à jour de 'DoConfig.py'

This commit is contained in:
2022-07-27 01:39:22 +00:00
parent 7c6343e087
commit 80445e9b72

View File

@@ -55,25 +55,30 @@ class GameOption(metaclass=ABCMeta):
TValueType:OptionType = OptionType.OT_INVALID
szDefaultValue:str = ""
szHelp:str = ""
szFormatedValue:str = ""
@abstractmethod
def __init__(self,GameRootDir:str,ConfigFileRelPath:str=None):
self.GameRootDir = GameRootDir
self.ConfigFileRelPath = ConfigFileRelPath
def set(self,value:str):
def format(self,value):
if self.TValueType == OptionType.OT_STRING:
value = str(value)
self.szFormatedValue = str(value)
elif self.TValueType == OptionType.OT_INTEGER:
value = int(value)
self.szFormatedValue = str(int(value))
elif self.TValueType == OptionType.OT_BOOLEAN:
value = bool(value)
try:
intval = int(value)
self.szFormatedValue = str(bool(intval))
except:
self.szFormatedValue = str(bool(1)) if value.lower() == "true" else str(bool(0))
elif self.TValueType == OptionType.OT_FLOAT:
value = float(value)
self.szFormatedValue = str(float(value))
else:
raise RuntimeError("Invalid Option TValueType")
print("setting option <{0}> to: {1}".format(self.szOptionName,value))
self.setAddKeyValue(value)
raise RuntimeError("Invalid Option TValueType")
print("setting option <{0}> to: {1}".format(self.szOptionName,self.szFormatedValue))
@abstractmethod
def set(self,value):
@@ -142,8 +147,9 @@ class GameOption_UT99(GameOption):
def set(self,value:str):
if not self.szOptionName:
raise RuntimeError("szOptionName is not set")
self.format(value)
inifile = ChaChaSimpleINI_UT(self.mainConfigFilePath)
inifile.setAddKeyValue(self.szSectionName,self.szKeyName,value,self.bForceAdd)
inifile.setAddKeyValue(self.szSectionName,self.szKeyName,self.szFormatedValue,self.bForceAdd)
inifile.writeFile()
def rem(self,value:str):