Skip to content

Commit

Permalink
updated icon,
Browse files Browse the repository at this point in the history
reworked tileset tool scripts
  • Loading branch information
geegaz committed Feb 10, 2022
1 parent 07f34b3 commit e1d7a97
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 225 deletions.
11 changes: 4 additions & 7 deletions Addons/SimpleTools/TileSets/AutomatedTiles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ extends "./ConnectingTiles.gd"
tool

export(bool) var create_shapes: bool = true setget set_create_shape
export(Array, String) var automated_tiles_names = [] setget set_automated_tiles_names

var automated = []

enum {SUCCESS, ERROR}

func set_create_shape(_new_state: bool):
func set_create_shape(_state: bool):
if !Engine.editor_hint:
# Skip function if not in the editor
return


automated = find_tiles_by_names(rules.get("automated"))

var result: int = create_collisions()
match result:
SUCCESS:
Expand All @@ -22,10 +23,6 @@ func set_create_shape(_new_state: bool):
create_shapes = false
print("Error while creating shapes")

func set_automated_tiles_names(new_array: Array):
automated = find_tiles_by_names(new_array)
automated_tiles_names = new_array

func create_collisions()->int:
for tile in automated:
var new_shape = ConvexPolygonShape2D.new()
Expand Down
37 changes: 26 additions & 11 deletions Addons/SimpleTools/TileSets/ConnectingTiles.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
extends TileSet
tool

export(Array, String) var connecting_tiles_names = [] setget set_connecting_tiles_names
export(Array, String) var sticking_tiles_names = [] setget set_excluding_tiles_names
export(String, FILE, "*.json") var rules_file setget load_rules_file
var rules: Dictionary

#export(Array, String) var connecting_tiles_names = [] setget set_connecting_tiles_names
#export(Array, String) var sticky_tiles_names = [] setget set_excluding_tiles_names

var connecting = []
var sticking = []
var sticky = []

func _is_tile_bound(drawn_id, neighbor_id):
# Logic: a tile in the "connecting" group will connect to any other tile in the group
if drawn_id in connecting and (neighbor_id in connecting or neighbor_id in sticking):
return true
return drawn_id in connecting and (neighbor_id in connecting or neighbor_id in sticky)

func find_tiles_by_names(names: Array)->Array:
var new_array = []
Expand All @@ -20,11 +22,24 @@ func find_tiles_by_names(names: Array)->Array:
new_array.append(id)
return new_array

func set_connecting_tiles_names(new_array: Array):
connecting = find_tiles_by_names(new_array)
connecting_tiles_names = new_array
#func set_connecting_tiles_names(new_array: Array):
# connecting = find_tiles_by_names(new_array)
# connecting_tiles_names = new_array
#
#func set_excluding_tiles_names(new_array: Array):
# sticky = find_tiles_by_names(new_array)
# sticky_tiles_names = new_array

func set_excluding_tiles_names(new_array: Array):
sticking = find_tiles_by_names(new_array)
sticking_tiles_names = new_array
func load_rules_file(path: String):
var file: File = File.new()
file.open(path, File.READ)
var json: JSONParseResult = JSON.parse(file.get_as_text())

if json.error == OK:
rules = json.result
connecting = find_tiles_by_names(rules.get("connecting"))
sticky = find_tiles_by_names(rules.get("sticky"))

rules_file = path


4 changes: 1 addition & 3 deletions Assets/Tilesets/background.tres
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[ext_resource path="res://Addons/SimpleTools/TileSets/ConnectingTiles.gd" type="Script" id=1]
[ext_resource path="res://Assets/Sprites/tilesets/background_tiles.png" type="Texture" id=2]


[resource]
0/name = "background_rock"
0/texture = ExtResource( 2 )
Expand Down Expand Up @@ -66,5 +65,4 @@
2/shapes = [ ]
2/z_index = 0
script = ExtResource( 1 )
connecting_tiles_names = [ "background_rock" ]
sticking_tiles_names = [ "background_metal" ]
rules_file = "res://Assets/Tilesets/background_rules.json"
9 changes: 9 additions & 0 deletions Assets/Tilesets/background_rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"connecting": [
"background_rock",
"background_fill"
],
"sticky": [
"background_metal"
]
}
Loading

0 comments on commit e1d7a97

Please sign in to comment.