Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var data = OS.get_date()
- var savegame = File.new()
- var save_path = "user://meugame.save"
- var save_data
- var save_model = {
- "jsonVersion": "0.0.0.1",
- "muteMusic": 0,
- "muteSfx": 0,
- "totalMoney": 0,
- "totalDiamods": 0,
- "worlds": [
- {
- "name": "Mundo 1",
- "levels": [
- { "num": "1", "stars": "0", "concluido": "0" },
- { "num": "2", "stars": "0", "concluido": "0" },
- { "num": "3", "stars": "0", "concluido": "0" },
- { "num": "4", "stars": "0", "concluido": "0" },
- { "num": "5", "stars": "0", "concluido": "0" },
- { "num": "6", "stars": "0", "concluido": "0" },
- { "num": "7", "stars": "0", "concluido": "0" },
- { "num": "8", "stars": "0", "concluido": "0" },
- { "num": "9", "stars": "0", "concluido": "0" },
- { "num": "10", "stars": "0", "concluido": "0" }
- ]
- },{
- "name": "Mundo 2",
- "levels": []
- }
- ]
- }
- func _ready():
- if not savegame.file_exists(save_path):
- # cria um novo arquivo
- newFile(save_path, save_model)
- else:
- # carrega um arquivo já salvo
- loadSavedGame()
- # para criar um arquivo novo a partir de um modelo de dados
- func newFile(_path, _data):
- save_data = _data
- savegame.open_encrypted_with_pass(_path, File.WRITE, OS.get_unique_id())
- savegame.store_var(_data)
- savegame.close()
- # carrega um arquivo para uma variavel local
- func loadSavedGame():
- savegame.open_encrypted_with_pass(save_path, File.READ, OS.get_unique_id())
- save_data = savegame.get_var()
- savegame.close()
- # Pega da variavel local e salva no arquivo
- # Essa função geralmente chamo somente após alguma ação, por exemplo ao concluir uma fase.
- func onlySaveData():
- savegame.open_encrypted_with_pass(save_path, File.WRITE, OS.get_unique_id())
- savegame.store_var(save_data)
- savegame.close()
- # Ao trabalhar com a variavel local, você pode usar essa função para obter um valor de alguma chave
- func readData(campo):
- var ret = 0
- if save_data.has(campo):
- ret = save_data[campo]
- return ret
- # Ao trabalhar com uma variavel local, você pode usar uma função como essa para salvar as informações ainda na variavel
- func saveData(campo, valor):
- if save_data!=null:
- save_data[campo] = valor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement