Skip to content

Instantly share code, notes, and snippets.

@YeOldeDM
YeOldeDM / _delete_data.py
Created August 6, 2016 20:18
delete a folder, and all contents of that folder
func _delete_data(path):
var dir = Directory.new()
var opened = dir.change_dir(path)
if opened != OK:
OS.alert("Error "+str(opened)+" opening path: "+path)
dir.list_dir_begin()
var current = dir.get_next()
print(current)
while not current.empty():
# List of current Actions used by Controller.
# (update this as new actions are added)
var cmd_list = [
'thrust_pro',
'thrust_retro',
'rcs_pro',
'rcs_retro',
'rcs_left',
'rcs_right',
'yaw_left',
#################################################
# CONTROLLER SIGNALS FOR SHIP FLIGHT CONTROL #
# #
# (Any actions set in this ship's Controller #
# MUST have a function defined here. The #
# function name must be identical to the #
# Controller signal emitted. #
# #
#################################################
# CONTROLLER SIGNAL FUNCTIONS START HERE #
extends Position2D
onready var main = get_node('/root/Main')
func _ready():
set_process(true)
func _process(delta):
# apply ship rotation to radar rotation
extends Node
## solution for dealing with Big Friggin Numbers
#value is stored as a list of ints 0-999
#if an int > 999, remainder is carried over to a new int
# 10 = [10]
# 100 = [100]
# 1000 = [0,1]
var story = {
'clearing': {
'text': "You are in a sunny CLEARING.",
'choices': {
'north': 'castle',
'west': 'river',
'east': 'forest',
}
},
func _integrate_forces(state):
var direction = get_linear_velocity()
var step = state.get_step()
for i in range(state.get_contact_count()):
var pos = get_pos()
var col = state.get_contact_collider_object(i)
var norm = state.get_contact_local_normal(i)
#..global save func
func save_hero(hero):
#grab data
var data = hero.get_package()
#init save file
var save = File.new()
var path = 'res://data/heroes/'+hero.get_name()+'.zd'
save.open(path,File.WRITE)
#save data
save.store_line(data.to_json())
+# load from a file with several dicts
+static func loadJsonMult(path):
+ var curfile = File.new()
+ if ( !curfile.file_exists(path)):
+ logd(str("ERR: loadJson file doesn't exist ",path))
+ return null
+ curfile.open(path,File.READ)
+ logd(str("MSG: loadJsonMult from ",path))
+ var data = {}
#Make sure our file exists:
if not saveGame.file_exists('res://saves/savegame.sav'):
print("no savegame found!")
return
#Dict to hold json lines
var loadNodes = {}
#Open file to Read
saveGame.open('res://saves/savegame.sav', File.READ)
#Go through file lines and append each line to loadNodes
while (!saveGame.eof_reached()):