Skip to content

Commit

Permalink
Added some error messages to make it more clear what went wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGreenTea committed May 12, 2015
1 parent 26320da commit 5175638
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 88 deletions.
22 changes: 18 additions & 4 deletions import.gd
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions plugin.cfg
Expand Up @@ -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"
script = "start.gd"
172 changes: 90 additions & 82 deletions plugin.xml
@@ -1,18 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resource_file type="PackedScene" subresource_count="4" version="1.0" version_name="Godot Engine v1.0.stable.custom_build">
<resource_file type="PackedScene" subresource_count="4" version="1.1" version_name="Godot Engine v1.1.rc2.custom_build">
<ext_resource path="import.gd" type="Script"></ext_resource>
<resource type="GDScript" path="local://1">
<string name="script/source"> "tool&#000a;extends Button&#000a;&#000a;func _on_Button_pressed():&#000a;&#0009;var _filedialog = get_child(0)&#000a;&#0009;_filedialog.set_current_path(&quot;&quot;)&#000a;&#0009;_filedialog.set_current_path(&quot;res://&quot;)&#000a;&#0009;_filedialog.show()&#000a;" </string>
<string name="script/source"> "tool&#000a;extends Button&#000a;&#000a;func _on_Button_pressed():&#000a;&#0009;var _filedialog = get_node(&quot;FileDialog&quot;)&#000a;&#0009;#_filedialog.set_current_path(&quot;&quot;)&#000a;&#0009;_filedialog.set_current_path(&quot;res://&quot;)&#000a;&#0009;_filedialog.show()&#000a;" </string>

</resource>
<resource type="GDScript" path="local://2">
<string name="script/source"> "tool&#000a;extends FileDialog&#000a;&#000a;func _ready():&#000a;&#0009;add_filter(&quot;*.json&quot;)&#000a;&#0009;set_mode(MODE_OPEN_FILE)&#000a;&#0009;#set_access(ACCESS_FILESYSTEM)&#000a;&#0009;hide()&#000a;&#000a;func _on_CheckBox_toggled( pressed ):&#000a;&#0009;if (pressed):&#000a;&#0009;&#0009;set_access(ACCESS_FILESYSTEM)&#000a;&#0009;else:&#000a;&#0009;&#0009;set_access(ACCESS_RESOURCES)" </string>
<string name="script/source"> "tool&#000a;extends FileDialog&#000a;&#000a;func _ready():&#000a;&#0009;add_filter(&quot;*.json&quot;)&#000a;&#0009;set_mode(MODE_OPEN_FILE)&#000a;&#0009;hide()&#000a;&#000a;func _on_CheckBox_toggled( pressed ):&#000a;&#0009;if (pressed):&#000a;&#0009;&#0009;set_access(ACCESS_FILESYSTEM)&#000a;&#0009;else:&#000a;&#0009;&#0009;set_access(ACCESS_RESOURCES)" </string>

</resource>
<main_resource>
<dictionary name="_bundled" shared="false">
<string> "conn_count" </string>
<int> 4 </int>
<string> "conns" </string>
<int_array len="24"> 2, 2, 48, 47, 2, 0, 3, 6, 50, 49, 2, 0, 4, 3, 52, 51, 2, 0, 5, 6, 48, 47, 2, 0 </int_array>
<string> "names" </string>
<string_array len="51">
<string_array len="53">
<string> "WindowDialog" </string>
<string> "_import_path" </string>
<string> "visibility/visible" </string>
Expand Down Expand Up @@ -58,21 +62,21 @@
<string> "import" </string>
<string> "anchor/top" </string>
<string> "EditorPlugin" </string>
<string> "ErrorPopup" </string>
<string> "AcceptDialog" </string>
<string> "_on_Button_pressed" </string>
<string> "pressed" </string>
<string> "_on_FileDialog_file_selected" </string>
<string> "file_selected" </string>
<string> "_on_CheckBox_toggled" </string>
<string> "toggled" </string>
</string_array>
<string> "version" </string>
<int> 1 </int>
<string> "conn_count" </string>
<int> 4 </int>
<string> "node_count" </string>
<int> 7 </int>
<int> 8 </int>
<string> "nodes" </string>
<int_array len="394"> -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 </int_array>
<string> "variants" </string>
<array len="33" shared="false">
<array len="38" shared="false">
<node_path> "" </node_path>
<bool> True </bool>
<real> 1 </real>
Expand All @@ -85,134 +89,137 @@
<int> 2 </int>
<string> "Tiled Importer" </string>
<dictionary shared="false">
<string> "__editor_plugin_screen__" </string>
<string> "Script" </string>
<string> "__editor_plugin_states__" </string>
<dictionary shared="false">
<string> "Script" </string>
<dictionary shared="false">
<string> "current" </string>
<int> 0 </int>
<string> "sources" </string>
<array len="2" shared="false">
<string> "import.gd" </string>
<node_path> "/root/EditorNode/@Panel3/@VBoxContainer6/@HSplitContainer8/@VSplitContainer9/@VSplitContainer10/@VBoxContainer11/@Panel16/@Control18/@CanvasItemEditor5886/@VSplitContainer5811/@HSplitContainer5812/@Control5813/@Control5814/@Viewport5815/WindowDialog/chooseFile/FileDialog" </node_path>
</array>
</dictionary>
<string> "2D" </string>
<dictionary shared="false">
<string> "ofs" </string>
<vector2> -162.516, -77.3002 </vector2>
<string> "snap_grid" </string>
<bool> False </bool>
<string> "snap_offset" </string>
<vector2> 0, 0 </vector2>
<string> "snap_pixel" </string>
<bool> False </bool>
<string> "snap_rotation_step" </string>
<real> 0.261799 </real>
<string> "zoom" </string>
<real> 2.272075 </real>
<string> "snap_step" </string>
<vector2> 10, 10 </vector2>
<string> "snap_relative" </string>
<bool> False </bool>
<string> "snap_grid" </string>
<string> "snap_rotation" </string>
<bool> False </bool>
<string> "snap_rotation_offset" </string>
<real> 0 </real>
<string> "snap_rotation_step" </string>
<real> 0.261799 </real>
<string> "snap_show_grid" </string>
<bool> False </bool>
<string> "snap_offset" </string>
<vector2> 0, 0 </vector2>
<string> "ofs" </string>
<vector2> 24.8278, 9.11441 </vector2>
<string> "snap_rotation" </string>
<bool> False </bool>
<string> "snap_step" </string>
<vector2> 10, 10 </vector2>
<string> "zoom" </string>
<real> 1.507341 </real>
</dictionary>
<string> "3D" </string>
<dictionary shared="false">
<string> "ambient_light_color" </string>
<color> 0.15, 0.15, 0.15, 1 </color>
<string> "default_light" </string>
<bool> True </bool>
<string> "default_srgb" </string>
<bool> False </bool>
<string> "deflight_rot_x" </string>
<real> 0.942478 </real>
<string> "deflight_rot_y" </string>
<real> 0.628319 </real>
<string> "zfar" </string>
<real> 500 </real>
<string> "fov" </string>
<real> 45 </real>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "viewport_mode" </string>
<int> 1 </int>
<string> "viewports" </string>
<array len="4" shared="false">
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
<string> "listener" </string>
<bool> True </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
<dictionary shared="false">
<string> "distance" </string>
<real> 4 </real>
<string> "listener" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "use_environment" </string>
<bool> False </bool>
<string> "use_orthogonal" </string>
<bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
<string> "x_rot" </string>
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
</dictionary>
</array>
<string> "viewport_mode" </string>
<int> 1 </int>
<string> "default_light" </string>
<bool> True </bool>
<string> "ambient_light_color" </string>
<color> 0.15, 0.15, 0.15, 1 </color>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "zfar" </string>
<real> 500 </real>
<string> "znear" </string>
<real> 0.1 </real>
<string> "default_srgb" </string>
<bool> False </bool>
<string> "deflight_rot_x" </string>
<real> 0.942478 </real>
</dictionary>
<string> "Script" </string>
<dictionary shared="false">
<string> "current" </string>
<int> 0 </int>
<string> "sources" </string>
<array len="3" shared="false">
<string> "import.gd" </string>
<node_path> "/root/EditorNode/@Panel4/@VBoxContainer7/@HSplitContainer9/@VSplitContainer10/@VSplitContainer11/@VBoxContainer12/@Panel17/@Control19/@CanvasItemEditor5885/@VSplitContainer5810/@HSplitContainer5811/@Control5812/@Control5813/@Viewport5814/WindowDialog/chooseFile" </node_path>
<node_path> "/root/EditorNode/@Panel4/@VBoxContainer7/@HSplitContainer9/@VSplitContainer10/@VSplitContainer11/@VBoxContainer12/@Panel17/@Control19/@CanvasItemEditor5885/@VSplitContainer5810/@HSplitContainer5811/@Control5812/@Control5813/@Viewport5814/WindowDialog/chooseFile/FileDialog" </node_path>
</array>
</dictionary>
</dictionary>
<string> "__editor_run_settings__" </string>
Expand All @@ -222,8 +229,6 @@
<string> "run_mode" </string>
<int> 0 </int>
</dictionary>
<string> "__editor_plugin_screen__" </string>
<string> "2D" </string>
</dictionary>
<int> 3 </int>
<real> 40 </real>
Expand All @@ -233,9 +238,9 @@
<string> "Choose File" </string>
<resource name=""></resource> <resource resource_type="Script" path="local://1"> </resource>
<real> 181 </real>
<real> 43 </real>
<real> 44 </real>
<real> 530 </real>
<real> 551 </real>
<real> 552 </real>
<color> 0.0784314, 0.0784314, 0.0784314, 1 </color>
<string> "Open a File" </string>
<resource resource_type="Script" path="local://2"> </resource>
Expand All @@ -245,12 +250,15 @@
<int> 0 </int>
<string> "Import map" </string>
<resource resource_type="Script" path="import.gd"> </resource>
<real> 126 </real>
<real> 180 </real>
<real> 573 </real>
<real> 282 </real>
<string> "Alert!" </string>
</array>
<string> "nodes" </string>
<int_array len="347"> -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 </int_array>
<string> "conns" </string>
<int_array len="24"> 2, 2, 46, 45, 2, 0, 3, 6, 48, 47, 2, 0, 4, 3, 50, 49, 2, 0, 5, 6, 46, 45, 2, 0 </int_array>
<string> "version" </string>
<int> 1 </int>
</dictionary>

</main_resource>
</resource_file>
</resource_file>

0 comments on commit 5175638

Please sign in to comment.