Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot File Handler #268

Merged
merged 10 commits into from
May 18, 2024
File renamed without changes.
43 changes: 11 additions & 32 deletions Spatial.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ const category3d_scene = preload("res://Category3D.tscn")
const category2d_scene = preload("res://Category2D.tscn")
const path2d_scene = preload("res://Route2D.tscn")
const gizmo_scene = preload("res://Gizmo/PointEdit.tscn")

# Scripts containing code used by this scene
const CategoryData = preload("res://CategoryData.gd")
const Waypoint = preload("res://waypoint.gd")
const PackDialog = preload("res://PackDialog.gd")
const FileHandler = preload("res://FileHandler.gd")

# Instancing scripts
var file_handler: FileHandler = FileHandler.new()
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved

##########Node Connections###########
onready var markers_ui := $Control/Dialogs/CategoriesDialog/MarkersUI as Tree
Expand All @@ -80,6 +85,9 @@ func _ready():
OS.set_window_position(Vector2(0,0))
set_minimal_mouse_block()

# Call ready for additional scripts
self.file_handler._ready()
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved

server.listen(4242)

if (Settings.burrito_link_auto_launch_enabled):
Expand Down Expand Up @@ -632,32 +640,6 @@ func gen_new_icon(position: Vector3, texture_path: String, waypoint_icon, catego
var category_data = category_item.get_metadata(0)
category_data.category3d.add_icon(new_icon)

# This function take all of the currently rendered objects and converts it into
# the data format that is saved/loaded from.
func data_from_renderview():
var icons_data = []
var paths_data = []

for icon in $Icons.get_children():
icons_data.append({
"position": [icon.translation.x, icon.translation.y, -icon.translation.z],
"texture": icon.texture_path
})

for path in $Paths.get_children():
#print(path)
var points = []
for point in range(path.get_point_count()):
var point_position:Vector3 = path.get_point_position(point)
points.append([point_position.x, point_position.y, -point_position.z])
paths_data.append({
"points": points,
"texture": path.texture_path
})

var data_out = {"icons": icons_data, "paths": paths_data}
return data_out

AsherGlick marked this conversation as resolved.
Show resolved Hide resolved
################################################################################
# Adjustment and gizmo functions
################################################################################
Expand Down Expand Up @@ -822,16 +804,13 @@ func _on_NewPathPoint_pressed():
#
################################################################################
func _on_SavePath_pressed():
$Control/Dialogs/SaveDialog.show()
pass

################################################################################
# TODO: This function will be used when exporting packs
################################################################################
func _on_SaveDialog_file_selected(path):
self.markerdata[str(self.map_id)] = data_from_renderview()
var save_game = File.new()
save_game.open(path, File.WRITE)
save_game.store_string(JSON.print(self.markerdata))
pass
AsherGlick marked this conversation as resolved.
Show resolved Hide resolved

func _on_NodeEditorDialog_hide():
self.currently_selected_node = null
Expand Down
4 changes: 2 additions & 2 deletions Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[ext_resource path="res://Spatial.gd" type="Script" id=1]
[ext_resource path="res://shaders/range_indicators.shader" type="Shader" id=2]
[ext_resource path="res://burrito.png" type="Texture" id=3]
[ext_resource path="res://FileHandler.gd" type="Script" id=4]
[ext_resource path="res://icon_close.png" type="Texture" id=5]
[ext_resource path="res://RangeDialog.gd" type="Script" id=6]
[ext_resource path="res://icon_new_icon.png" type="Texture" id=7]
Expand All @@ -12,7 +13,6 @@
[ext_resource path="res://icon_new_point.png" type="Texture" id=11]
[ext_resource path="res://SettingsDialog.gd" type="Script" id=12]
[ext_resource path="res://Category3D.gd" type="Script" id=13]
[ext_resource path="res://PackDialog.gd" type="Script" id=14]
[ext_resource path="res://Category2D.gd" type="Script" id=15]

[sub_resource type="Shader" id=1]
Expand Down Expand Up @@ -193,7 +193,7 @@ mode = 2
access = 2
current_dir = ""
current_path = ""
script = ExtResource( 14 )
script = ExtResource( 4 )
__meta__ = {
"_edit_use_anchors_": false
}
Expand Down