Add files via upload

master
AiTechEye 2021-03-21 14:21:05 +01:00 committed by GitHub
parent 8eafd26a98
commit c413117d9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 256 additions and 0 deletions

18
Button.gd Normal file
View File

@ -0,0 +1,18 @@
extends Control
func _ready():
print(Global.save)
if not Global.save.get(Global.current_scene_name):
Global.save[Global.current_scene_name] = {}
if Global.save[Global.current_scene_name].get(name):
queue_free()
func _on_button_down():
if not Global.save.get(Global.current_scene_name):
Global.save[Global.current_scene_name] = {}
Global.save[Global.current_scene_name][name] = true
Global.save_data()
Global.add_points()
queue_free()
print(Global.save)

22
Button.tscn Normal file
View File

@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Button.gd" type="Script" id=1]
[node name="Button" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -924.0
margin_bottom = -500.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="."]
margin_right = 100.0
margin_bottom = 100.0
text = "Collect button"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="button_down" from="Button" to="." method="_on_button_down"]

35
Control.gd Normal file
View File

@ -0,0 +1,35 @@
extends Control
func _on_stuck_button_down():
Global.save.stuck = true
get_node("stuck").disabled = true
Global.save_data()
func _on_stuck_tree_entered():
if Global.save.get("stuck"):
get_node("stuck").disabled = true
func _on_toggle_button_down():
if Global.save.get("toggled") == false:
Global.save.toggled = true
get_node("toggled").text = "Toggle (ON)"
else:
Global.save.toggled = false
get_node("toggled").text = "Toggle (OFF)"
Global.save_data()
func _on_toggled_ready():
if Global.save.get("toggled") == true:
get_node("toggled").text = "Toggle (ON) (loaded)"
elif Global.save.get("toggled") == false:
get_node("toggled").text = "Toggle (OFF) (loaded)"
else:
get_node("toggled").text = "Toggle (ON) (not loaded)"
func _on_reset_button_down():
if Global.save[Global.current_scene_name]:
Global.save[Global.current_scene_name] = null
get_tree().reload_current_scene()

92
Control.tscn Normal file
View File

@ -0,0 +1,92 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Control.gd" type="Script" id=1]
[ext_resource path="res://Button.tscn" type="PackedScene" id=2]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="stuck" type="Button" parent="."]
margin_left = 253.362
margin_top = 288.369
margin_right = 350.362
margin_bottom = 382.369
text = "Stuck button"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" parent="." instance=ExtResource( 2 )]
[node name="Button2" parent="." instance=ExtResource( 2 )]
margin_left = 117.466
margin_top = 2.66969
margin_right = -806.534
margin_bottom = -497.33
[node name="Button3" parent="." instance=ExtResource( 2 )]
margin_left = 240.939
margin_top = 5.33936
margin_right = -683.061
margin_bottom = -494.661
[node name="Button4" parent="." instance=ExtResource( 2 )]
margin_left = 357.737
margin_top = 3.3371
margin_right = -566.263
margin_bottom = -496.663
[node name="Button5" parent="." instance=ExtResource( 2 )]
margin_left = 483.212
margin_top = 2.00227
margin_right = -440.788
margin_bottom = -497.998
[node name="Button6" parent="." instance=ExtResource( 2 )]
margin_left = 606.017
margin_top = 0.667412
margin_right = -317.983
margin_bottom = -499.333
[node name="Button7" parent="." instance=ExtResource( 2 )]
margin_left = 726.153
margin_top = 2.00225
margin_right = -197.847
margin_bottom = -497.998
[node name="Button8" parent="." instance=ExtResource( 2 )]
margin_left = 7.19388
margin_top = 140.4
margin_right = -916.806
margin_bottom = -359.6
[node name="toggled" type="Button" parent="."]
margin_left = 418.859
margin_top = 261.002
margin_right = 647.859
margin_bottom = 400.002
text = "Toggle"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="reset" type="Button" parent="."]
margin_left = 18.0142
margin_top = 432.65
margin_right = 69.0142
margin_bottom = 460.65
rect_scale = Vector2( 5, 5 )
text = "Reset"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="button_down" from="stuck" to="." method="_on_stuck_button_down"]
[connection signal="tree_entered" from="stuck" to="." method="_on_stuck_tree_entered"]
[connection signal="button_down" from="toggled" to="." method="_on_toggle_button_down"]
[connection signal="ready" from="toggled" to="." method="_on_toggled_ready"]
[connection signal="button_down" from="reset" to="." method="_on_reset_button_down"]

7
default_env.tres Normal file
View File

@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

34
global.gd Normal file
View File

@ -0,0 +1,34 @@
extends Node
# This scene is added to the autoload project properties, so this will be reachable from the whole project
var current_scene_name = "world1"
var save = {
"points":0,
}
func add_points(a = 1):
save.points += a
get_node("Label").text = str(save.points)
func _enter_tree():
load_data()
get_node("Label").text = str(save.points)
# saves everyhing in the "save" variable
func save_data():
var file = File.new()
file.open("user://save",file.WRITE_READ)
file.store_var(save)
file.close()
# and load
func load_data():
var file = File.new()
if not file.file_exists("user://save"):
return false
file.open("user://save",file.READ)
save = file.get_var()
file.close()
return true

20
global.tscn Normal file
View File

@ -0,0 +1,20 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://global.gd" type="Script" id=1]
[node name="Node" type="Control"]
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
margin_left = 858.0
margin_top = 7.0
margin_right = 873.0
margin_bottom = 21.0
rect_scale = Vector2( 10, 10 )
text = "0"
__meta__ = {
"_edit_use_anchors_": false
}

28
project.godot Normal file
View File

@ -0,0 +1,28 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="Buttons"
run/main_scene="res://Control.tscn"
config/icon="res://icon.png"
[autoload]
Global="*res://global.tscn"
[rendering]
environment/default_environment="res://default_env.tres"