Added a lot of things, working on save/loading of the game

This commit is contained in:
leca 2024-05-31 02:41:00 +03:00
parent 6f82c0d97c
commit cba56ef1da
26 changed files with 639 additions and 24 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cs0pf7ogpaqm0"
path="res://.godot/imported/Tree texture.png-f926170428cfb15d629cee223218cb1e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://models/textures/Tree texture.png"
dest_files=["res://.godot/imported/Tree texture.png-f926170428cfb15d629cee223218cb1e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
models/tree1.blend Normal file

Binary file not shown.

50
models/tree1.blend.import Normal file
View File

@ -0,0 +1,50 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://iex6w53r12mp"
path="res://.godot/imported/tree1.blend-cc08633ad44091cf543995f60bfe014d.scn"
[deps]
source_file="res://models/tree1.blend"
dest_files=["res://.godot/imported/tree1.blend-cc08633ad44091cf543995f60bfe014d.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1
blender/nodes/visible=0
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true

BIN
models/tree1.blend1 Normal file

Binary file not shown.

BIN
models/tree1.glb Normal file

Binary file not shown.

34
models/tree1.glb.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bmtdabffpea0c"
path="res://.godot/imported/tree1.glb-11071132bbffea34242c0708ce7d8c96.scn"
[deps]
source_file="res://models/tree1.glb"
dest_files=["res://.godot/imported/tree1.glb-11071132bbffea34242c0708ce7d8c96.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@ -0,0 +1,38 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bmdnagwn484ry"
path.s3tc="res://.godot/imported/tree1_Tree texture.png-a307eefd8a9f7394b4f1a33a9ac5ea26.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={
"md5": "608aea78302cc1f1db9655a5e11c59a2"
}
[deps]
source_file="res://models/tree1_Tree texture.png"
dest_files=["res://.godot/imported/tree1_Tree texture.png-a307eefd8a9f7394b4f1a33a9ac5ea26.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View File

@ -11,13 +11,18 @@ config_version=5
[application] [application]
config/name="Godsim" config/name="Godsim"
run/main_scene="res://scenes/world.tscn" run/main_scene="res://scenes/UI/main_menu.tscn"
config/features=PackedStringArray("4.2", "Forward Plus") config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload] [autoload]
Definitions="*res://scripts/definitions.gd" Definitions="*res://scripts/definitions.gd"
World="*res://scripts/world.gd"
[filesystem]
import/fbx/enabled=false
[input] [input]
@ -69,6 +74,7 @@ run={
LMC={ LMC={
"deadzone": 0.5, "deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
] ]
} }
"tile type loop"={ "tile type loop"={
@ -76,3 +82,8 @@ LMC={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"echo":false,"script":null)
] ]
} }
ingame_menu={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}

View File

@ -0,0 +1,73 @@
[gd_scene load_steps=3 format=3 uid="uid://csfa8wr1fbfb2"]
[ext_resource type="Script" path="res://scripts/ingame_menu.gd" id="1_swq50"]
[ext_resource type="Script" path="res://scripts/menu_button.gd" id="2_ey872"]
[node name="ingame_menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_swq50")
[node name="PanelContainer" type="PanelContainer" parent="."]
modulate = Color(1, 1, 1, 0.501961)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 89.0
offset_top = 93.0
offset_right = -89.0
offset_bottom = -93.0
grow_horizontal = 2
grow_vertical = 2
[node name="Buttons" type="Control" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="save_world_button" type="Button" parent="Buttons"]
layout_mode = 2
offset_left = -45.0
offset_top = -45.0
offset_right = 46.0
offset_bottom = -14.0
size_flags_horizontal = 4
size_flags_vertical = 4
text = "Save world"
script = ExtResource("2_ey872")
[node name="save_exit_button" type="Button" parent="Buttons"]
layout_mode = 2
offset_left = -71.0
offset_top = 22.0
offset_right = 87.0
offset_bottom = 53.0
size_flags_horizontal = 4
size_flags_vertical = 4
text = "Save and exit game"
script = ExtResource("2_ey872")
[node name="exit_nosave_button" type="Button" parent="Buttons"]
layout_mode = 2
offset_left = 334.0
offset_top = 212.0
offset_right = 492.0
offset_bottom = 243.0
size_flags_horizontal = 4
size_flags_vertical = 4
text = "exit without saving"
script = ExtResource("2_ey872")

59
scenes/UI/main_menu.tscn Normal file
View File

@ -0,0 +1,59 @@
[gd_scene load_steps=2 format=3 uid="uid://byrk15nhm7h45"]
[ext_resource type="Script" path="res://scripts/menu_button.gd" id="1_48nxl"]
[node name="Main menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="new_world_button" type="Button" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -47.0
offset_top = -73.0
offset_right = 45.0
offset_bottom = -42.0
grow_horizontal = 2
grow_vertical = 2
text = "New world"
script = ExtResource("1_48nxl")
[node name="load_world_button" type="Button" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -47.5
offset_top = -15.5
offset_right = 47.5
offset_bottom = 15.5
grow_horizontal = 2
grow_vertical = 2
text = "Load world"
script = ExtResource("1_48nxl")
[node name="quit_button" type="Button" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -23.0
offset_top = 55.0
offset_right = 19.0
offset_bottom = 86.0
grow_horizontal = 2
grow_vertical = 2
text = "Quit"
script = ExtResource("1_48nxl")

View File

@ -1,7 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://b6er1dx11vq1a"] [gd_scene load_steps=5 format=3 uid="uid://b6er1dx11vq1a"]
[ext_resource type="Script" path="res://scripts/God.gd" id="1_hfa56"] [ext_resource type="Script" path="res://scripts/God.gd" id="1_hfa56"]
[ext_resource type="PackedScene" uid="uid://bs7ctvbx7xov5" path="res://scenes/ui.tscn" id="2_06brk"] [ext_resource type="PackedScene" uid="uid://bs7ctvbx7xov5" path="res://scenes/UI/ui.tscn" id="2_tlgt4"]
[ext_resource type="Script" path="res://scripts/ingame_menu.gd" id="3_26rdb"]
[ext_resource type="Script" path="res://scripts/ingame_menu_button.gd" id="4_ggyng"]
[node name="God" type="Node3D"] [node name="God" type="Node3D"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0) transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0)
@ -12,5 +14,75 @@ script = ExtResource("1_hfa56")
[node name="eye" type="RayCast3D" parent="Camera"] [node name="eye" type="RayCast3D" parent="Camera"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0) transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
target_position = Vector3(100, 0, 0) target_position = Vector3(100, 0, 0)
collision_mask = 3
[node name="UI" parent="." instance=ExtResource("2_06brk")] [node name="UI" parent="." instance=ExtResource("2_tlgt4")]
[node name="ingame_menu" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("3_26rdb")
[node name="PanelContainer" type="PanelContainer" parent="ingame_menu"]
modulate = Color(1, 1, 1, 0.501961)
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 89.0
offset_top = 93.0
offset_right = -89.0
offset_bottom = -93.0
grow_horizontal = 2
grow_vertical = 2
[node name="Buttons" type="Control" parent="ingame_menu"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="save_world_button" type="Button" parent="ingame_menu/Buttons"]
layout_mode = 2
offset_left = -45.0
offset_top = -45.0
offset_right = 46.0
offset_bottom = -14.0
size_flags_horizontal = 4
size_flags_vertical = 4
text = "Save world"
script = ExtResource("4_ggyng")
[node name="save_exit_button" type="Button" parent="ingame_menu/Buttons"]
layout_mode = 2
offset_left = -71.0
offset_top = 22.0
offset_right = 87.0
offset_bottom = 53.0
size_flags_horizontal = 4
size_flags_vertical = 4
text = "Save and exit game"
script = ExtResource("4_ggyng")
[node name="exit_nosave_button" type="Button" parent="ingame_menu/Buttons"]
layout_mode = 2
offset_left = 334.0
offset_top = 212.0
offset_right = 492.0
offset_bottom = 243.0
size_flags_horizontal = 4
size_flags_vertical = 4
text = "exit without saving"
script = ExtResource("4_ggyng")

View File

@ -33,6 +33,7 @@ size = Vector3(10, 5, 10)
[node name="Tile" type="StaticBody3D"] [node name="Tile" type="StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0)
collision_layer = 2
script = ExtResource("1_s01tx") script = ExtResource("1_s01tx")
[node name="Empty_tile" type="CollisionShape3D" parent="."] [node name="Empty_tile" type="CollisionShape3D" parent="."]
@ -64,13 +65,17 @@ skeleton = NodePath("../..")
[node name="ray_north" type="RayCast3D" parent="."] [node name="ray_north" type="RayCast3D" parent="."]
target_position = Vector3(10, 0, 0) target_position = Vector3(10, 0, 0)
collision_mask = 3
[node name="ray_south" type="RayCast3D" parent="."] [node name="ray_south" type="RayCast3D" parent="."]
target_position = Vector3(-10, 0, 0) target_position = Vector3(-10, 0, 0)
collision_mask = 3
[node name="ray_west" type="RayCast3D" parent="."] [node name="ray_west" type="RayCast3D" parent="."]
target_position = Vector3(0, 0, -10) target_position = Vector3(0, 0, -10)
collision_mask = 3
[node name="ray_east" type="RayCast3D" parent="."] [node name="ray_east" type="RayCast3D" parent="."]
target_position = Vector3(0, 0, 10) target_position = Vector3(0, 0, 10)
collision_mask = 3
collide_with_areas = true collide_with_areas = true

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://diinihb536yya"]
[ext_resource type="PackedScene" uid="uid://bmtdabffpea0c" path="res://models/tree1.glb" id="1_q4afb"]
[node name="Tree1" type="Node3D"]
[node name="tree1" parent="." instance=ExtResource("1_q4afb")]
[editable path="tree1"]

View File

@ -1,29 +1,28 @@
[gd_scene load_steps=6 format=3 uid="uid://dh52xle0rfx5r"] [gd_scene load_steps=6 format=3 uid="uid://dh52xle0rfx5r"]
[ext_resource type="PackedScene" uid="uid://b6er1dx11vq1a" path="res://scenes/models/god.tscn" id="1_vj3b2"] [ext_resource type="Script" path="res://scripts/Earth.gd" id="1_u71pd"]
[ext_resource type="Script" path="res://scripts/Earth.gd" id="2_oiur1"] [ext_resource type="PackedScene" uid="uid://b6er1dx11vq1a" path="res://scenes/models/god.tscn" id="2_frpdt"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_xk8d1"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_01wm3"]
[sub_resource type="Sky" id="Sky_wd7fg"] [sub_resource type="Sky" id="Sky_oeb53"]
sky_material = SubResource("ProceduralSkyMaterial_xk8d1") sky_material = SubResource("ProceduralSkyMaterial_01wm3")
[sub_resource type="Environment" id="Environment_4ke8e"] [sub_resource type="Environment" id="Environment_4hkk2"]
background_mode = 2 background_mode = 2
sky = SubResource("Sky_wd7fg") sky = SubResource("Sky_oeb53")
ambient_light_source = 3
[node name="World" type="Node3D"] [node name="World" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.20056, -2.31495, -0.853709)
[node name="God" parent="." instance=ExtResource("1_vj3b2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, 1)
[node name="Sky" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_4ke8e")
[node name="Sun" type="DirectionalLight3D" parent="Sky"]
transform = Transform3D(-0.0647024, -0.76, 0.646694, -0.0118927, 0.648593, 0.761042, -0.997834, 0.0415503, -0.051004, 0, 0, 0)
shadow_enabled = true
[node name="Earth" type="Node3D" parent="."] [node name="Earth" type="Node3D" parent="."]
script = ExtResource("2_oiur1") script = ExtResource("1_u71pd")
[node name="God" parent="." instance=ExtResource("2_frpdt")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -2.77222, 0.906321, 0)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_4hkk2")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="WorldEnvironment"]
transform = Transform3D(-3.53179e-08, 0.58921, -0.80798, 2.57552e-08, 0.80798, 0.58921, 1, 0, -4.37114e-08, -14.3426, 13.3054, 0)

View File

@ -10,6 +10,8 @@ var tile_exemplar = preload("res://scenes/models/tile.tscn");
func _ready(): func _ready():
var start_tile = tile_exemplar.instantiate() var start_tile = tile_exemplar.instantiate()
start_tile.add_to_group("Persistent")
add_child(start_tile); add_child(start_tile);
func _physics_process(delta): func _physics_process(delta):
@ -23,6 +25,7 @@ func mark_free_tiles():
for dir in free_dirs: for dir in free_dirs:
var free_tile = tile_exemplar.instantiate() var free_tile = tile_exemplar.instantiate()
free_tile.tile_type = TileType.Empty free_tile.tile_type = TileType.Empty
free_tile.add_to_group("Persistent")
add_child(free_tile) add_child(free_tile)
var pos: Vector3 = tile.position var pos: Vector3 = tile.position
match dir: match dir:

View File

@ -41,7 +41,7 @@ func _physics_process(delta):
velocity_label.text = "Velocity: " + str(walk) velocity_label.text = "Velocity: " + str(walk)
var input_dir = Input.get_vector("left", "right", "forward", "backward") var input_dir = Input.get_vector("left", "right", "forward", "backward")
var direction = (head.transform.basis * Vector3(input_dir.x, input_dir.x, input_dir.y)).normalized() var direction = (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
var velocity = Vector3.ZERO var velocity = Vector3.ZERO
var speed var speed

View File

@ -32,3 +32,13 @@ func get_free_dirs_around():
func _process(delta): func _process(delta):
pass pass
func save():
if tile_type == TileType.Empty: return {}
return {
"node": "tile",
"pos_x": position.x,
"pos_y": position.y,
"pos_z": position.z,
"tile_type": tile_type
}

6
scripts/ingame_menu.gd Normal file
View File

@ -0,0 +1,6 @@
extends Control
func _physics_process(delta):
if Input.is_action_just_pressed("ingame_menu"):
self.visible = !self.visible
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE if self.visible else Input.MOUSE_MODE_CAPTURED)

View File

@ -0,0 +1,24 @@
extends Button
@onready var button = $"."
@onready var main_menu = $".."
var world_scene = preload("res://scenes/world.tscn")
func _ready():
print("ready")
enable()
func enable():
$".".pressed.connect(self._button_pressed)
func disable():
$".".pressed.disconnect()
func _button_pressed():
if ("save_world" in name):
World.save_world()
elif ("save_exit" in name):
World.save_world()
get_tree().change_scene_to_file("res://scenes/UI/main_menu.tscn")
elif ("exit_nosave" in name):
get_tree().change_scene_to_file("res://scenes/UI/main_menu.tscn")

42
scripts/menu_button.gd Normal file
View File

@ -0,0 +1,42 @@
extends Button
@onready var button = $"."
@onready var main_menu = $".."
var world_scene = preload("res://scenes/world.tscn")
func _ready():
print("ready")
enable()
func test():
print("test")
func enable():
$".".pressed.connect(self._button_pressed)
func disable():
$".".pressed.disconnect()
func _button_pressed():
if ("quit" in name):
get_tree().quit()
elif ("new_world" in name):
get_tree().change_scene_to_packed(world_scene)
World.new_world()
elif ("load_world" in name):
#assert(get_tree().change_scene_to_packed(world_scene) == OK)
#get_tree().change_scene_to_packed(world_scene)
var world_scene_instance = world_scene.instantiate();
world_scene_instance.name = "world"
var a = $"/root/Main menu"
print(str(a))
get_tree().root.add_child(world_scene_instance)
get_tree().root.remove_child(a)
World.load_world("world")
elif ("save_world" in name):
World.save_world()
elif ("save_exit" in name):
World.save_world()
get_tree().change_scene_to_file("res://scenes/UI/main_menu.tscn")
elif ("exit_nosave" in name):
get_tree().change_scene_to_file("res://scenes/UI/main_menu.tscn")

108
scripts/world.gd Normal file
View File

@ -0,0 +1,108 @@
extends Node
var world_seed = 0;
var world_info = {
"seed": 0,
"name": "world"
}
func _ready():
#new_world()
pass
func new_world():
world_info.seed = round(Time.get_unix_time_from_system())
print("World seed is " + str(world_info.seed))
print("World name is " + str(world_info.name))
func save_world():
print("Saving world")
var save_game = FileAccess.open("user://%s.save" % world_info.name, FileAccess.WRITE)
# Saving world info
save_game.store_line(JSON.stringify(world_info))
var save_nodes = get_tree().get_nodes_in_group("Persistent")
for node in save_nodes:
# Check the node is an instanced scene so it can be instanced again during load.
if node.scene_file_path.is_empty():
print("persistent node '%s' is not an instanced scene, skipped" % node.name)
continue
# Check the node has a save function.
if !node.has_method("save"):
print("persistent node '%s' is missing a save() function, skipped" % node.name)
continue
# Call the node's save function.
var node_data = node.call("save")
#print(node_data)
if (node_data == {}): continue
# JSON provides a static method to serialized JSON string.
var json_string = JSON.stringify(node_data)
# Store the save dictionary as a new line in the save file.
save_game.store_line(json_string)
func load_world(save_name):
if not FileAccess.file_exists("user://%s.save" % save_name):
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("Persistent")
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("user://%s.save" % save_name, FileAccess.READ)
var json_string_world = save_game.get_line()
var json_world = JSON.new()
var parse_result_world = json_world.parse(json_string_world)
if not parse_result_world == OK:
print("JSON Parse Error: ", json_world.get_error_message(), " in ", json_string_world, " at line ", json_world.get_error_line())
return
world_info = json_world.get_data()
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()
var new_object
match node_data["node"]:
"tile":
new_object = load("res://scenes/models/tile.tscn").instantiate()
#print(str(get_tree().root.get_node("world/Earth")))
get_tree().root.get_node("world/Earth").add_child(new_object)
new_object.position = Vector3(node_data["pos_x"], node_data["pos_y"], node_data["pos_z"])
# Now we set the remaining variables.
for i in node_data.keys():
if i == "node" or "pos" in i:
continue
new_object.set(i, node_data[i])
new_object.call("update_tile")
get_tree().root.get_node("world/Earth").call("mark_free_tiles")

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

View File

@ -0,0 +1,38 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://djg78u0i8giw8"
path.s3tc="res://.godot/imported/tree1_Tree texture.png-643219c601b830844579a0c7f3bf8bf3.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={
"md5": "608aea78302cc1f1db9655a5e11c59a2"
}
[deps]
source_file="res://textures/tree1_Tree texture.png"
dest_files=["res://.godot/imported/tree1_Tree texture.png-643219c601b830844579a0c7f3bf8bf3.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0