Mieux le reseaux

This commit is contained in:
AleaJactaEst 2020-05-02 20:52:15 +02:00
parent e38836527f
commit 6ec43b2a00

View file

@ -0,0 +1,67 @@
# Manage configuration to connect on khaganat
#
# Copyright (C) 2019 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class_name string_manager
# $HOMEDIR/.local/share/godot/app_userdata/Khanat/string.cfg
var _config_filename = "user://string.cfg"
var _timestamp = 0
var _phrases = {}
func write():
print("[config string_manager] Save config")
var config_file = ConfigFile.new()
config_file.set_value("config", "timestamp", self._timestamp)
for i in _phrases:
config_file.set_value("phrases", i, _phrases[i])
config_file.save(_config_filename)
func read():
print("[config string_manager] Load connexion config")
var need_write = false
var config_file = ConfigFile.new()
var err = config_file.load(_config_filename)
if err:
print("Error code when loading player config file ", _config_filename, " : ", err)
need_write = true
self._timestamp = config_file.get_value("config", "timestamp", self._timestamp)
for i in config_file.get_section_keys("phrases"):
_phrases[i] = config_file.get_value("phrases", i, "")
if need_write:
write()
func _init():
read()
func get_timestamp():
return self._timestamp
func check_phases(id):
if _phrases.has(id):
return true
return false
func get_phases(id):
if _phrases.has(id):
return _phrases[id]
return ""
func set_timestamp(timestamp):
if self._timestamp != timestamp:
self._timestamp = timestamp
write()