robustness of tileset related functionality
This commit is contained in:
parent
ec1c99ebb4
commit
85be2f7063
@ -1,6 +1,6 @@
|
|||||||
tool
|
tool
|
||||||
extends TK_Context
|
extends TK_Context
|
||||||
class_name TK_GridContext
|
class_name n_parent
|
||||||
|
|
||||||
## todo: Cell visualization.
|
## todo: Cell visualization.
|
||||||
## todo: Integration of TileMap.
|
## todo: Integration of TileMap.
|
||||||
@ -30,7 +30,8 @@ func try_moving(p_game_object: Node2D, p_from: Vector2, p_to: Vector2) -> bool:
|
|||||||
|
|
||||||
func register_collider(p_collider: Node) -> void:
|
func register_collider(p_collider: Node) -> void:
|
||||||
_colliders[p_collider] = null
|
_colliders[p_collider] = null
|
||||||
if p_collider.connect("child_exiting_tree", self, "_on_collider_exiting_tree") != OK:
|
if not p_collider.is_connected("child_exiting_tree", self, "_on_collider_exiting_tree") and \
|
||||||
|
p_collider.connect("child_exiting_tree", self, "_on_collider_exiting_tree") != OK:
|
||||||
assert(false)
|
assert(false)
|
||||||
|
|
||||||
func _on_collider_exiting_tree(p_collider) -> void:
|
func _on_collider_exiting_tree(p_collider) -> void:
|
||||||
|
@ -2,10 +2,13 @@ tool
|
|||||||
extends TileMap
|
extends TileMap
|
||||||
|
|
||||||
# todo: Give care about descriptor swaps being loseless / non introducing artifacts.
|
# todo: Give care about descriptor swaps being loseless / non introducing artifacts.
|
||||||
|
# todo: Prevent user from deleting or editing tile_set property.
|
||||||
|
|
||||||
|
# todo: Update it when changed.
|
||||||
## Dictates whether tileset collision information should be exposed to game context.
|
## Dictates whether tileset collision information should be exposed to game context.
|
||||||
export var expose_collisions: bool = true
|
export var expose_collisions: bool = true
|
||||||
|
|
||||||
|
# todo: Use Node identity instead of name.
|
||||||
var _descriptor_name_to_id: Dictionary # String to int
|
var _descriptor_name_to_id: Dictionary # String to int
|
||||||
var _id_to_descriptor_name: Dictionary # int to String
|
var _id_to_descriptor_name: Dictionary # int to String
|
||||||
|
|
||||||
@ -29,16 +32,26 @@ func is_path_traversible(p_game_object: Node2D, p_from: Vector2, p_to: Vector2)
|
|||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
tile_set = TileSet.new()
|
tile_set = TileSet.new()
|
||||||
get_parent().register_collider(self)
|
|
||||||
|
var n_parent := get_parent()
|
||||||
|
if not n_parent is TK_Context:
|
||||||
|
return
|
||||||
|
|
||||||
|
n_parent.register_collider(self)
|
||||||
|
|
||||||
# It's okay to fail here for non-grid contexts.
|
# It's okay to fail here for non-grid contexts.
|
||||||
if get_parent().connect("cell_size_changed", self, "_update_cell_size"):
|
if not n_parent.is_connected("cell_size_changed", self, "_update_cell_size") and \
|
||||||
_update_cell_size(get_parent().cell_size, get_parent().cell_size)
|
n_parent.connect("cell_size_changed", self, "_update_cell_size") != OK:
|
||||||
|
|
||||||
if connect("child_entered_tree", self, "_on_child_entered_tree") != OK:
|
|
||||||
assert(false)
|
assert(false)
|
||||||
|
|
||||||
if connect("child_exiting_tree", self, "_on_child_exiting_tree") != OK:
|
_update_cell_size(n_parent.cell_size, n_parent.cell_size)
|
||||||
|
|
||||||
|
if not is_connected("child_entered_tree", self, "_on_child_entered_tree") and \
|
||||||
|
connect("child_entered_tree", self, "_on_child_entered_tree") != OK:
|
||||||
|
assert(false)
|
||||||
|
|
||||||
|
if not is_connected("child_exiting_tree", self, "_on_child_exiting_tree") and \
|
||||||
|
connect("child_exiting_tree", self, "_on_child_exiting_tree") != OK:
|
||||||
assert(false)
|
assert(false)
|
||||||
|
|
||||||
func _update_cell_size(_p_old_cell_size: Vector2, p_new_cell_size: Vector2) -> void:
|
func _update_cell_size(_p_old_cell_size: Vector2, p_new_cell_size: Vector2) -> void:
|
||||||
@ -56,11 +69,13 @@ func _on_child_entered_tree(p_node: Node) -> void:
|
|||||||
_id_to_descriptor_name[id] = p_node.name
|
_id_to_descriptor_name[id] = p_node.name
|
||||||
tile_set.create_tile(id)
|
tile_set.create_tile(id)
|
||||||
tile_set.tile_set_texture(id, p_node.texture)
|
tile_set.tile_set_texture(id, p_node.texture)
|
||||||
|
if not p_node.id.empty():
|
||||||
|
tile_set.tile_set_name(id, p_node.id)
|
||||||
|
|
||||||
func _on_child_exiting_tree(p_node: Node) -> void:
|
func _on_child_exiting_tree(p_node: Node) -> void:
|
||||||
var id := _descriptor_name_to_id[p_node.name] as int
|
var id := _descriptor_name_to_id[p_node.name] as int
|
||||||
for cell in get_used_cells_by_id(id):
|
for cell in get_used_cells_by_id(id):
|
||||||
set_cell(cell.x, cell.y, -1)
|
set_cellv(cell, -1)
|
||||||
tile_set.remove_tile(id)
|
tile_set.remove_tile(id)
|
||||||
if not _descriptor_name_to_id.erase(p_node.name):
|
if not _descriptor_name_to_id.erase(p_node.name):
|
||||||
assert(false)
|
assert(false)
|
||||||
|
@ -7,6 +7,10 @@ export var texture: Texture setget _set_texture
|
|||||||
# todo: More layer customizeability.
|
# todo: More layer customizeability.
|
||||||
export var is_solid: bool
|
export var is_solid: bool
|
||||||
|
|
||||||
|
# todo: Update TileMapObject in editor when it's changed.
|
||||||
|
export var id: String = ""
|
||||||
|
|
||||||
|
# todo: Should work for non-grid objects.
|
||||||
func is_traversible_for(_p_game_object: Node2D) -> bool:
|
func is_traversible_for(_p_game_object: Node2D) -> bool:
|
||||||
return not is_solid
|
return not is_solid
|
||||||
|
|
||||||
|
@ -134,15 +134,15 @@ _global_script_classes=[ {
|
|||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://nodes/GameObject.gd"
|
"path": "res://nodes/GameObject.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "TK_Context",
|
|
||||||
"class": "TK_GridContext",
|
|
||||||
"language": "GDScript",
|
|
||||||
"path": "res://nodes/GridContext.gd"
|
|
||||||
}, {
|
|
||||||
"base": "Node",
|
"base": "Node",
|
||||||
"class": "TK_TileMapTileDescriptor",
|
"class": "TK_TileMapTileDescriptor",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://nodes/TileMapTileDescriptor.gd"
|
"path": "res://nodes/TileMapTileDescriptor.gd"
|
||||||
|
}, {
|
||||||
|
"base": "TK_Context",
|
||||||
|
"class": "n_parent",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://nodes/GridContext.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"BrushPrefabs": "",
|
"BrushPrefabs": "",
|
||||||
@ -170,14 +170,15 @@ _global_script_class_icons={
|
|||||||
"TK_Controller": "",
|
"TK_Controller": "",
|
||||||
"TK_FittingSprite": "",
|
"TK_FittingSprite": "",
|
||||||
"TK_GameObject": "",
|
"TK_GameObject": "",
|
||||||
"TK_GridContext": "",
|
"TK_TileMapTileDescriptor": "",
|
||||||
"TK_TileMapTileDescriptor": ""
|
"n_parent": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="TochieKit"
|
config/name="TochieKit"
|
||||||
run/main_scene="res://scenes/Game.tscn"
|
run/main_scene="res://scenes/Game.tscn"
|
||||||
|
run/low_processor_mode=true
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
[autoload]
|
[autoload]
|
||||||
@ -226,6 +227,15 @@ move_left={
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[input_devices]
|
||||||
|
|
||||||
|
buffering/agile_event_flushing=true
|
||||||
|
pointing/emulate_touch_from_mouse=true
|
||||||
|
|
||||||
|
[node]
|
||||||
|
|
||||||
|
name_num_separator=3
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
common/enable_pause_aware_picking=true
|
common/enable_pause_aware_picking=true
|
||||||
@ -233,8 +243,18 @@ common/enable_pause_aware_picking=true
|
|||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
quality/driver/driver_name="GLES2"
|
quality/driver/driver_name="GLES2"
|
||||||
|
quality/intended_usage/framebuffer_allocation=1
|
||||||
|
quality/intended_usage/framebuffer_allocation.mobile=1
|
||||||
2d/snapping/use_gpu_pixel_snap=true
|
2d/snapping/use_gpu_pixel_snap=true
|
||||||
|
threads/thread_model=2
|
||||||
vram_compression/import_etc=true
|
vram_compression/import_etc=true
|
||||||
vram_compression/import_etc2=false
|
vram_compression/import_etc2=false
|
||||||
|
quality/reflections/texture_array_reflections=false
|
||||||
|
quality/shading/force_vertex_shading=true
|
||||||
|
quality/shading/force_lambert_over_burley=true
|
||||||
|
quality/shading/force_blinn_over_ggx=true
|
||||||
|
quality/filters/use_nearest_mipmap_filter=true
|
||||||
|
batching/options/single_rect_fallback=true
|
||||||
|
quality/lightmapping/use_bicubic_sampling=false
|
||||||
environment/default_clear_color=Color( 0.00784314, 0, 0.117647, 1 )
|
environment/default_clear_color=Color( 0.00784314, 0, 0.117647, 1 )
|
||||||
environment/default_environment="res://default_env.tres"
|
environment/default_environment="res://default_env.tres"
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
[ext_resource path="res://nodes/GridContext.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://nodes/GridContext.tscn" type="PackedScene" id=4]
|
||||||
[ext_resource path="res://nodes/GameObject.tscn" type="PackedScene" id=5]
|
[ext_resource path="res://nodes/GameObject.tscn" type="PackedScene" id=5]
|
||||||
[ext_resource path="res://art/tiles/brickwall.png" type="Texture" id=6]
|
[ext_resource path="res://art/tiles/brickwall.png" type="Texture" id=6]
|
||||||
[ext_resource path="res://nodes/TileMapObject.gd" type="Script" id=7]
|
[ext_resource path="res://nodes/TileMapObject.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://scenes/tiles/Brickwall.tscn" type="PackedScene" id=8]
|
[ext_resource path="res://scenes/tiles/Brickwall.tscn" type="PackedScene" id=8]
|
||||||
|
|
||||||
[sub_resource type="TileSet" id=1]
|
[sub_resource type="TileSet" id=1]
|
||||||
0/name = ""
|
0/name = "tk.Brickwall"
|
||||||
0/texture = ExtResource( 6 )
|
0/texture = ExtResource( 6 )
|
||||||
0/tex_offset = Vector2( 0, 0 )
|
0/tex_offset = Vector2( 0, 0 )
|
||||||
0/modulate = Color( 1, 1, 1, 1 )
|
0/modulate = Color( 1, 1, 1, 1 )
|
||||||
@ -29,14 +29,11 @@
|
|||||||
|
|
||||||
[node name="GridContext" parent="." instance=ExtResource( 4 )]
|
[node name="GridContext" parent="." instance=ExtResource( 4 )]
|
||||||
|
|
||||||
[node name="TileMapObject" type="TileMap" parent="GridContext"]
|
[node name="TileMapObject" parent="GridContext" instance=ExtResource( 7 )]
|
||||||
scale = Vector2( 4, 4 )
|
scale = Vector2( 4, 4 )
|
||||||
tile_set = SubResource( 1 )
|
tile_set = SubResource( 1 )
|
||||||
cell_size = Vector2( 16, 16 )
|
cell_size = Vector2( 16, 16 )
|
||||||
bake_navigation = true
|
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 65536, 0, 0, 65551, 0, 0, 131072, 0, 0, 131087, 0, 0, 196608, 0, 0, 196623, 0, 0, 262144, 0, 0, 262159, 0, 0, 327680, 0, 0, 327695, 0, 0, 393216, 0, 0, 393231, 0, 0, 458752, 0, 0, 458767, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524302, 0, 0, 524303, 0, 0 )
|
||||||
format = 1
|
|
||||||
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 65536, 0, 0, 65551, 0, 0, 131072, 0, 0, 131074, 0, 0, 131085, 0, 0, 131087, 0, 0, 196608, 0, 0, 196623, 0, 0, 262144, 0, 0, 262146, 0, 0, 262157, 0, 0, 262159, 0, 0, 327680, 0, 0, 327695, 0, 0, 393216, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 393229, 0, 0, 393231, 0, 0, 458752, 0, 0, 458767, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524302, 0, 0, 524303, 0, 0 )
|
|
||||||
script = ExtResource( 7 )
|
|
||||||
|
|
||||||
[node name="Brickwall" parent="GridContext/TileMapObject" instance=ExtResource( 8 )]
|
[node name="Brickwall" parent="GridContext/TileMapObject" instance=ExtResource( 8 )]
|
||||||
|
|
||||||
|
@ -7,3 +7,4 @@
|
|||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
texture = ExtResource( 1 )
|
texture = ExtResource( 1 )
|
||||||
is_solid = true
|
is_solid = true
|
||||||
|
id = "tk.Brickwall"
|
||||||
|
Loading…
Reference in New Issue
Block a user