tidy. default map. decay
This commit is contained in:
parent
454a14275f
commit
e9ee626484
@ -1,5 +1,8 @@
|
||||
extends ConfirmationDialog
|
||||
|
||||
func _ready():
|
||||
get_tree().root.get_node("Sim/Map").load_map("user://saves/default")
|
||||
|
||||
func _on_about_to_popup():
|
||||
$ItemList.clear()
|
||||
var dir = DirAccess.open("user://saves/")
|
||||
@ -21,49 +24,10 @@ func _on_about_to_popup():
|
||||
print("An error occurred when trying to access the path.")
|
||||
|
||||
func _on_confirmed():
|
||||
var map = get_tree().root.get_node("Sim/Map")
|
||||
|
||||
# Load and instance the selected item
|
||||
# Load and instance the first selected item
|
||||
for item in $ItemList.get_selected_items():
|
||||
$"../SaveDialog/LineEdit".text=$ItemList.get_item_text(item)
|
||||
var filename = "user://saves/" + $ItemList.get_item_text(item)
|
||||
print("load:", filename)
|
||||
|
||||
if not FileAccess.file_exists(filename):
|
||||
return # Error! We don't have a save to load.
|
||||
|
||||
# We need to revert the game state so we're not cloning objects
|
||||
# during loading. This will vary wildly depending on the needs of a
|
||||
# project, so take care with this step.
|
||||
# For our example, we will accomplish this by deleting saveable objects.
|
||||
var save_nodes = get_tree().get_nodes_in_group("Persist")
|
||||
for i in save_nodes:
|
||||
i.queue_free()
|
||||
|
||||
# Load the file line by line and process that dictionary to restore
|
||||
# the object it represents.
|
||||
var save_game = FileAccess.open(filename, FileAccess.READ)
|
||||
while save_game.get_position() < save_game.get_length():
|
||||
var json_string = save_game.get_line()
|
||||
|
||||
# Creates the helper class to interact with JSON
|
||||
var json = JSON.new()
|
||||
|
||||
# Check if there is any error while parsing the JSON string, skip in case of failure
|
||||
var parse_result = json.parse(json_string)
|
||||
if not parse_result == OK:
|
||||
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
||||
continue
|
||||
|
||||
# Get the data from the JSON object
|
||||
var node_data = json.get_data()
|
||||
|
||||
# Firstly, we need to create the object and add it to the tree and set its position.
|
||||
var new_object = load(node_data["filename"]).instantiate()
|
||||
# Check the node has a load function.
|
||||
if !new_object.has_method("load_data"):
|
||||
print("persistent node '%s' is missing a load_data() function, skipped" % new_object.name)
|
||||
new_object.queue_free()
|
||||
continue
|
||||
new_object.load_data(node_data)
|
||||
map.add_child(new_object)
|
||||
$"../SaveDialog/LineEdit".text=$ItemList.get_item_text(item).get_basename()
|
||||
get_tree().root.get_node("Sim/Map").load_map(filename)
|
||||
break
|
||||
|
41
Map.gd
41
Map.gd
@ -70,7 +70,7 @@ func spawn_player(pos,vol):
|
||||
new_player.queue_free()
|
||||
|
||||
|
||||
func not_ready():
|
||||
func _ready():
|
||||
poolcircle(Vector2(0,0),200,32,100,0,0)
|
||||
poolcircle(Vector2(600,0),200,32,0,100,0)
|
||||
poolcircle(Vector2(1200,0),200,32,0,0,100)
|
||||
@ -79,7 +79,7 @@ func not_ready():
|
||||
poolcircle(Vector2(600,600),200,32,50,0,50)
|
||||
poolcircle(Vector2(1200,600),200,32,50,50,0)
|
||||
|
||||
poolcircle(Vector2(600,200),2000,100,1000,1000,1000)
|
||||
#poolcircle(Vector2(600,200),2000,100,1000,1000,1000)
|
||||
|
||||
|
||||
func poolcircle(pos: Vector2, radius, count, r,g,b):
|
||||
@ -92,3 +92,40 @@ func poolcircle(pos: Vector2, radius, count, r,g,b):
|
||||
new_pool.mana_b=b
|
||||
new_pool.get_node("CollisionShape2D2").disabled=true;
|
||||
add_child(new_pool)
|
||||
|
||||
func load_map(filename):
|
||||
print("load:", filename)
|
||||
if not FileAccess.file_exists(filename):
|
||||
return # Error! We don't have a save to load.
|
||||
|
||||
# deleting saveable objects.
|
||||
var save_nodes = get_tree().get_nodes_in_group("Persist")
|
||||
for i in save_nodes:
|
||||
i.queue_free()
|
||||
|
||||
# Load the file line by line and process
|
||||
var save_game = FileAccess.open(filename, FileAccess.READ)
|
||||
while save_game.get_position() < save_game.get_length():
|
||||
var json_string = save_game.get_line()
|
||||
|
||||
# Creates the helper class to interact with JSON
|
||||
var json = JSON.new()
|
||||
|
||||
# Check if there is any error while parsing the JSON string, skip in case of failure
|
||||
var parse_result = json.parse(json_string)
|
||||
if not parse_result == OK:
|
||||
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
|
||||
continue
|
||||
|
||||
# Get the data from the JSON object
|
||||
var node_data = json.get_data()
|
||||
|
||||
# Firstly, we need to create the object and add it to the tree and set its position.
|
||||
var new_object = load(node_data["filename"]).instantiate()
|
||||
# Check the node has a load function.
|
||||
if !new_object.has_method("load_data"):
|
||||
print("persistent node '%s' is missing a load_data() function, skipped" % new_object.name)
|
||||
new_object.queue_free()
|
||||
continue
|
||||
new_object.load_data(node_data)
|
||||
add_child(new_object)
|
||||
|
@ -140,3 +140,7 @@ func load_data(data):
|
||||
carrying_r=data["r"]
|
||||
carrying_g=data["g"]
|
||||
carrying_b=data["b"]
|
||||
|
||||
|
||||
func _on_decay_timer_timeout():
|
||||
pass # Replace with function body.
|
||||
|
16
Pool.gd
16
Pool.gd
@ -45,13 +45,12 @@ func update():
|
||||
self.scale=Vector2(s,s)
|
||||
self.queue_redraw() # Request to redraw the node
|
||||
|
||||
|
||||
func decay():
|
||||
var new_player = load("res://player.tscn").instantiate()
|
||||
new_player.get_node("CharacterBody2D").velocity = Vector2.from_angle(randf_range(0, 2 * PI)) * 100
|
||||
new_player.get_node("CharacterBody2D").position = position
|
||||
new_player.get_node("CharacterBody2D").exchange_with(self)
|
||||
new_player.get_node("CharacterBody2D/CollisionShape2D").disabled=true
|
||||
new_player.apply_impulse(Vector2.from_angle(randf_range(0, 2 * PI)) * 100)
|
||||
new_player.position = position
|
||||
new_player.exchange_with(self)
|
||||
new_player.get_node("CollisionShape2D").disabled=true
|
||||
get_tree().root.add_child(new_player)
|
||||
|
||||
func save_data():
|
||||
@ -70,3 +69,10 @@ func load_data(data):
|
||||
mana_r=data["r"]
|
||||
mana_g=data["g"]
|
||||
mana_b=data["b"]
|
||||
|
||||
func _on_decay_timer_timeout():
|
||||
if not get_tree().root.get_node("Sim/ScreenOverlay/HUD/HBoxContainer/HBoxContainer3/Decay").is_pressed():
|
||||
return
|
||||
if (mana_r+mana_g+mana_b)>randf_range(0,99999):
|
||||
decay()
|
||||
#$DecayTimer.wait_time=
|
||||
|
@ -3,7 +3,12 @@ extends ConfirmationDialog
|
||||
var base_path = "user://saves/"
|
||||
|
||||
func _ready():
|
||||
if not DirAccess.dir_exists_absolute(base_path):
|
||||
print("check for saves folder...")
|
||||
if DirAccess.dir_exists_absolute(base_path):
|
||||
print("...exists")
|
||||
return
|
||||
|
||||
print("...not exist, create...")
|
||||
DirAccess.make_dir_recursive_absolute(base_path)
|
||||
var dir = DirAccess.open("res://saves/")
|
||||
if dir:
|
||||
|
@ -213,7 +213,7 @@ custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="bin/alpha8.x86_64"
|
||||
export_path="bin/alpha9.x86_64"
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
encrypt_pck=false
|
||||
@ -224,7 +224,7 @@ encrypt_directory=false
|
||||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
debug/export_console_wrapper=0
|
||||
binary_format/embed_pck=false
|
||||
binary_format/embed_pck=true
|
||||
texture_format/bptc=true
|
||||
texture_format/s3tc=true
|
||||
texture_format/etc=false
|
||||
@ -253,7 +253,7 @@ custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="bin/alpha8_macos.zip"
|
||||
export_path="bin/alpha9_macos.zip"
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
encrypt_pck=false
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_fmfn8"]
|
||||
|
||||
[node name="StaticBody2D" type="StaticBody2D" groups=["Persist"]]
|
||||
[node name="Pool" type="StaticBody2D" groups=["Persist"]]
|
||||
scale = Vector2(0.173205, 0.173205)
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_tvic3")
|
||||
@ -16,3 +17,8 @@ shape = SubResource("CircleShape2D_fmfn8")
|
||||
|
||||
[node name="Icon" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_45evg")
|
||||
|
||||
[node name="DecayTimer" type="Timer" parent="."]
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="DecayTimer" to="." method="_on_decay_timer_timeout"]
|
||||
|
4
sim.tscn
4
sim.tscn
@ -56,6 +56,10 @@ max_length = 5
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
|
||||
[node name="Decay" type="CheckBox" parent="ScreenOverlay/HUD/HBoxContainer/HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
text = "Decay"
|
||||
|
||||
[node name="Load" type="Button" parent="ScreenOverlay/HUD/HBoxContainer/HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
text = "Load..."
|
||||
|
Loading…
Reference in New Issue
Block a user