diff --git a/import.gd b/import.gd index 85cd2c0..59c67e8 100644 --- a/import.gd +++ b/import.gd @@ -3,11 +3,15 @@ tool extends EditorPlugin var map_path = "" +var error_popup const FLIPPED_HORIZONTALLY_FLAG = 0x80000000 const FLIPPED_VERTICALLY_FLAG = 0x40000000 const FLIPPED_DIAGONALLY_FLAG = 0x20000000 +func _ready(): + error_popup = get_node("ErrorPopup") + func createTileset(var data, var cell_size): var ts = TileSet.new() var size = cell_size @@ -18,6 +22,8 @@ func createTileset(var data, var cell_size): var file = File.new() if (!file.file_exists(path)): print("couldn't find the tileset: " + path) + error_popup.set_text("couldn't find the tileset: " + path) + error_popup.popup() return false var texture = load(path) texture.set_flags(0) @@ -100,19 +106,24 @@ func _on_Button_pressed(): var root_node = get_tree().get_edited_scene_root() if root_node == null: print("No root node found. Please add one before trying to import a tiled map") + error_popup.set_text("No root node found. Please add one before trying to import a tiled map") + error_popup.popup() return var json = File.new() if (json.file_exists(map_path)): json.open(map_path, 1) else: - print("the map file seems to not exist") + print("The map file " + map_path +" seems to not exist.") + error_popup.set_text("The map file " + map_path +" seems to not exist.") + error_popup.popup() return false var map_data = {} var err = map_data.parse_json(json.get_as_text()) if (err!=OK): - print("error parsing json") - else: - print("success!") + print("Error parsing the map file. Please make sure it's in a valid format. Currently only .json is supported") + error_popup.set_text("Error parsing the map file. Please make sure it's in a valid format. Currently only .json is supported") + error_popup.popup() + return var tilemap_root = Node2D.new() tilemap_root.set_name("Tile Map") @@ -155,6 +166,9 @@ func _on_Button_pressed(): layer_map.set_cell(x, y, gid, flipped_horizontally, flipped_vertically) i += 1 + error_popup.set_text("Succesfully imported the map") + error_popup.popup() + return func _on_FileDialog_file_selected( path ): map_path = path diff --git a/plugin.cfg b/plugin.cfg index 923d5d9..3fcb93e 100644 --- a/plugin.cfg +++ b/plugin.cfg @@ -3,6 +3,6 @@ name = "Tiled Map Importer" description = "Imports Map from the program Tiled. Only works with .json files, so make sure you export your maps right!" author = "MrGreen" -version = "0.1" +version = "0.2" installs = false -script = "start.gd" \ No newline at end of file +script = "start.gd" diff --git a/plugin.xml b/plugin.xml index f79ebd8..5879462 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,18 +1,22 @@ - + - "tool�a;extends Button�a;�a;func _on_Button_pressed():�a; var _filedialog = get_child(0)�a; _filedialog.set_current_path("")�a; _filedialog.set_current_path("res://")�a; _filedialog.show()�a;" + "tool�a;extends Button�a;�a;func _on_Button_pressed():�a; var _filedialog = get_node("FileDialog")�a; #_filedialog.set_current_path("")�a; _filedialog.set_current_path("res://")�a; _filedialog.show()�a;" - "tool�a;extends FileDialog�a;�a;func _ready():�a; add_filter("*.json")�a; set_mode(MODE_OPEN_FILE)�a; #set_access(ACCESS_FILESYSTEM)�a; hide()�a;�a;func _on_CheckBox_toggled( pressed ):�a; if (pressed):�a; set_access(ACCESS_FILESYSTEM)�a; else:�a; set_access(ACCESS_RESOURCES)" + "tool�a;extends FileDialog�a;�a;func _ready():�a; add_filter("*.json")�a; set_mode(MODE_OPEN_FILE)�a; hide()�a;�a;func _on_CheckBox_toggled( pressed ):�a; if (pressed):�a; set_access(ACCESS_FILESYSTEM)�a; else:�a; set_access(ACCESS_RESOURCES)" + "conn_count" + 4 + "conns" + 2, 2, 48, 47, 2, 0, 3, 6, 50, 49, 2, 0, 4, 3, 52, 51, 2, 0, 5, 6, 48, 47, 2, 0 "names" - + "WindowDialog" "_import_path" "visibility/visible" @@ -58,6 +62,8 @@ "import" "anchor/top" "EditorPlugin" + "ErrorPopup" + "AcceptDialog" "_on_Button_pressed" "pressed" "_on_FileDialog_file_selected" @@ -65,14 +71,12 @@ "_on_CheckBox_toggled" "toggled" - "version" - 1 - "conn_count" - 4 "node_count" - 7 + 8 + "nodes" + -1, -1, 0, 0, -1, 21, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 6, 4, 7, 5, 8, 6, 9, 7, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 19, 1, 20, 10, 21, 11, 0, 0, 0, 22, 22, -1, 17, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 23, 3, 24, 3, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 25, 8, 0, 0, 0, 27, 26, -1, 30, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 28, 12, 23, 12, 6, 13, 7, 14, 8, 15, 9, 16, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 29, 8, 30, 8, 31, 8, 32, 8, 33, 17, 34, 18, 35, 8, 36, 8, 37, 3, 38, 19, 0, 2, 0, 39, 39, -1, 22, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 6, 20, 7, 21, 8, 22, 9, 23, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 40, 24, 19, 1, 20, 25, 38, 26, 0, 2, 0, 41, 41, -1, 26, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 7, 13, 8, 27, 9, 28, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 29, 8, 30, 1, 31, 8, 32, 8, 33, 29, 34, 18, 35, 8, 36, 8, 37, 30, 0, 0, 0, 27, 42, -1, 31, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 28, 12, 43, 3, 23, 12, 24, 3, 6, 13, 7, 16, 8, 15, 9, 14, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 29, 8, 30, 8, 31, 8, 32, 8, 33, 31, 34, 18, 35, 8, 36, 8, 37, 3, 0, 5, 0, 44, 44, -1, 2, 1, 0, 38, 32, 0, 6, 0, 46, 45, -1, 20, 1, 0, 2, 8, 3, 2, 4, 2, 5, 3, 6, 33, 7, 34, 8, 35, 9, 36, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 19, 8, 20, 37, 0 "variants" - + "" True 1 @@ -85,134 +89,137 @@ 2 "Tiled Importer" + "__editor_plugin_screen__" + "Script" "__editor_plugin_states__" - "Script" - - "current" - 0 - "sources" - - "import.gd" - "/root/EditorNode/@Panel3/@VBoxContainer6/@HSplitContainer8/@VSplitContainer9/@VSplitContainer10/@VBoxContainer11/@Panel16/@Control18/@CanvasItemEditor5886/@VSplitContainer5811/@HSplitContainer5812/@Control5813/@Control5814/@Viewport5815/WindowDialog/chooseFile/FileDialog" - - "2D" + "ofs" + -162.516, -77.3002 + "snap_grid" + False + "snap_offset" + 0, 0 "snap_pixel" False - "snap_rotation_step" - 0.261799 - "zoom" - 2.272075 - "snap_step" - 10, 10 "snap_relative" False - "snap_grid" + "snap_rotation" False "snap_rotation_offset" 0 + "snap_rotation_step" + 0.261799 "snap_show_grid" False - "snap_offset" - 0, 0 - "ofs" - 24.8278, 9.11441 - "snap_rotation" - False + "snap_step" + 10, 10 + "zoom" + 1.507341 "3D" + "ambient_light_color" + 0.15, 0.15, 0.15, 1 + "default_light" + True + "default_srgb" + False + "deflight_rot_x" + 0.942478 "deflight_rot_y" 0.628319 - "zfar" - 500 "fov" 45 + "show_grid" + True + "show_origin" + True + "viewport_mode" + 1 "viewports" "distance" 4 - "x_rot" - 0 - "y_rot" - 0 "listener" True + "pos" + 0, 0, 0 "use_environment" False "use_orthogonal" False - "pos" - 0, 0, 0 - - - "distance" - 4 "x_rot" 0 "y_rot" 0 + + + "distance" + 4 "listener" False + "pos" + 0, 0, 0 "use_environment" False "use_orthogonal" False - "pos" - 0, 0, 0 - - - "distance" - 4 "x_rot" 0 "y_rot" 0 + + + "distance" + 4 "listener" False + "pos" + 0, 0, 0 "use_environment" False "use_orthogonal" False - "pos" - 0, 0, 0 - - - "distance" - 4 "x_rot" 0 "y_rot" 0 + + + "distance" + 4 "listener" False + "pos" + 0, 0, 0 "use_environment" False "use_orthogonal" False - "pos" - 0, 0, 0 + "x_rot" + 0 + "y_rot" + 0 - "viewport_mode" - 1 - "default_light" - True - "ambient_light_color" - 0.15, 0.15, 0.15, 1 - "show_grid" - True - "show_origin" - True + "zfar" + 500 "znear" 0.1 - "default_srgb" - False - "deflight_rot_x" - 0.942478 + + "Script" + + "current" + 0 + "sources" + + "import.gd" + "/root/EditorNode/@Panel4/@VBoxContainer7/@HSplitContainer9/@VSplitContainer10/@VSplitContainer11/@VBoxContainer12/@Panel17/@Control19/@CanvasItemEditor5885/@VSplitContainer5810/@HSplitContainer5811/@Control5812/@Control5813/@Viewport5814/WindowDialog/chooseFile" + "/root/EditorNode/@Panel4/@VBoxContainer7/@HSplitContainer9/@VSplitContainer10/@VSplitContainer11/@VBoxContainer12/@Panel17/@Control19/@CanvasItemEditor5885/@VSplitContainer5810/@HSplitContainer5811/@Control5812/@Control5813/@Viewport5814/WindowDialog/chooseFile/FileDialog" + "__editor_run_settings__" @@ -222,8 +229,6 @@ "run_mode" 0 - "__editor_plugin_screen__" - "2D" 3 40 @@ -233,9 +238,9 @@ "Choose File" 181 - 43 + 44 530 - 551 + 552 0.0784314, 0.0784314, 0.0784314, 1 "Open a File" @@ -245,12 +250,15 @@ 0 "Import map" + 126 + 180 + 573 + 282 + "Alert!" - "nodes" - -1, -1, 0, 0, -1, 21, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 6, 4, 7, 5, 8, 6, 9, 7, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 19, 1, 20, 10, 21, 11, 0, 0, 0, 22, 22, -1, 17, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 23, 3, 24, 3, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 25, 8, 0, 0, 0, 27, 26, -1, 30, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 28, 12, 23, 12, 6, 13, 7, 14, 8, 15, 9, 16, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 29, 8, 30, 8, 31, 8, 32, 8, 33, 17, 34, 18, 35, 8, 36, 8, 37, 3, 38, 19, 0, 2, 0, 39, 39, -1, 22, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 6, 20, 7, 21, 8, 22, 9, 23, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 40, 24, 19, 1, 20, 25, 38, 26, 0, 2, 0, 41, 41, -1, 26, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 7, 13, 8, 27, 9, 28, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 29, 8, 30, 1, 31, 8, 32, 8, 33, 29, 34, 18, 35, 8, 36, 8, 37, 30, 0, 0, 0, 27, 42, -1, 31, 1, 0, 2, 1, 3, 2, 4, 2, 5, 3, 28, 12, 43, 3, 23, 12, 24, 3, 6, 13, 7, 16, 8, 15, 9, 14, 10, 0, 11, 0, 12, 0, 13, 0, 14, 8, 15, 1, 16, 9, 17, 9, 18, 2, 29, 8, 30, 8, 31, 8, 32, 8, 33, 31, 34, 18, 35, 8, 36, 8, 37, 3, 0, 5, 0, 44, 44, -1, 2, 1, 0, 38, 32, 0 - "conns" - 2, 2, 46, 45, 2, 0, 3, 6, 48, 47, 2, 0, 4, 3, 50, 49, 2, 0, 5, 6, 46, 45, 2, 0 + "version" + 1 - \ No newline at end of file +