new player art
This commit is contained in:
parent
562a33bd8e
commit
f774f8e8a4
65 changed files with 2953 additions and 276 deletions
74
addons/TileMapDual/atlas_watcher.gd
Normal file
74
addons/TileMapDual/atlas_watcher.gd
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
class_name AtlasWatcher
|
||||||
|
##[br] Watches a TileSetAtlasSource for changes.
|
||||||
|
##[br] Causes its 'parent' TileSetWatcher to emit terrains_changed when the atlas changes.
|
||||||
|
##[br] Also emits parent.atlas_autotiled when it thinks the user auto-generated atlas tiles.
|
||||||
|
|
||||||
|
## Prevents the number of seen atlases from extending to infinity.
|
||||||
|
const UNDO_LIMIT = 1024
|
||||||
|
|
||||||
|
## Stores all of the atlas instance id's that have been seen before, to prevent autogen on redo.
|
||||||
|
static var _registered_atlases: Array[int] = []
|
||||||
|
|
||||||
|
## The TileSetWatcher that created this AtlasWatcher. Used to send signals back.
|
||||||
|
var parent: TileSetWatcher
|
||||||
|
## The Source ID of `self.atlas`.
|
||||||
|
var sid: int
|
||||||
|
## The atlas to be watched for changes.
|
||||||
|
var atlas: TileSetAtlasSource
|
||||||
|
|
||||||
|
|
||||||
|
func _init(parent: TileSetWatcher, sid: int, atlas: TileSetAtlasSource) -> void:
|
||||||
|
self.parent = parent
|
||||||
|
self.sid = sid
|
||||||
|
self.atlas = atlas
|
||||||
|
atlas.changed.connect(_atlas_changed, ConnectFlags.CONNECT_DEFERRED)
|
||||||
|
var id: int = atlas.get_instance_id()
|
||||||
|
# should not autogen if atlas was created through redo, i.e. its instance id already existed
|
||||||
|
if _atlas_is_empty() and id not in _registered_atlases:
|
||||||
|
_registered_atlases.push_back(id)
|
||||||
|
if _registered_atlases.size() > UNDO_LIMIT:
|
||||||
|
_registered_atlases.pop_front()
|
||||||
|
atlas.changed.connect(
|
||||||
|
_detect_autogen,
|
||||||
|
ConnectFlags.CONNECT_DEFERRED | ConnectFlags.CONNECT_ONE_SHOT,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _atlas_is_empty() -> bool:
|
||||||
|
return atlas.get_tiles_count() == 0
|
||||||
|
|
||||||
|
|
||||||
|
## Returns true if the texture has any opaque pixels in the specified tile coordinates.
|
||||||
|
func _is_opaque_tile(image: Image, tile: Vector2i, p_threshold: float = 0.1) -> bool:
|
||||||
|
# We cannot use atlas.get_tile_texture_region(tile) as it fails on unregistered tiles.
|
||||||
|
var region := Rect2i(tile * atlas.texture_region_size, atlas.texture_region_size)
|
||||||
|
var sprite: Image = image.get_region(region)
|
||||||
|
if sprite.is_invisible():
|
||||||
|
return false
|
||||||
|
# We're still not sure if the tile is empty or not.
|
||||||
|
# Godot's auto-gen considers 0.1 opacity as "transparent" but not "invisible".
|
||||||
|
for y in range(region.position.y, region.end.y):
|
||||||
|
for x in range(region.position.x, region.end.x):
|
||||||
|
if image.get_pixel(x, y).a > p_threshold:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
##[br] HACK: literally just tries to guess which tiles the terrain autogen system would make
|
||||||
|
##[br] Called once, and only once, at the end of the first frame that a texture is created.
|
||||||
|
func _detect_autogen() -> void:
|
||||||
|
var size := Vector2i(atlas.texture.get_size()) / atlas.texture_region_size
|
||||||
|
var image: Image = atlas.texture.get_image()
|
||||||
|
# NOTE: Literally useless
|
||||||
|
# var expected_tiles := []
|
||||||
|
for y in size.y:
|
||||||
|
for x in size.x:
|
||||||
|
var tile := Vector2i(x, y)
|
||||||
|
if atlas.has_tile(tile) != _is_opaque_tile(image, tile):
|
||||||
|
return
|
||||||
|
parent.atlas_autotiled.emit(sid, atlas)
|
||||||
|
|
||||||
|
|
||||||
|
## Called every time the atlas changes. Simply flags that terrains have changed.
|
||||||
|
func _atlas_changed() -> void:
|
||||||
|
parent._flag_terrains_changed = true
|
||||||
1
addons/TileMapDual/atlas_watcher.gd.uid
Normal file
1
addons/TileMapDual/atlas_watcher.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cfhiw77a85x8w
|
||||||
41
addons/TileMapDual/cursor_dual.gd
Normal file
41
addons/TileMapDual/cursor_dual.gd
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
@icon('cursor_dual.svg')
|
||||||
|
class_name CursorDual
|
||||||
|
extends Sprite2D
|
||||||
|
|
||||||
|
# TODO: instead of setting the target tilemap manually,
|
||||||
|
# just add the CursorDual as a child of the target tilemap
|
||||||
|
@export var tilemap_dual: TileMapDual = null
|
||||||
|
|
||||||
|
var cell: Vector2i
|
||||||
|
var tile_size: Vector2
|
||||||
|
var sprite_size: Vector2
|
||||||
|
var terrain: int = 1
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if tilemap_dual != null:
|
||||||
|
tile_size = tilemap_dual.tile_set.tile_size
|
||||||
|
sprite_size = self.texture.get_size()
|
||||||
|
scale = Vector2(tile_size.y, tile_size.y) / sprite_size
|
||||||
|
self.set_scale(scale)
|
||||||
|
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
if tilemap_dual == null:
|
||||||
|
return
|
||||||
|
cell = tilemap_dual.local_to_map(tilemap_dual.get_local_mouse_position())
|
||||||
|
global_position = tilemap_dual.to_global(tilemap_dual.map_to_local(cell))
|
||||||
|
# Clicking the 1 key activates the first terrain
|
||||||
|
if Input.is_action_pressed("quick_action_1"):
|
||||||
|
terrain = 1
|
||||||
|
# Clicking the 2 key activates the second terrain
|
||||||
|
if Input.is_action_pressed("quick_action_2"):
|
||||||
|
terrain = 2
|
||||||
|
# Clicking the 0 key activates the background terrain
|
||||||
|
if Input.is_action_pressed("quick_action_0"):
|
||||||
|
terrain = 0
|
||||||
|
|
||||||
|
if Input.is_action_pressed("left_click"):
|
||||||
|
tilemap_dual.draw_cell(cell, terrain)
|
||||||
|
elif Input.is_action_pressed("right_click"):
|
||||||
|
tilemap_dual.draw_cell(cell, 0)
|
||||||
1
addons/TileMapDual/cursor_dual.gd.uid
Normal file
1
addons/TileMapDual/cursor_dual.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://c6m630v880okx
|
||||||
49
addons/TileMapDual/cursor_dual.svg
Normal file
49
addons/TileMapDual/cursor_dual.svg
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
width="16"
|
||||||
|
height="16"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
sodipodi:docname="CursorDual.svg"
|
||||||
|
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs1" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#999999"
|
||||||
|
borderopacity="1"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:zoom="35.5"
|
||||||
|
inkscape:cx="9.0845069"
|
||||||
|
inkscape:cy="8.112676"
|
||||||
|
inkscape:window-width="1366"
|
||||||
|
inkscape:window-height="736"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg1" />
|
||||||
|
<path
|
||||||
|
d="M 8.9882813,2.0703125 V 4.046875 h 2.9648437 v 2.9648437 h 1.976563 V 2.0703125 Z"
|
||||||
|
style="fill:#ffb273;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
id="path10" />
|
||||||
|
<path
|
||||||
|
d="m 8.9882813,11.953125 v 1.976563 H 13.929688 V 8.9882813 h -1.976563 v 2.9648437 z"
|
||||||
|
style="fill:#ffb273;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
id="path9" />
|
||||||
|
<path
|
||||||
|
d="M 7.0117187,13.929688 V 11.953125 H 4.046875 V 8.9882813 H 2.0703125 v 4.9414067 z"
|
||||||
|
style="fill:#ffb273;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
id="path8" />
|
||||||
|
<path
|
||||||
|
d="M 2.0703125,7.0117187 H 4.046875 V 4.046875 H 7.0117187 V 2.0703125 H 2.0703125 Z"
|
||||||
|
style="fill:#ffb273;stroke:#000000;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
|
||||||
|
id="path7" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.8 KiB |
44
addons/TileMapDual/cursor_dual.svg.import
Normal file
44
addons/TileMapDual/cursor_dual.svg.import
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bth8306ui4dcx"
|
||||||
|
path="res://.godot/imported/cursor_dual.svg-5d3e91639de0bb1f1616a3d17dccb9e5.ctex"
|
||||||
|
metadata={
|
||||||
|
"has_editor_variant": true,
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/TileMapDual/cursor_dual.svg"
|
||||||
|
dest_files=["res://.godot/imported/cursor_dual.svg-5d3e91639de0bb1f1616a3d17dccb9e5.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=true
|
||||||
|
editor/convert_colors_with_editor_theme=true
|
||||||
164
addons/TileMapDual/display.gd
Normal file
164
addons/TileMapDual/display.gd
Normal file
|
|
@ -0,0 +1,164 @@
|
||||||
|
class_name Display
|
||||||
|
extends Node2D
|
||||||
|
##[br] A Node designed to hold and manage up to 2 DisplayLayer children.
|
||||||
|
##[br] See [DisplayLayer] for details.
|
||||||
|
|
||||||
|
## Emitted when the tiles in the map have been edited.
|
||||||
|
signal world_tiles_changed(changed: Array)
|
||||||
|
|
||||||
|
## Every meaningfully different TileSet.tile_shape * TileSet.tile_offset_axis combination.
|
||||||
|
enum GridShape {
|
||||||
|
SQUARE,
|
||||||
|
ISO,
|
||||||
|
HALF_OFF_HORI,
|
||||||
|
HALF_OFF_VERT,
|
||||||
|
HEX_HORI,
|
||||||
|
HEX_VERT,
|
||||||
|
}
|
||||||
|
|
||||||
|
##[br] How to deal with every available GridShape.
|
||||||
|
##[br] See [DisplayLayer] for more information about these fields.
|
||||||
|
const GRIDS: Dictionary[GridShape, Array] = {
|
||||||
|
GridShape.SQUARE: [
|
||||||
|
{
|
||||||
|
# []
|
||||||
|
'offset': Vector2(-0.5, -0.5),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
GridShape.ISO: [
|
||||||
|
{
|
||||||
|
# <>
|
||||||
|
'offset': Vector2(0, -0.5),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
GridShape.HALF_OFF_HORI: [
|
||||||
|
{
|
||||||
|
# v
|
||||||
|
'offset': Vector2(0.0, -0.5),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# ^
|
||||||
|
'offset': Vector2(-0.5, -0.5),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
GridShape.HALF_OFF_VERT: [
|
||||||
|
{
|
||||||
|
# >
|
||||||
|
'offset': Vector2(-0.5, 0.0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# <
|
||||||
|
'offset': Vector2(-0.5, -0.5),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
GridShape.HEX_HORI: [
|
||||||
|
{
|
||||||
|
# v
|
||||||
|
'offset': Vector2(0.0, -3.0 / 8.0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# ^
|
||||||
|
'offset': Vector2(-0.5, -3.0 / 8.0),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
GridShape.HEX_VERT: [
|
||||||
|
{
|
||||||
|
# >
|
||||||
|
'offset': Vector2(-3.0 / 8.0, 0.0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# <
|
||||||
|
'offset': Vector2(-3.0 / 8.0, -0.5),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
## The parent TileMapDual to base the terrains off of.
|
||||||
|
@export var world: TileMapDual
|
||||||
|
|
||||||
|
## See [TerrainDual]
|
||||||
|
var terrain: TerrainDual
|
||||||
|
## The TileCache computed from the last time update() was called.
|
||||||
|
var cached_cells := TileCache.new()
|
||||||
|
## See [TileSetWatcher]
|
||||||
|
var _tileset_watcher: TileSetWatcher
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: phase out GridShape and simply transpose everything when the offset axis is vertical
|
||||||
|
##[br] Returns what kind of grid a TileSet is.
|
||||||
|
##[br] Will default to SQUARE if Godot decides to add a new TileShape.
|
||||||
|
static func tileset_gridshape(tile_set: TileSet) -> GridShape:
|
||||||
|
var hori: bool = tile_set.tile_offset_axis == TileSet.TILE_OFFSET_AXIS_HORIZONTAL
|
||||||
|
match tile_set.tile_shape:
|
||||||
|
TileSet.TileShape.TILE_SHAPE_SQUARE:
|
||||||
|
return GridShape.SQUARE
|
||||||
|
TileSet.TileShape.TILE_SHAPE_ISOMETRIC:
|
||||||
|
return GridShape.ISO
|
||||||
|
TileSet.TileShape.TILE_SHAPE_HALF_OFFSET_SQUARE:
|
||||||
|
return GridShape.HALF_OFF_HORI if hori else GridShape.HALF_OFF_VERT
|
||||||
|
TileSet.TileShape.TILE_SHAPE_HEXAGON:
|
||||||
|
return GridShape.HEX_HORI if hori else GridShape.HEX_VERT
|
||||||
|
_:
|
||||||
|
return GridShape.SQUARE
|
||||||
|
|
||||||
|
|
||||||
|
## Creates a new Display that updates when the TileSet updates.
|
||||||
|
func _init(world: TileMapDual, tileset_watcher: TileSetWatcher) -> void:
|
||||||
|
#print('initializing Display...')
|
||||||
|
self.world = world
|
||||||
|
_tileset_watcher = tileset_watcher
|
||||||
|
terrain = TerrainDual.new(tileset_watcher)
|
||||||
|
terrain.changed.connect(_terrain_changed, 1)
|
||||||
|
world_tiles_changed.connect(_world_tiles_changed, 1)
|
||||||
|
# let parent materal through to the displaylayers
|
||||||
|
use_parent_material = true
|
||||||
|
# Enable Y sorting
|
||||||
|
y_sort_enabled = true
|
||||||
|
|
||||||
|
|
||||||
|
## Updates the display based on the cells changed in the world TileMapDual.
|
||||||
|
func update(updated: Array) -> void:
|
||||||
|
if _tileset_watcher.tile_set == null:
|
||||||
|
return
|
||||||
|
_update_properties()
|
||||||
|
if not updated.is_empty():
|
||||||
|
cached_cells.update(world, updated)
|
||||||
|
world_tiles_changed.emit(updated)
|
||||||
|
|
||||||
|
|
||||||
|
## Activates when the TerrainDual changes.
|
||||||
|
func _terrain_changed() -> void:
|
||||||
|
cached_cells.update(world)
|
||||||
|
_delete_layers()
|
||||||
|
if _tileset_watcher.tile_set != null:
|
||||||
|
_create_layers()
|
||||||
|
|
||||||
|
|
||||||
|
func _world_tiles_changed(changed: Array) -> void:
|
||||||
|
#print('SIGNAL EMITTED: world_tiles_changed(%s)' % {'changed': changed})
|
||||||
|
for child in get_children(true):
|
||||||
|
child.update_tiles(cached_cells, changed)
|
||||||
|
|
||||||
|
|
||||||
|
## Initializes and configures new DisplayLayers according to the grid shape.
|
||||||
|
func _create_layers() -> void:
|
||||||
|
#print('GRID SHAPE: %s' % _tileset_watcher.grid_shape)
|
||||||
|
var grid: Array = GRIDS[_tileset_watcher.grid_shape]
|
||||||
|
for i: int in grid.size():
|
||||||
|
var layer_config: Dictionary = grid[i]
|
||||||
|
#print('layer_config: %s' % layer_config)
|
||||||
|
var layer := DisplayLayer.new(world, _tileset_watcher, layer_config, terrain.layers[i])
|
||||||
|
add_child(layer)
|
||||||
|
layer.update_tiles_all(cached_cells)
|
||||||
|
|
||||||
|
|
||||||
|
## Deletes all of the DisplayLayers.
|
||||||
|
func _delete_layers() -> void:
|
||||||
|
for child in get_children(true):
|
||||||
|
child.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
## Activates when the properties of the parent TileMapDual have been edited.
|
||||||
|
func _update_properties() -> void:
|
||||||
|
for child in get_children(true):
|
||||||
|
child.update_properties(world)
|
||||||
1
addons/TileMapDual/display.gd.uid
Normal file
1
addons/TileMapDual/display.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cacp8xe0jaxln
|
||||||
104
addons/TileMapDual/display_layer.gd
Normal file
104
addons/TileMapDual/display_layer.gd
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
class_name DisplayLayer
|
||||||
|
extends TileMapLayer
|
||||||
|
##[br] A single TileMapLayer whose purpose is to display tiles to maintain the Dual Grid illusion.
|
||||||
|
##[br] Its contents are automatically computed and updated based on:
|
||||||
|
##[br] - the contents of the parent TileMapDual
|
||||||
|
##[br] - the rules set in its assigned TerrainLayer
|
||||||
|
|
||||||
|
##[br] How much to offset this DisplayLayer relative to the main TileMapDual grid.
|
||||||
|
##[br] This is independent of tile size.
|
||||||
|
var offset: Vector2
|
||||||
|
## See [TileSetWatcher]
|
||||||
|
var _tileset_watcher: TileSetWatcher
|
||||||
|
## See [TerrainDual]
|
||||||
|
var _terrain: TerrainLayer
|
||||||
|
|
||||||
|
|
||||||
|
func _init(
|
||||||
|
world: TileMapDual,
|
||||||
|
tileset_watcher: TileSetWatcher,
|
||||||
|
fields: Dictionary,
|
||||||
|
layer: TerrainLayer,
|
||||||
|
) -> void:
|
||||||
|
#print('initializing Layer...')
|
||||||
|
update_properties(world)
|
||||||
|
offset = fields.offset
|
||||||
|
_tileset_watcher = tileset_watcher
|
||||||
|
_terrain = layer
|
||||||
|
tile_set = tileset_watcher.tile_set
|
||||||
|
tileset_watcher.tileset_resized.connect(reposition, 1)
|
||||||
|
reposition()
|
||||||
|
|
||||||
|
|
||||||
|
## Adjusts the position of this DisplayLayer based on the tile set's tile_size
|
||||||
|
func reposition() -> void:
|
||||||
|
position = offset * Vector2(_tileset_watcher.tile_size)
|
||||||
|
|
||||||
|
|
||||||
|
## Copies properties from parent TileMapDual to child display tilemap
|
||||||
|
func update_properties(parent: TileMapDual) -> void:
|
||||||
|
# Both tilemaps must be the same, so we copy all relevant properties
|
||||||
|
# Tilemap
|
||||||
|
# already covered by parent._tileset_watcher
|
||||||
|
# Rendering
|
||||||
|
self.y_sort_origin = parent.y_sort_origin
|
||||||
|
self.x_draw_order_reversed = parent.x_draw_order_reversed
|
||||||
|
self.rendering_quadrant_size = parent.rendering_quadrant_size
|
||||||
|
# Physics
|
||||||
|
self.collision_enabled = parent.collision_enabled
|
||||||
|
self.use_kinematic_bodies = parent.use_kinematic_bodies
|
||||||
|
self.collision_visibility_mode = parent.collision_visibility_mode
|
||||||
|
# Navigation
|
||||||
|
self.navigation_enabled = parent.navigation_enabled
|
||||||
|
self.navigation_visibility_mode = parent.navigation_visibility_mode
|
||||||
|
# Canvas item properties
|
||||||
|
self.show_behind_parent = parent.show_behind_parent
|
||||||
|
self.top_level = parent.top_level
|
||||||
|
self.light_mask = parent.light_mask
|
||||||
|
self.visibility_layer = parent.visibility_layer
|
||||||
|
self.y_sort_enabled = parent.y_sort_enabled
|
||||||
|
self.modulate = parent.modulate
|
||||||
|
self.self_modulate = parent.self_modulate
|
||||||
|
# NOTE: parent material takes priority over the current shaders,
|
||||||
|
# causing the world tiles to show up
|
||||||
|
self.use_parent_material = parent.use_parent_material
|
||||||
|
|
||||||
|
# Save any manually introduced Material change:
|
||||||
|
self.material = parent.display_material
|
||||||
|
|
||||||
|
|
||||||
|
## Updates all display tiles to reflect the current changes.
|
||||||
|
func update_tiles_all(cache: TileCache) -> void:
|
||||||
|
update_tiles(cache, cache.cells.keys())
|
||||||
|
|
||||||
|
|
||||||
|
## Update all display tiles affected by the world cells
|
||||||
|
func update_tiles(cache: TileCache, updated_world_cells: Array) -> void:
|
||||||
|
#push_warning('updating tiles')
|
||||||
|
var already_updated := Set.new()
|
||||||
|
for path: Array in _terrain.display_to_world_neighborhood:
|
||||||
|
path = path.map(Util.reverse_neighbor)
|
||||||
|
for world_cell: Vector2i in updated_world_cells:
|
||||||
|
var display_cell: Vector2i = follow_path(world_cell, path)
|
||||||
|
if already_updated.insert(display_cell):
|
||||||
|
update_tile(cache, display_cell)
|
||||||
|
|
||||||
|
|
||||||
|
## Updates a specific world cell.
|
||||||
|
func update_tile(cache: TileCache, cell: Vector2i) -> void:
|
||||||
|
var get_cell_at_path: Callable = func(
|
||||||
|
path,
|
||||||
|
):
|
||||||
|
return cache.get_terrain_at(follow_path(cell, path))
|
||||||
|
var terrain_neighbors: Array = _terrain.display_to_world_neighborhood.map(get_cell_at_path)
|
||||||
|
var mapping: Dictionary = _terrain.apply_rule(terrain_neighbors, cell)
|
||||||
|
var sid: int = mapping.sid
|
||||||
|
var tile: Vector2i = mapping.tile
|
||||||
|
set_cell(cell, sid, tile)
|
||||||
|
|
||||||
|
|
||||||
|
## Finds the neighbor of a given cell by following a path of CellNeighbors
|
||||||
|
func follow_path(cell: Vector2i, path: Array) -> Vector2i:
|
||||||
|
for neighbor: TileSet.CellNeighbor in path:
|
||||||
|
cell = get_neighbor_cell(cell, neighbor)
|
||||||
|
return cell
|
||||||
1
addons/TileMapDual/display_layer.gd.uid
Normal file
1
addons/TileMapDual/display_layer.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bon5inags0mqy
|
||||||
6
addons/TileMapDual/ghost.gdshader
Normal file
6
addons/TileMapDual/ghost.gdshader
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// A shader that sets all pixels to 0 alpha, making the object invisible.
|
||||||
|
|
||||||
|
shader_type canvas_item;
|
||||||
|
void fragment() {
|
||||||
|
COLOR = vec4(0);
|
||||||
|
}
|
||||||
1
addons/TileMapDual/ghost.gdshader.uid
Normal file
1
addons/TileMapDual/ghost.gdshader.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://44652e0wv1ve
|
||||||
6
addons/TileMapDual/ghost_material.tres
Normal file
6
addons/TileMapDual/ghost_material.tres
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://cmbcfxlkxxnwq"]
|
||||||
|
|
||||||
|
[ext_resource type="Shader" uid="uid://44652e0wv1ve" path="res://addons/TileMapDual/ghost.gdshader" id="1_gvngp"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
shader = ExtResource("1_gvngp")
|
||||||
7
addons/TileMapDual/plugin.cfg
Normal file
7
addons/TileMapDual/plugin.cfg
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
[plugin]
|
||||||
|
|
||||||
|
name="TileMapDual"
|
||||||
|
description="An automatic, real-time dual-grid tileset system for Godot!"
|
||||||
|
author="@GilaPixel"
|
||||||
|
version="v5.0.2"
|
||||||
|
script="plugin.gd"
|
||||||
78
addons/TileMapDual/plugin.gd
Normal file
78
addons/TileMapDual/plugin.gd
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
@tool
|
||||||
|
class_name TileMapDualEditorPlugin
|
||||||
|
extends EditorPlugin
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: create a message queue that groups warnings, errors, and messages into categories
|
||||||
|
# so that we don't get 300 lines of the same warnings pushed to console every time we undo/redo
|
||||||
|
func _enter_tree() -> void:
|
||||||
|
# register custom nodes
|
||||||
|
const TILE_MAP_DUAL_ICON: Texture2D = preload("tile_map_dual.svg")
|
||||||
|
add_custom_type(
|
||||||
|
"TileMapDual",
|
||||||
|
"TileMapLayer",
|
||||||
|
preload("tile_map_dual.gd"),
|
||||||
|
TILE_MAP_DUAL_ICON,
|
||||||
|
)
|
||||||
|
add_custom_type(
|
||||||
|
"TileMapDualLegacy",
|
||||||
|
"TileMapLayer",
|
||||||
|
preload("tile_map_dual_legacy.gd"),
|
||||||
|
TILE_MAP_DUAL_ICON,
|
||||||
|
)
|
||||||
|
add_custom_type(
|
||||||
|
"CursorDual",
|
||||||
|
"Sprite2D",
|
||||||
|
preload("cursor_dual.gd"),
|
||||||
|
preload("cursor_dual.svg"),
|
||||||
|
)
|
||||||
|
# load editor-only functions
|
||||||
|
TileMapDual.autotile = autotile
|
||||||
|
TileMapDual.popup = popup
|
||||||
|
# finish
|
||||||
|
# print("plugin TileMapDual loaded")
|
||||||
|
|
||||||
|
|
||||||
|
func _exit_tree() -> void:
|
||||||
|
# disable editor-only functions
|
||||||
|
TileMapDual.popup = TileMapDual._editor_only.bind('popup').unbind(2)
|
||||||
|
TileMapDual.autotile = TileMapDual._editor_only.bind('autotile').unbind(3)
|
||||||
|
# remove custom nodes
|
||||||
|
remove_custom_type("TileMapDualLegacy")
|
||||||
|
remove_custom_type("CursorDual")
|
||||||
|
remove_custom_type("TileMapDual")
|
||||||
|
# finish
|
||||||
|
# print("plugin TileMapDual unloaded")
|
||||||
|
|
||||||
|
|
||||||
|
# HACK: functions that reference EditorPlugin, directly or indirectly,
|
||||||
|
# cannot be in the publicly exported scripts
|
||||||
|
# or else they simply won't work when exported
|
||||||
|
## Shows a popup with a title bar, a message,
|
||||||
|
## and an "Ok" button in the middle of the screen.
|
||||||
|
func popup(title: String, message: String) -> void:
|
||||||
|
var popup := AcceptDialog.new()
|
||||||
|
get_editor_interface().get_base_control().add_child(popup)
|
||||||
|
popup.name = 'TileMapDualPopup'
|
||||||
|
popup.title = title
|
||||||
|
popup.dialog_text = message
|
||||||
|
popup.popup_centered()
|
||||||
|
await popup.confirmed
|
||||||
|
popup.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
## Automatically generate terrains when the atlas is initialized.
|
||||||
|
func autotile(_source_id: int, atlas: TileSetAtlasSource, tile_set: TileSet):
|
||||||
|
print_stack()
|
||||||
|
var urm: EditorUndoRedoManager = get_undo_redo()
|
||||||
|
urm.create_action(
|
||||||
|
"Create tiles in non-transparent texture regions",
|
||||||
|
UndoRedo.MergeMode.MERGE_ALL,
|
||||||
|
self,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
# NOTE: commit_action() is called immediately after.
|
||||||
|
# NOTE: Atlas is guaranteed to have only been auto-generated
|
||||||
|
# with no extra peering bit information.
|
||||||
|
TerrainPreset.write_default_preset(urm, tile_set, atlas)
|
||||||
|
urm.commit_action()
|
||||||
1
addons/TileMapDual/plugin.gd.uid
Normal file
1
addons/TileMapDual/plugin.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://xq472thciwj0
|
||||||
78
addons/TileMapDual/set.gd
Normal file
78
addons/TileMapDual/set.gd
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
class_name Set
|
||||||
|
extends Resource
|
||||||
|
##[br] Real sets don't exist yet.
|
||||||
|
##[br] https://github.com/godotengine/godot/pull/94399
|
||||||
|
|
||||||
|
## A dummy value to put in a slot.
|
||||||
|
const DUMMY = null
|
||||||
|
|
||||||
|
## The internal Dictionary that holds this Set's items as keys.
|
||||||
|
var data: Dictionary = { }
|
||||||
|
|
||||||
|
|
||||||
|
func _init(initial_data: Variant = []) -> void:
|
||||||
|
union_in_place(initial_data)
|
||||||
|
|
||||||
|
|
||||||
|
## Returns true if the item exists in this Set.
|
||||||
|
func has(item: Variant) -> bool:
|
||||||
|
return item in data
|
||||||
|
|
||||||
|
|
||||||
|
## Returns true if the item was not previously in the Set.
|
||||||
|
func insert(item: Variant) -> bool:
|
||||||
|
var out := not has(item)
|
||||||
|
data[item] = DUMMY
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
## Returns true if the item was previously in the Set.
|
||||||
|
func remove(item: Variant) -> bool:
|
||||||
|
return data.erase(item)
|
||||||
|
|
||||||
|
|
||||||
|
## Deletes all items in this Set.
|
||||||
|
func clear() -> void:
|
||||||
|
data = { }
|
||||||
|
|
||||||
|
|
||||||
|
## Merges an Array's items or Dict's keys into the Set.
|
||||||
|
func union_in_place(other: Variant):
|
||||||
|
for item in other:
|
||||||
|
insert(item)
|
||||||
|
|
||||||
|
|
||||||
|
## Returns a new Set with the items of both self and other.
|
||||||
|
func union(other: Set) -> Set:
|
||||||
|
var out = self.duplicate()
|
||||||
|
out.union_in_place(other.data)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
## Removes an Array's items or Dict's keys from the Set.
|
||||||
|
func diff_in_place(other: Variant):
|
||||||
|
for item in other:
|
||||||
|
remove(item)
|
||||||
|
|
||||||
|
|
||||||
|
## Returns a new Set with all items in self that are not present in other.
|
||||||
|
func diff(other: Set) -> Set:
|
||||||
|
var out = self.duplicate()
|
||||||
|
out.diff_in_place(other.data)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
## Inserts elements that are in other but not in self, and removes elements found in both.
|
||||||
|
func xor_in_place(other: Variant):
|
||||||
|
for item in other:
|
||||||
|
if has(item):
|
||||||
|
remove(item)
|
||||||
|
else:
|
||||||
|
insert(item)
|
||||||
|
|
||||||
|
|
||||||
|
## Returns a new Set where each item is either in self or other, but not both.
|
||||||
|
func xor(other: Set) -> Set:
|
||||||
|
var out = self.duplicate()
|
||||||
|
out.xor_in_place(other.data)
|
||||||
|
return out
|
||||||
1
addons/TileMapDual/set.gd.uid
Normal file
1
addons/TileMapDual/set.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ds8j47h4vi6gx
|
||||||
196
addons/TileMapDual/terrain_dual.gd
Normal file
196
addons/TileMapDual/terrain_dual.gd
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
class_name TerrainDual
|
||||||
|
extends Resource
|
||||||
|
##[br] Reads a TileSet and dictates which tiles in the display map
|
||||||
|
##[br] match up with its neighbors in the world map
|
||||||
|
|
||||||
|
## A specific neighborhood that the Display tiles will look at.
|
||||||
|
enum Neighborhood {
|
||||||
|
SQUARE,
|
||||||
|
ISOMETRIC,
|
||||||
|
TRIANGLE_HORIZONTAL,
|
||||||
|
TRIANGLE_VERTICAL,
|
||||||
|
}
|
||||||
|
|
||||||
|
## Maps a GridShape to a Neighborhood.
|
||||||
|
const GRID_NEIGHBORHOODS: Dictionary[Display.GridShape, Neighborhood] = {
|
||||||
|
Display.GridShape.SQUARE: Neighborhood.SQUARE,
|
||||||
|
Display.GridShape.ISO: Neighborhood.ISOMETRIC,
|
||||||
|
Display.GridShape.HALF_OFF_HORI: Neighborhood.TRIANGLE_HORIZONTAL,
|
||||||
|
Display.GridShape.HALF_OFF_VERT: Neighborhood.TRIANGLE_VERTICAL,
|
||||||
|
Display.GridShape.HEX_HORI: Neighborhood.TRIANGLE_HORIZONTAL,
|
||||||
|
Display.GridShape.HEX_VERT: Neighborhood.TRIANGLE_VERTICAL,
|
||||||
|
}
|
||||||
|
## Maps a Neighborhood to a set of atlas terrain neighbors.
|
||||||
|
const NEIGHBORHOOD_LAYERS: Dictionary[Neighborhood, Array] = {
|
||||||
|
Neighborhood.SQUARE: [
|
||||||
|
{
|
||||||
|
# []
|
||||||
|
'terrain_neighborhood': [
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_RIGHT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER,
|
||||||
|
],
|
||||||
|
'display_to_world_neighborhood': [
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_LEFT_CORNER],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_SIDE],
|
||||||
|
[TileSet.CELL_NEIGHBOR_LEFT_SIDE],
|
||||||
|
[],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Neighborhood.ISOMETRIC: [
|
||||||
|
{
|
||||||
|
# <>
|
||||||
|
'terrain_neighborhood': [
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_RIGHT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_CORNER,
|
||||||
|
],
|
||||||
|
'display_to_world_neighborhood': [
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_CORNER],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE],
|
||||||
|
[],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
Neighborhood.TRIANGLE_HORIZONTAL: [
|
||||||
|
{
|
||||||
|
# v
|
||||||
|
'terrain_neighborhood': [
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_RIGHT_CORNER,
|
||||||
|
],
|
||||||
|
'display_to_world_neighborhood': [
|
||||||
|
[],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_RIGHT_SIDE],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# ^
|
||||||
|
'terrain_neighborhood': [
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER,
|
||||||
|
],
|
||||||
|
'display_to_world_neighborhood': [
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE],
|
||||||
|
[TileSet.CELL_NEIGHBOR_LEFT_SIDE],
|
||||||
|
[],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
# TODO: this is just TRIANGLE_HORIZONTAL but transposed. this can be refactored.
|
||||||
|
Neighborhood.TRIANGLE_VERTICAL: [
|
||||||
|
{
|
||||||
|
# >
|
||||||
|
'terrain_neighborhood': [
|
||||||
|
TileSet.CELL_NEIGHBOR_RIGHT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_CORNER,
|
||||||
|
],
|
||||||
|
'display_to_world_neighborhood': [
|
||||||
|
[],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE],
|
||||||
|
[TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
# <
|
||||||
|
'terrain_neighborhood': [
|
||||||
|
TileSet.CELL_NEIGHBOR_LEFT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_TOP_RIGHT_CORNER,
|
||||||
|
TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER,
|
||||||
|
],
|
||||||
|
'display_to_world_neighborhood': [
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_LEFT_SIDE],
|
||||||
|
[TileSet.CELL_NEIGHBOR_TOP_SIDE],
|
||||||
|
[],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
## The Neighborhood type of this TerrainDual.
|
||||||
|
var neighborhood: Neighborhood
|
||||||
|
## Maps a terrain type to its sprite as registered in the TerrainDual.
|
||||||
|
var terrains: Dictionary[int, Dictionary]
|
||||||
|
## The TerrainLayers for this TerrainDual.
|
||||||
|
var layers: Array
|
||||||
|
var _tileset_watcher: TileSetWatcher
|
||||||
|
|
||||||
|
|
||||||
|
# Functions are ordered top to bottom in the transformation pipeline
|
||||||
|
## Maps a TileSet to a Neighborhood.
|
||||||
|
static func tileset_neighborhood(tile_set: TileSet) -> Neighborhood:
|
||||||
|
return GRID_NEIGHBORHOODS[Display.tileset_gridshape(tile_set)]
|
||||||
|
|
||||||
|
|
||||||
|
func _init(tileset_watcher: TileSetWatcher) -> void:
|
||||||
|
_tileset_watcher = tileset_watcher
|
||||||
|
_tileset_watcher.terrains_changed.connect(_changed, 1)
|
||||||
|
_changed()
|
||||||
|
|
||||||
|
|
||||||
|
## Create rules for every atlas in a TileSet.
|
||||||
|
func read_tileset(tile_set: TileSet) -> void:
|
||||||
|
terrains = { }
|
||||||
|
layers = []
|
||||||
|
neighborhood = Neighborhood.SQUARE # default
|
||||||
|
if tile_set == null:
|
||||||
|
return
|
||||||
|
neighborhood = tileset_neighborhood(tile_set)
|
||||||
|
layers = NEIGHBORHOOD_LAYERS[neighborhood].map(TerrainLayer.new)
|
||||||
|
for i in tile_set.get_source_count():
|
||||||
|
var sid: int = tile_set.get_source_id(i)
|
||||||
|
var src: TileSetSource = tile_set.get_source(sid)
|
||||||
|
if src is not TileSetAtlasSource:
|
||||||
|
continue
|
||||||
|
read_atlas(src, sid)
|
||||||
|
|
||||||
|
|
||||||
|
## Create rules for every tile in an atlas.
|
||||||
|
func read_atlas(atlas: TileSetAtlasSource, sid: int) -> void:
|
||||||
|
var size = atlas.get_atlas_grid_size()
|
||||||
|
for y in size.y:
|
||||||
|
for x in size.x:
|
||||||
|
var tile := Vector2i(x, y)
|
||||||
|
# Take only existing tiles
|
||||||
|
if not atlas.has_tile(tile):
|
||||||
|
continue
|
||||||
|
read_tile(atlas, sid, tile)
|
||||||
|
|
||||||
|
|
||||||
|
## Add a new rule for a specific tile in an atlas.
|
||||||
|
func read_tile(atlas: TileSetAtlasSource, sid: int, tile: Vector2i) -> void:
|
||||||
|
var data: TileData = atlas.get_tile_data(tile, 0)
|
||||||
|
var mapping: Dictionary[String, Variant] = { 'sid': sid, 'tile': tile }
|
||||||
|
var terrain_set: int = data.terrain_set
|
||||||
|
if terrain_set != 0:
|
||||||
|
push_warning(
|
||||||
|
"The tile at %s has a terrain set of %d. \
|
||||||
|
Only terrain set 0 is supported." % [mapping, terrain_set],
|
||||||
|
)
|
||||||
|
return
|
||||||
|
var terrain: int = data.terrain
|
||||||
|
if terrain != -1:
|
||||||
|
if not terrain in terrains:
|
||||||
|
terrains[terrain] = mapping
|
||||||
|
|
||||||
|
var filters = NEIGHBORHOOD_LAYERS[neighborhood]
|
||||||
|
for i in layers.size():
|
||||||
|
var layer: TerrainLayer = layers[i]
|
||||||
|
layer._register_tile(data, mapping)
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Emitted when any of the terrains change.
|
||||||
|
##[br] NOTE: Prefer connecting to TerrainDual.changed
|
||||||
|
## instead of TileSetWatcher.terrains_changed.
|
||||||
|
func _changed() -> void:
|
||||||
|
#print('SIGNAL EMITTED: changed(%s)' % {})
|
||||||
|
read_tileset(_tileset_watcher.tile_set)
|
||||||
|
emit_changed()
|
||||||
1
addons/TileMapDual/terrain_dual.gd.uid
Normal file
1
addons/TileMapDual/terrain_dual.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://qa8xnqphuk68
|
||||||
126
addons/TileMapDual/terrain_layer.gd
Normal file
126
addons/TileMapDual/terrain_layer.gd
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
class_name TerrainLayer
|
||||||
|
extends Resource
|
||||||
|
## A set of _rules usable by a single DisplayLayer.
|
||||||
|
|
||||||
|
const TILE_EMPTY: Dictionary[String, Variant] = { 'sid': -1, 'tile': Vector2i(-1, -1) }
|
||||||
|
|
||||||
|
## A list of which CellNeighbors to care about during terrain checking.
|
||||||
|
var terrain_neighborhood: Array = []
|
||||||
|
##[br] When a cell in a DisplayLayer needs to be recomputed,
|
||||||
|
## the TerrainLayer needs to know which tiles surround it.
|
||||||
|
##[br] This Array stores the paths from the affected cell to the neighboring world cells.
|
||||||
|
var display_to_world_neighborhood: Array
|
||||||
|
## Generator for random placement of tiles
|
||||||
|
var rand: RandomNumberGenerator
|
||||||
|
## Random seed used to generate tiles deterministically
|
||||||
|
var global_seed: int = 707
|
||||||
|
# TODO: change Mapping to support https://github.com/pablogila/TileMapDual/issues/13
|
||||||
|
##[br] The rules that dictate which tile matches a given set of neighbors.
|
||||||
|
##[br] Used by register_rule() and apply_rule()
|
||||||
|
##[codeblock]
|
||||||
|
## _rules: TrieNode = # The actual type of _rules
|
||||||
|
##
|
||||||
|
## TrieNode: Dictionary{
|
||||||
|
## key: int = # The terrain value of this neighbor
|
||||||
|
## value: TrieNode | TrieLeaf = # The next branch of this trie
|
||||||
|
## }
|
||||||
|
##
|
||||||
|
## TrieLeaf: Dictionary{
|
||||||
|
## 'mapping': Mapping = # The tile that this should now become
|
||||||
|
## }
|
||||||
|
##
|
||||||
|
## Mapping: Dictionary{
|
||||||
|
## 'sid': int = # The source_id of this tile
|
||||||
|
## 'tile': Vector2i = # The Atlas Coordinates of this tile
|
||||||
|
## }
|
||||||
|
##[/codeblock]
|
||||||
|
##[br] Internally a decision "trie":
|
||||||
|
##[br] - each node branch represents a terrain neighbor
|
||||||
|
##[br] - each leaf node represents the terrain that a tile
|
||||||
|
## with the given terrain neighborhood should become
|
||||||
|
##[br]
|
||||||
|
##[br] How the trie is searched:
|
||||||
|
##[br] - check the next neighbor in terrain_neighbors
|
||||||
|
##[br] - check if there is a branch corresponding to the terrain of that neighbor
|
||||||
|
##[br] - if there is a branch, search again under that branch
|
||||||
|
##[br] - else pretend that neighbor is empty and try again
|
||||||
|
##[br] - if there really isn't a branch, no rules exist so just return empty
|
||||||
|
##[br] - once at a leaf node, its mapping should tell us what terrain to become
|
||||||
|
##[br]
|
||||||
|
##[br] See apply_rule() for more details.
|
||||||
|
var _rules: Dictionary = { }
|
||||||
|
|
||||||
|
|
||||||
|
## Coerces all empty tiles to have a terrain of 0.
|
||||||
|
static func normalize_terrain(terrain):
|
||||||
|
return terrain if terrain != -1 else 0
|
||||||
|
|
||||||
|
|
||||||
|
func _init(fields: Dictionary) -> void:
|
||||||
|
self.terrain_neighborhood = fields.terrain_neighborhood
|
||||||
|
self.display_to_world_neighborhood = fields.display_to_world_neighborhood
|
||||||
|
self.rand = RandomNumberGenerator.new()
|
||||||
|
|
||||||
|
|
||||||
|
## Returns the tile that should be used based on the surrounding terrain neighbors
|
||||||
|
func apply_rule(terrain_neighbors: Array, cell: Vector2i) -> Dictionary:
|
||||||
|
var is_empty: bool = terrain_neighbors.all(func(terrain): return terrain == -1)
|
||||||
|
if is_empty:
|
||||||
|
return TILE_EMPTY
|
||||||
|
var normalized_neighbors = terrain_neighbors.map(normalize_terrain)
|
||||||
|
|
||||||
|
var node := _rules
|
||||||
|
for terrain in normalized_neighbors:
|
||||||
|
if terrain not in node:
|
||||||
|
terrain = 0
|
||||||
|
if terrain not in node:
|
||||||
|
return TILE_EMPTY
|
||||||
|
node = node[terrain]
|
||||||
|
if 'mappings' not in node:
|
||||||
|
return TILE_EMPTY
|
||||||
|
|
||||||
|
#random tile selection
|
||||||
|
var weights: Array = []
|
||||||
|
var index: int = 0
|
||||||
|
for mapping in node.mappings:
|
||||||
|
weights.append(mapping.prob)
|
||||||
|
rand.seed = hash(str(cell) + str(global_seed))
|
||||||
|
index = rand.rand_weighted(weights)
|
||||||
|
return node.mappings[index]
|
||||||
|
|
||||||
|
|
||||||
|
## Register a new rule for a specific tile in an atlas.
|
||||||
|
func _register_tile(data: TileData, mapping: Dictionary) -> void:
|
||||||
|
if data.terrain_set != 0:
|
||||||
|
# This was already handled as an error in the parent TerrainDual
|
||||||
|
return
|
||||||
|
var terrain_neighbors := terrain_neighborhood.map(data.get_terrain_peering_bit)
|
||||||
|
# Skip tiles with no peering bits in this filter
|
||||||
|
# They might be used for a different layer,
|
||||||
|
# or may have no peering bits at all, which will just be ignored by all layers
|
||||||
|
if terrain_neighbors.any(func(neighbor): return neighbor == -1):
|
||||||
|
if terrain_neighbors.any(func(neighbor): return neighbor != -1):
|
||||||
|
push_warning(
|
||||||
|
"Invalid Tile Neighborhood at %s.\n" % [mapping] +
|
||||||
|
"Expected neighborhood: %s" % [terrain_neighborhood.map(Util.neighbor_name)],
|
||||||
|
)
|
||||||
|
return
|
||||||
|
mapping["prob"] = data.probability
|
||||||
|
_register_rule(terrain_neighbors, mapping)
|
||||||
|
|
||||||
|
|
||||||
|
## Register a new rule for a set of surrounding terrain neighbors
|
||||||
|
func _register_rule(terrain_neighbors: Array, mapping: Dictionary) -> void:
|
||||||
|
var node: Dictionary = _rules
|
||||||
|
for terrain in terrain_neighbors:
|
||||||
|
if terrain not in node:
|
||||||
|
node[terrain] = { }
|
||||||
|
node = node[terrain]
|
||||||
|
if not 'mappings' in node:
|
||||||
|
node.mappings = []
|
||||||
|
node.mappings.append(mapping)
|
||||||
|
|
||||||
|
|
||||||
|
## Utility function for easier printing
|
||||||
|
func _neighbors_to_dict(terrain_neighbors: Array) -> Dictionary:
|
||||||
|
return Util.arrays_to_dict(terrain_neighborhood.map(Util.neighbor_name), terrain_neighbors)
|
||||||
1
addons/TileMapDual/terrain_layer.gd.uid
Normal file
1
addons/TileMapDual/terrain_layer.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ks3fxwahkm6j
|
||||||
375
addons/TileMapDual/terrain_preset.gd
Normal file
375
addons/TileMapDual/terrain_preset.gd
Normal file
|
|
@ -0,0 +1,375 @@
|
||||||
|
class_name TerrainPreset
|
||||||
|
## Functions for automatically generating terrains for an atlas.
|
||||||
|
|
||||||
|
## Determines the available Terrain presets for a certain Atlas.
|
||||||
|
enum Topology {
|
||||||
|
SQUARE,
|
||||||
|
TRIANGLE,
|
||||||
|
}
|
||||||
|
|
||||||
|
## Maps a Neighborhood to a Topology.
|
||||||
|
const NEIGHBORHOOD_TOPOLOGIES: Dictionary[TerrainDual.Neighborhood, Topology] = {
|
||||||
|
TerrainDual.Neighborhood.SQUARE: Topology.SQUARE,
|
||||||
|
TerrainDual.Neighborhood.ISOMETRIC: Topology.SQUARE,
|
||||||
|
TerrainDual.Neighborhood.TRIANGLE_HORIZONTAL: Topology.TRIANGLE,
|
||||||
|
TerrainDual.Neighborhood.TRIANGLE_VERTICAL: Topology.TRIANGLE,
|
||||||
|
}
|
||||||
|
## Contains all of the builtin Terrain presets for each topology
|
||||||
|
const PRESETS: Dictionary[Topology, Dictionary] = {
|
||||||
|
Topology.SQUARE: {
|
||||||
|
'Standard': {
|
||||||
|
'size': Vector2i(4, 4),
|
||||||
|
'bg': Vector2i(0, 3),
|
||||||
|
'fg': Vector2i(2, 1),
|
||||||
|
'layers': [
|
||||||
|
[
|
||||||
|
# []
|
||||||
|
Vector2i(0, 3),
|
||||||
|
Vector2i(3, 3),
|
||||||
|
Vector2i(0, 2),
|
||||||
|
Vector2i(1, 2),
|
||||||
|
Vector2i(0, 0),
|
||||||
|
Vector2i(3, 2),
|
||||||
|
Vector2i(2, 3),
|
||||||
|
Vector2i(3, 1),
|
||||||
|
Vector2i(1, 3),
|
||||||
|
Vector2i(0, 1),
|
||||||
|
Vector2i(1, 0),
|
||||||
|
Vector2i(2, 2),
|
||||||
|
Vector2i(3, 0),
|
||||||
|
Vector2i(2, 0),
|
||||||
|
Vector2i(1, 1),
|
||||||
|
Vector2i(2, 1),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Topology.TRIANGLE: {
|
||||||
|
'Standard': {
|
||||||
|
'size': Vector2i(4, 4),
|
||||||
|
'bg': Vector2i(0, 0),
|
||||||
|
'fg': Vector2i(0, 2),
|
||||||
|
'layers': [
|
||||||
|
[
|
||||||
|
# v
|
||||||
|
Vector2i(0, 1),
|
||||||
|
Vector2i(2, 3),
|
||||||
|
Vector2i(3, 1),
|
||||||
|
Vector2i(1, 3),
|
||||||
|
Vector2i(1, 1),
|
||||||
|
Vector2i(3, 3),
|
||||||
|
Vector2i(2, 1),
|
||||||
|
Vector2i(0, 3),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
# ^
|
||||||
|
Vector2i(0, 0),
|
||||||
|
Vector2i(2, 2),
|
||||||
|
Vector2i(3, 0),
|
||||||
|
Vector2i(1, 2),
|
||||||
|
Vector2i(1, 0),
|
||||||
|
Vector2i(3, 2),
|
||||||
|
Vector2i(2, 0),
|
||||||
|
Vector2i(0, 2),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
# Old template.
|
||||||
|
# a bit inconvenient to use for Brick (Half-Off Square) tilesets.
|
||||||
|
'Winged': {
|
||||||
|
'size': Vector2i(4, 4),
|
||||||
|
'bg': Vector2i(0, 0),
|
||||||
|
'fg': Vector2i(0, 2),
|
||||||
|
'layers': [
|
||||||
|
[
|
||||||
|
# v
|
||||||
|
Vector2i(0, 1),
|
||||||
|
Vector2i(2, 1),
|
||||||
|
Vector2i(3, 1),
|
||||||
|
Vector2i(1, 3),
|
||||||
|
Vector2i(1, 1),
|
||||||
|
Vector2i(3, 3),
|
||||||
|
Vector2i(2, 3),
|
||||||
|
Vector2i(0, 3),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
# ^
|
||||||
|
Vector2i(0, 0),
|
||||||
|
Vector2i(2, 0),
|
||||||
|
Vector2i(3, 0),
|
||||||
|
Vector2i(1, 2),
|
||||||
|
Vector2i(1, 0),
|
||||||
|
Vector2i(3, 2),
|
||||||
|
Vector2i(2, 2),
|
||||||
|
Vector2i(0, 2),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
# Old template.
|
||||||
|
# The gaps between triangles made them harder to align.
|
||||||
|
'Alternating': {
|
||||||
|
'size': Vector2i(4, 4),
|
||||||
|
'bg': Vector2i(0, 0),
|
||||||
|
'fg': Vector2i(0, 2),
|
||||||
|
'layers': [
|
||||||
|
[
|
||||||
|
# v
|
||||||
|
Vector2i(0, 0),
|
||||||
|
Vector2i(2, 0),
|
||||||
|
Vector2i(3, 1),
|
||||||
|
Vector2i(1, 3),
|
||||||
|
Vector2i(1, 1),
|
||||||
|
Vector2i(3, 3),
|
||||||
|
Vector2i(2, 2),
|
||||||
|
Vector2i(0, 2),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
# ^
|
||||||
|
Vector2i(0, 1),
|
||||||
|
Vector2i(2, 1),
|
||||||
|
Vector2i(3, 0),
|
||||||
|
Vector2i(1, 2),
|
||||||
|
Vector2i(1, 0),
|
||||||
|
Vector2i(3, 2),
|
||||||
|
Vector2i(2, 3),
|
||||||
|
Vector2i(0, 3),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Maps a Neighborhood to a preset of the specified name.
|
||||||
|
static func neighborhood_preset(
|
||||||
|
neighborhood: TerrainDual.Neighborhood,
|
||||||
|
preset_name: String = 'Standard',
|
||||||
|
) -> Dictionary:
|
||||||
|
var topology: Topology = NEIGHBORHOOD_TOPOLOGIES[neighborhood]
|
||||||
|
# TODO: test when the preset doesn't exist
|
||||||
|
var available_presets: Dictionary = PRESETS[topology]
|
||||||
|
if preset_name not in available_presets:
|
||||||
|
return { 'size': Vector2i.ONE, 'layers': [] }
|
||||||
|
var out: Dictionary = available_presets[preset_name].duplicate(true)
|
||||||
|
# All Horizontal neighborhoods can be transposed to Vertical
|
||||||
|
if neighborhood == TerrainDual.Neighborhood.TRIANGLE_VERTICAL:
|
||||||
|
out.size = Util.transpose_vec(out.size)
|
||||||
|
out.fg = Util.transpose_vec(out.fg)
|
||||||
|
out.bg = Util.transpose_vec(out.bg)
|
||||||
|
for seq in out.layers:
|
||||||
|
for i in seq.size():
|
||||||
|
seq[i] = Util.transpose_vec(seq[i])
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Would you like to automatically create tiles in the atlas?
|
||||||
|
##[br]
|
||||||
|
##[br] NOTE: Assumes urm.create_action() was called.
|
||||||
|
##Does not actually do anything until urm.commit_action() is called.
|
||||||
|
##[br] NOTE: Assumes atlas only has auto-generated tiles.
|
||||||
|
##Does not save peering bit information or anything else for undo/redo.
|
||||||
|
static func write_default_preset(
|
||||||
|
urm: EditorUndoRedoManager,
|
||||||
|
tile_set: TileSet,
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
) -> void:
|
||||||
|
#print('writing default')
|
||||||
|
var neighborhood := TerrainDual.tileset_neighborhood(tile_set)
|
||||||
|
var terrain: int = new_terrain(
|
||||||
|
urm,
|
||||||
|
tile_set,
|
||||||
|
atlas.texture.resource_path.get_file(),
|
||||||
|
)
|
||||||
|
write_preset(
|
||||||
|
urm,
|
||||||
|
atlas,
|
||||||
|
neighborhood,
|
||||||
|
terrain,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Creates terrain set 0 (the primary terrain set) and terrain 0 (the 'any' terrain)
|
||||||
|
##[br]
|
||||||
|
##[br] NOTE: Assumes urm.create_action() was called.
|
||||||
|
##Does not actually do anything until urm.commit_action() is called.
|
||||||
|
static func init_terrains(urm: EditorUndoRedoManager, tile_set: TileSet) -> void:
|
||||||
|
urm.add_do_method(TerrainPreset, "_do_init_terrains", tile_set)
|
||||||
|
urm.add_undo_method(TerrainPreset, "_undo_init_terrains", tile_set)
|
||||||
|
|
||||||
|
|
||||||
|
static func _do_init_terrains(tile_set: TileSet) -> void:
|
||||||
|
tile_set.add_terrain_set()
|
||||||
|
tile_set.set_terrain_set_mode(0, TileSet.TERRAIN_MODE_MATCH_CORNERS)
|
||||||
|
tile_set.add_terrain(0)
|
||||||
|
tile_set.set_terrain_name(0, 0, "<any>")
|
||||||
|
tile_set.set_terrain_color(0, 0, Color.VIOLET)
|
||||||
|
|
||||||
|
|
||||||
|
static func _undo_init_terrains(tile_set: TileSet) -> void:
|
||||||
|
tile_set.remove_terrain_set(0)
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Adds a new terrain type to terrain set 0 for the sprites to use.
|
||||||
|
##[br]
|
||||||
|
##[br] NOTE: Assumes urm.create_action() was called.
|
||||||
|
## Does not actually do anything until urm.commit_action() is called.
|
||||||
|
static func new_terrain(urm: EditorUndoRedoManager, tile_set: TileSet, terrain_name: String) -> int:
|
||||||
|
var terrain: int
|
||||||
|
if tile_set.get_terrain_sets_count() == 0:
|
||||||
|
init_terrains(urm, tile_set)
|
||||||
|
terrain = 1
|
||||||
|
else:
|
||||||
|
terrain = tile_set.get_terrains_count(0)
|
||||||
|
urm.add_do_method(TerrainPreset, "_do_new_terrain", tile_set, terrain_name)
|
||||||
|
urm.add_undo_method(TerrainPreset, "_undo_new_terrain", tile_set)
|
||||||
|
return terrain
|
||||||
|
|
||||||
|
|
||||||
|
static func _do_new_terrain(tile_set: TileSet, terrain_name: String) -> void:
|
||||||
|
tile_set.add_terrain(0)
|
||||||
|
var terrain: int = tile_set.get_terrains_count(0) - 1
|
||||||
|
tile_set.set_terrain_name(0, terrain, "FG -%s" % terrain_name)
|
||||||
|
|
||||||
|
|
||||||
|
static func _undo_new_terrain(tile_set: TileSet) -> void:
|
||||||
|
var terrain: int = tile_set.get_terrains_count(0) - 1
|
||||||
|
tile_set.remove_terrain(0, terrain)
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Takes a preset and writes it onto the given atlas, replacing the previous configuration.
|
||||||
|
##[br] ARGUMENTS:
|
||||||
|
##[br] - atlas: the atlas source to apply the preset to.
|
||||||
|
##[br] - filters: the neighborhood filter
|
||||||
|
##[br]
|
||||||
|
##[br] NOTE: Assumes urm.create_action() was called.
|
||||||
|
## Does not actually do anything until urm.commit_action() is called.
|
||||||
|
##[br] NOTE: Assumes atlas only has auto-generated tiles.
|
||||||
|
## Does not save peering bit information or anything else for undo/redo.
|
||||||
|
static func write_preset(
|
||||||
|
urm: EditorUndoRedoManager,
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
neighborhood: TerrainDual.Neighborhood,
|
||||||
|
terrain_foreground: int,
|
||||||
|
terrain_background: int = 0,
|
||||||
|
preset: Dictionary = neighborhood_preset(neighborhood),
|
||||||
|
) -> void:
|
||||||
|
clear_and_divide_atlas(urm, atlas, preset.size)
|
||||||
|
urm.add_do_method(
|
||||||
|
TerrainPreset,
|
||||||
|
'_do_write_preset',
|
||||||
|
atlas,
|
||||||
|
neighborhood,
|
||||||
|
terrain_foreground,
|
||||||
|
terrain_background,
|
||||||
|
preset,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
static func _do_write_preset(
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
neighborhood: TerrainDual.Neighborhood,
|
||||||
|
terrain_foreground: int,
|
||||||
|
terrain_background: int,
|
||||||
|
preset: Dictionary,
|
||||||
|
) -> void:
|
||||||
|
var layers: Array = TerrainDual.NEIGHBORHOOD_LAYERS[neighborhood]
|
||||||
|
# Set peering bits
|
||||||
|
var sequences: Array = preset.layers
|
||||||
|
for j in layers.size():
|
||||||
|
var terrain_neighborhood = layers[j].terrain_neighborhood
|
||||||
|
var sequence: Array = sequences[j]
|
||||||
|
for i in sequence.size():
|
||||||
|
var tile: Vector2i = sequence[i]
|
||||||
|
atlas.create_tile(tile)
|
||||||
|
var data: TileData = atlas.get_tile_data(tile, 0)
|
||||||
|
data.terrain_set = 0
|
||||||
|
for neighbor in terrain_neighborhood:
|
||||||
|
data.set_terrain_peering_bit(
|
||||||
|
neighbor,
|
||||||
|
[terrain_background, terrain_foreground][i & 1],
|
||||||
|
)
|
||||||
|
i >>= 1
|
||||||
|
# Set terrains
|
||||||
|
atlas.get_tile_data(preset.bg, 0).terrain = terrain_background
|
||||||
|
atlas.get_tile_data(preset.fg, 0).terrain = terrain_foreground
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Unregisters all the tiles in an atlas and changes the size of the individual sprites.
|
||||||
|
##[br]
|
||||||
|
##[br] NOTE: Assumes urm.create_action() was called.
|
||||||
|
## Does not actually do anything until urm.commit_action() is called.
|
||||||
|
##[br] NOTE: Assumes atlas only has auto-generated tiles.
|
||||||
|
## Does not save peering bit information or anything else for undo/redo.
|
||||||
|
static func clear_and_resize_atlas(
|
||||||
|
urm: EditorUndoRedoManager,
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
size: Vector2,
|
||||||
|
) -> void:
|
||||||
|
var atlas_data: Dictionary[String, Variant] = _save_atlas_data(atlas)
|
||||||
|
urm.add_do_method(TerrainPreset, '_do_clear_and_resize_atlas', atlas, size)
|
||||||
|
urm.add_undo_method(TerrainPreset, '_undo_clear_and_resize_atlas', atlas, atlas_data)
|
||||||
|
|
||||||
|
|
||||||
|
static func _do_clear_and_resize_atlas(atlas: TileSetAtlasSource, size: Vector2) -> void:
|
||||||
|
# Clear all tiles
|
||||||
|
atlas.texture_region_size = atlas.texture.get_size() + Vector2.ONE
|
||||||
|
atlas.clear_tiles_outside_texture()
|
||||||
|
# Resize the tiles
|
||||||
|
atlas.texture_region_size = size
|
||||||
|
|
||||||
|
|
||||||
|
static func _undo_clear_and_resize_atlas(
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
atlas_data: Dictionary[String, Variant],
|
||||||
|
) -> void:
|
||||||
|
_load_atlas_data(atlas, atlas_data)
|
||||||
|
|
||||||
|
|
||||||
|
## NOTE: Assumes atlas only has auto-generated tiles.
|
||||||
|
## Does not save peering bit information or anything else.
|
||||||
|
static func _save_atlas_data(
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
) -> Dictionary[String, Variant]:
|
||||||
|
var size_img: Vector2 = atlas.texture.get_size()
|
||||||
|
var size_sprite: Vector2i = atlas.texture_region_size
|
||||||
|
var size_dims := Vector2i(size_img) / size_sprite
|
||||||
|
var tiles: Array[Array] = []
|
||||||
|
for y in size_dims.y:
|
||||||
|
var row: Array[bool] = []
|
||||||
|
for x in size_dims.x:
|
||||||
|
var tile := Vector2i(x, y)
|
||||||
|
var exists: bool = atlas.has_tile(tile)
|
||||||
|
row.push_back(exists)
|
||||||
|
tiles.push_back(row)
|
||||||
|
return {
|
||||||
|
'size_sprite': size_sprite,
|
||||||
|
'size_dims': size_dims,
|
||||||
|
'tiles': tiles,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static func _load_atlas_data(
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
atlas_data: Dictionary[String, Variant],
|
||||||
|
) -> void:
|
||||||
|
_do_clear_and_resize_atlas(atlas, atlas_data.size_sprite)
|
||||||
|
for y in atlas_data.size_dims.y:
|
||||||
|
for x in atlas_data.size_dims.x:
|
||||||
|
if atlas_data.tiles[y][x]:
|
||||||
|
var tile := Vector2i(x, y)
|
||||||
|
atlas.create_tile(tile)
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Unregisters all the tiles in an atlas and changes the size of the
|
||||||
|
## individual sprites to accomodate a divisions.x by divisions.y grid of sprites.
|
||||||
|
##[br]
|
||||||
|
##[br] NOTE: Assumes urm.create_action() was called.
|
||||||
|
## Does not actually do anything until urm.commit_action() is called.
|
||||||
|
##[br] NOTE: Assumes atlas only has auto-generated tiles.
|
||||||
|
## Does not save peering bit information or anything else for undo/redo.
|
||||||
|
static func clear_and_divide_atlas(
|
||||||
|
urm: EditorUndoRedoManager,
|
||||||
|
atlas: TileSetAtlasSource,
|
||||||
|
divisions: Vector2i,
|
||||||
|
) -> void:
|
||||||
|
clear_and_resize_atlas(urm, atlas, atlas.texture.get_size() / Vector2(divisions))
|
||||||
1
addons/TileMapDual/terrain_preset.gd.uid
Normal file
1
addons/TileMapDual/terrain_preset.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cdsxbtu57wews
|
||||||
76
addons/TileMapDual/tile_cache.gd
Normal file
76
addons/TileMapDual/tile_cache.gd
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
class_name TileCache
|
||||||
|
extends Resource
|
||||||
|
## Caches the sprite location and terrains of each tile in the TileMapDual world grid.
|
||||||
|
|
||||||
|
##[br] Maps a cell coordinate to the stored tile data.
|
||||||
|
##[codeblock]
|
||||||
|
## Dictionary{
|
||||||
|
## key: Vector2i = # The coordinates of this tile in the world grid.
|
||||||
|
## value: Dictionary{
|
||||||
|
## 'sid': int = # The Source ID of this tile.
|
||||||
|
## 'tile': Vector2i = # The coordinates of this tile in its Atlas.
|
||||||
|
## 'terrain': int = # The terrain assigned to this tile.
|
||||||
|
## } = # The data stored at this tile.
|
||||||
|
## }
|
||||||
|
##[/codeblock]
|
||||||
|
var cells: Dictionary[Vector2i, Dictionary] = { }
|
||||||
|
|
||||||
|
|
||||||
|
func _init() -> void:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Updates specific cells of the TileCache based on the current layer data at those points.
|
||||||
|
##[br] Makes corrections in case the user accidentally places invalid tiles.
|
||||||
|
func update(world: TileMapLayer, edited: Array[Vector2i] = cells.keys()) -> void:
|
||||||
|
var tile_set: TileSet = world.tile_set
|
||||||
|
if tile_set == null:
|
||||||
|
push_error('Attempted to update TileCache while tile set was null')
|
||||||
|
return
|
||||||
|
for cell: Vector2i in edited:
|
||||||
|
# Invalid cells will be treated as empty and ignored
|
||||||
|
var sid: int = world.get_cell_source_id(cell)
|
||||||
|
if sid == -1:
|
||||||
|
cells.erase(cell)
|
||||||
|
continue
|
||||||
|
if not tile_set.has_source(sid):
|
||||||
|
continue
|
||||||
|
var src = tile_set.get_source(sid)
|
||||||
|
var tile: Vector2i = world.get_cell_atlas_coords(cell)
|
||||||
|
if not src.has_tile(tile):
|
||||||
|
continue
|
||||||
|
var data: TileData = world.get_cell_tile_data(cell)
|
||||||
|
if data == null:
|
||||||
|
continue
|
||||||
|
# Accidental cells should be reset to their previous value
|
||||||
|
# They will be treated as unchanged
|
||||||
|
if data.terrain == -1 or data.terrain_set != 0:
|
||||||
|
if cell not in cells:
|
||||||
|
world.erase_cell(cell)
|
||||||
|
continue
|
||||||
|
var cached: Dictionary = cells[cell]
|
||||||
|
sid = cached.sid
|
||||||
|
tile = cached.tile
|
||||||
|
world.set_cell(cell, sid, tile)
|
||||||
|
data = world.get_cell_tile_data(cell)
|
||||||
|
cells[cell] = { 'sid': sid, 'tile': tile, 'terrain': data.terrain }
|
||||||
|
|
||||||
|
|
||||||
|
## Returns the symmetric difference (xor) of two tile caches.
|
||||||
|
func xor(other: TileCache) -> Array[Vector2i]:
|
||||||
|
var out: Array[Vector2i] = []
|
||||||
|
for key in cells:
|
||||||
|
if key not in other.cells or cells[key].terrain != other.cells[key].terrain:
|
||||||
|
out.push_back(key)
|
||||||
|
for key in other.cells:
|
||||||
|
if key not in cells:
|
||||||
|
out.push_back(key)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Returns the terrain value of the tile at the given cell coordinates.
|
||||||
|
##[br] Empty cells have a terrain of -1.
|
||||||
|
func get_terrain_at(cell: Vector2i) -> int:
|
||||||
|
if cell not in cells:
|
||||||
|
return -1
|
||||||
|
return cells[cell].terrain
|
||||||
1
addons/TileMapDual/tile_cache.gd.uid
Normal file
1
addons/TileMapDual/tile_cache.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dpuc70ypq7wf8
|
||||||
170
addons/TileMapDual/tile_map_dual.gd
Normal file
170
addons/TileMapDual/tile_map_dual.gd
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
@tool
|
||||||
|
@icon('tile_map_dual.svg')
|
||||||
|
class_name TileMapDual
|
||||||
|
extends TileMapLayer
|
||||||
|
|
||||||
|
static var autotile: Callable = _editor_only.bind('autotile').unbind(3)
|
||||||
|
static var popup: Callable = _editor_only.bind('popup').unbind(2)
|
||||||
|
|
||||||
|
## HACK: How long to wait before processing another "frame".
|
||||||
|
## Mainly matters when [godot_4_3_compatibility] is active.
|
||||||
|
@export_range(0.0, 0.1) var refresh_time: float = 0.02
|
||||||
|
## When toggled on, double-checks ALL cells in the grid every change.
|
||||||
|
## Only use this when running Godot 4.3 and below,
|
||||||
|
## where TileMapLayer could not detect changes properly.
|
||||||
|
@export var godot_4_3_compatibility: bool = _godot_is_below_4_4()
|
||||||
|
|
||||||
|
## Material for the display tilemap.
|
||||||
|
@export_custom(PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial, CanvasItemMaterial")
|
||||||
|
var display_material: Material:
|
||||||
|
get:
|
||||||
|
return display_material
|
||||||
|
set(new_material): # Custom setter so that it gets copied
|
||||||
|
display_material = new_material
|
||||||
|
changed.emit()
|
||||||
|
## An invisible material used to hide the world grid so only the display layers show up.
|
||||||
|
## Currently implemented as a shader that sets all pixels to 0 alpha.
|
||||||
|
var _ghost_material: Material = preload("res://addons/TileMapDual/ghost_material.tres")
|
||||||
|
var _tileset_watcher: TileSetWatcher
|
||||||
|
var _display: Display
|
||||||
|
## Keeps track of use_parent_material to see when it turns on or off.
|
||||||
|
var _cached_use_parent_material = null
|
||||||
|
var _timer: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
# === External functions that don't exist once exported ===
|
||||||
|
# HACK: this uses some sort of "Dynamic Linking" technique
|
||||||
|
# because these features don't exist right now
|
||||||
|
# - conditional compilation
|
||||||
|
# - static signals
|
||||||
|
static func _editor_only(name: String):
|
||||||
|
push_error('Attempt to call Editor-Only function "' + name + '"')
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
_tileset_watcher = TileSetWatcher.new(tile_set)
|
||||||
|
_display = Display.new(self, _tileset_watcher)
|
||||||
|
add_child(_display)
|
||||||
|
_make_self_invisible(true)
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
_tileset_watcher.atlas_autotiled.connect(_atlas_autotiled)
|
||||||
|
set_process(true)
|
||||||
|
else: # Run in-game using signals for better performance
|
||||||
|
changed.connect(_changed, 1)
|
||||||
|
set_process(false)
|
||||||
|
# Update full tileset on first instance
|
||||||
|
await get_tree().process_frame
|
||||||
|
_changed()
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta: float) -> void: # Only used inside the editor
|
||||||
|
if refresh_time < 0.0:
|
||||||
|
return
|
||||||
|
if _timer > 0:
|
||||||
|
_timer -= delta
|
||||||
|
return
|
||||||
|
_timer = refresh_time
|
||||||
|
_changed.call_deferred()
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Public method to add and remove tiles.
|
||||||
|
##[br]
|
||||||
|
##[br] - 'cell' is a vector with the cell position.
|
||||||
|
##[br] - 'terrain' is which terrain type to draw.
|
||||||
|
##[br] - terrain -1 completely removes the tile,
|
||||||
|
##[br] - and by default, terrain 0 is the empty tile.
|
||||||
|
func draw_cell(cell: Vector2i, terrain: int = 1) -> void:
|
||||||
|
var terrains: Dictionary[int, Dictionary] = _display.terrain.terrains
|
||||||
|
if terrain not in terrains:
|
||||||
|
erase_cell(cell)
|
||||||
|
changed.emit()
|
||||||
|
return
|
||||||
|
var tile_to_use: Dictionary = terrains[terrain]
|
||||||
|
var sid: int = tile_to_use.sid
|
||||||
|
var tile: Vector2i = tile_to_use.tile
|
||||||
|
set_cell(cell, sid, tile)
|
||||||
|
changed.emit()
|
||||||
|
|
||||||
|
|
||||||
|
## Public method to get the terrain at a specific coordinate.
|
||||||
|
func get_cell(cell: Vector2i) -> int:
|
||||||
|
return get_cell_tile_data(cell).terrain
|
||||||
|
|
||||||
|
|
||||||
|
## Automatically generate terrains when the atlas is initialized.
|
||||||
|
func _atlas_autotiled(source_id: int, atlas: TileSetAtlasSource):
|
||||||
|
autotile.call(source_id, atlas, tile_set)
|
||||||
|
|
||||||
|
|
||||||
|
##[br] Makes the main world grid invisible.
|
||||||
|
##[br] The main tiles don't need to be seen. Only the DisplayLayers should be visible.
|
||||||
|
##[br] Called every frame, and functions a lot like TileSetWatcher.
|
||||||
|
func _make_self_invisible(startup: bool = false) -> void:
|
||||||
|
# If user has set a material in the original slot, inform the user
|
||||||
|
if material != _ghost_material:
|
||||||
|
if not startup and Engine.is_editor_hint():
|
||||||
|
popup.call(
|
||||||
|
"Warning! Direct material edit detected.",
|
||||||
|
"Don't manually edit the real material in the editor! \
|
||||||
|
Instead edit the custom 'Display Material' property.\n" +
|
||||||
|
"(Resetting the material to an invisible shader material... \
|
||||||
|
this is to keep the 'World Layer' invisible)\n" +
|
||||||
|
"* This warning is only given when the material is set in the Godot editor.\n" +
|
||||||
|
"* In-game scripts may set the material directly. \
|
||||||
|
It will be copied over to display_material automatically.",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# copy over the material if it was edited by script
|
||||||
|
display_material = material
|
||||||
|
material = _ghost_material # Force TileMapDual's material to become invisible
|
||||||
|
|
||||||
|
# check if use_parent_material is set
|
||||||
|
if (
|
||||||
|
Engine.is_editor_hint()
|
||||||
|
and use_parent_material != _cached_use_parent_material
|
||||||
|
and _cached_use_parent_material == false # cache may be null
|
||||||
|
):
|
||||||
|
popup.call(
|
||||||
|
"Warning: Using Parent Material.",
|
||||||
|
"The parent material will override any other materials \
|
||||||
|
used by the TileMapDual,\n" +
|
||||||
|
"including the 'ghost shader' that the world tiles \
|
||||||
|
use to hide themselves.\n" +
|
||||||
|
"This will cause the world tiles to show themselves in-game.\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Recommendation: Turn this setting off. Don't use parent material.\n" +
|
||||||
|
"* Workaround: Set your world tiles to custom sprites \
|
||||||
|
that are entirely transparent.\n" +
|
||||||
|
"(see 'res://addons/TileMapDual/docs/custom_drawing_sprites.mp4' \
|
||||||
|
for a non-transparent example)",
|
||||||
|
)
|
||||||
|
_cached_use_parent_material = use_parent_material
|
||||||
|
|
||||||
|
|
||||||
|
## Detects if godot is below v4.4.
|
||||||
|
## Only used to detect whether the _update_cells() function is usable.
|
||||||
|
func _godot_is_below_4_4():
|
||||||
|
var version: Dictionary = Engine.get_version_info()
|
||||||
|
return (version.major < 4) or (version.major == 4 and version.minor < 4)
|
||||||
|
|
||||||
|
|
||||||
|
## Called by signals when the tileset changes,
|
||||||
|
## or by _process inside the editor.
|
||||||
|
func _changed() -> void:
|
||||||
|
_tileset_watcher.update(tile_set)
|
||||||
|
|
||||||
|
var updated_cells: Array[Vector2i] = []
|
||||||
|
# HACK: double check all tiles every refresh
|
||||||
|
if godot_4_3_compatibility and tile_set != null:
|
||||||
|
var current_cells := TileCache.new()
|
||||||
|
current_cells.update(self, get_used_cells())
|
||||||
|
updated_cells = current_cells.xor(_display.cached_cells)
|
||||||
|
|
||||||
|
_display.update(updated_cells)
|
||||||
|
_make_self_invisible()
|
||||||
|
|
||||||
|
|
||||||
|
## Called when the user draws on the map or presses undo/redo.
|
||||||
|
func _update_cells(coords: Array[Vector2i], _forced_cleanup: bool) -> void:
|
||||||
|
if is_instance_valid(_display):
|
||||||
|
_display.update(coords)
|
||||||
1
addons/TileMapDual/tile_map_dual.gd.uid
Normal file
1
addons/TileMapDual/tile_map_dual.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cjk8nronimk5r
|
||||||
38
addons/TileMapDual/tile_map_dual.svg
Normal file
38
addons/TileMapDual/tile_map_dual.svg
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
width="16"
|
||||||
|
height="16"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
sodipodi:docname="TileMapDual.svg"
|
||||||
|
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs1" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#999999"
|
||||||
|
borderopacity="1"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:zoom="35.5"
|
||||||
|
inkscape:cx="8"
|
||||||
|
inkscape:cy="8.028169"
|
||||||
|
inkscape:window-width="1366"
|
||||||
|
inkscape:window-height="736"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg1" />
|
||||||
|
<path
|
||||||
|
fill="#8da5f3"
|
||||||
|
d="M8 2 6.25 3.375 8 4.75l1.75-1.375zm2.624 2.062-1.75 1.375 1.75 1.375 1.75-1.375Zm2.626 2.063L11.5 7.5l1.75 1.375L15 7.5ZM5.376 4.062l-1.75 1.375 1.75 1.375 1.75-1.375zM8 6.124 6.25 7.499 8 8.874l1.75-1.375zm2.626 2.063-1.75 1.375 1.75 1.375 1.75-1.375ZM2.75 6.125 1 7.5l1.75 1.375L4.5 7.5Zm2.624 2.062-1.75 1.375 1.75 1.375 1.75-1.375ZM8 10.25l-1.75 1.375L8 13l1.75-1.375z"
|
||||||
|
id="path1"
|
||||||
|
style="fill:#ffb273;fill-opacity:1" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.4 KiB |
44
addons/TileMapDual/tile_map_dual.svg.import
Normal file
44
addons/TileMapDual/tile_map_dual.svg.import
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://bqu55yxko3ofm"
|
||||||
|
path="res://.godot/imported/tile_map_dual.svg-53ffd5e7e4d2fa588a55e62f35fec36c.ctex"
|
||||||
|
metadata={
|
||||||
|
"has_editor_variant": true,
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/TileMapDual/tile_map_dual.svg"
|
||||||
|
dest_files=["res://.godot/imported/tile_map_dual.svg-53ffd5e7e4d2fa588a55e62f35fec36c.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=true
|
||||||
|
editor/convert_colors_with_editor_theme=true
|
||||||
408
addons/TileMapDual/tile_map_dual_legacy.gd
Normal file
408
addons/TileMapDual/tile_map_dual_legacy.gd
Normal file
|
|
@ -0,0 +1,408 @@
|
||||||
|
@tool
|
||||||
|
@icon('tile_map_dual.svg')
|
||||||
|
class_name TileMapDualLegacy
|
||||||
|
extends TileMapLayer
|
||||||
|
## Material for the display tilemap.
|
||||||
|
## @deprecated: Use [TileMapDual] instead.
|
||||||
|
|
||||||
|
## We will use a bit-wise logic, so that a summation over all sketched
|
||||||
|
## neighbours provides a unique key, assigned to the corresponding
|
||||||
|
## tile from the Atlas through the NEIGHBOURS_TO_ATLAS dictionary.
|
||||||
|
enum Location {
|
||||||
|
TOP_LEFT = 1,
|
||||||
|
LOW_LEFT = 2,
|
||||||
|
TOP_RIGHT = 4,
|
||||||
|
LOW_RIGHT = 8,
|
||||||
|
}
|
||||||
|
enum Direction {
|
||||||
|
TOP,
|
||||||
|
LEFT,
|
||||||
|
BOTTOM,
|
||||||
|
RIGHT,
|
||||||
|
BOTTOM_LEFT,
|
||||||
|
BOTTOM_RIGHT,
|
||||||
|
TOP_LEFT,
|
||||||
|
TOP_RIGHT,
|
||||||
|
}
|
||||||
|
|
||||||
|
## Overlapping tiles from the World grid
|
||||||
|
## that a tile from the Dual grid has.
|
||||||
|
const _NEIGHBORS: Dictionary[Direction, TileSet.CellNeighbor] = {
|
||||||
|
Direction.TOP: TileSet.CellNeighbor.CELL_NEIGHBOR_TOP_SIDE,
|
||||||
|
Direction.LEFT: TileSet.CellNeighbor.CELL_NEIGHBOR_LEFT_SIDE,
|
||||||
|
Direction.RIGHT: TileSet.CellNeighbor.CELL_NEIGHBOR_RIGHT_SIDE,
|
||||||
|
Direction.BOTTOM: TileSet.CellNeighbor.CELL_NEIGHBOR_BOTTOM_SIDE,
|
||||||
|
Direction.TOP_LEFT: TileSet.CellNeighbor.CELL_NEIGHBOR_TOP_LEFT_CORNER,
|
||||||
|
Direction.TOP_RIGHT: TileSet.CellNeighbor.CELL_NEIGHBOR_TOP_RIGHT_CORNER,
|
||||||
|
Direction.BOTTOM_LEFT: TileSet.CellNeighbor.CELL_NEIGHBOR_BOTTOM_LEFT_CORNER,
|
||||||
|
Direction.BOTTOM_RIGHT: TileSet.CellNeighbor.CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER,
|
||||||
|
}
|
||||||
|
## Overlapping tiles from the World grid
|
||||||
|
## that a tile from the Dual grid has.
|
||||||
|
## To be used ONLY with isometric tilesets.
|
||||||
|
## CellNighbors are literal, even for Isometric
|
||||||
|
const _NEIGHBORS_ISOMETRIC: Dictionary[Direction, TileSet.CellNeighbor] = {
|
||||||
|
Direction.TOP: TileSet.CellNeighbor.CELL_NEIGHBOR_TOP_RIGHT_SIDE,
|
||||||
|
Direction.LEFT: TileSet.CellNeighbor.CELL_NEIGHBOR_TOP_LEFT_SIDE,
|
||||||
|
Direction.RIGHT: TileSet.CellNeighbor.CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE,
|
||||||
|
Direction.BOTTOM: TileSet.CellNeighbor.CELL_NEIGHBOR_BOTTOM_LEFT_SIDE,
|
||||||
|
Direction.TOP_LEFT: TileSet.CellNeighbor.CELL_NEIGHBOR_TOP_CORNER,
|
||||||
|
Direction.TOP_RIGHT: TileSet.CellNeighbor.CELL_NEIGHBOR_RIGHT_CORNER,
|
||||||
|
Direction.BOTTOM_LEFT: TileSet.CellNeighbor.CELL_NEIGHBOR_LEFT_CORNER,
|
||||||
|
Direction.BOTTOM_RIGHT: TileSet.CellNeighbor.CELL_NEIGHBOR_BOTTOM_CORNER,
|
||||||
|
}
|
||||||
|
## Dict to assign the Atlas coordinates from the
|
||||||
|
## summation over all sketched NEIGHBOURS.
|
||||||
|
## Follows the official 2x2 template.
|
||||||
|
## Works for isometric as well.
|
||||||
|
const _NEIGHBORS_TO_ATLAS: Dictionary[Direction, Vector2i] = {
|
||||||
|
0: Vector2i(0, 3),
|
||||||
|
1: Vector2i(3, 3),
|
||||||
|
2: Vector2i(0, 0),
|
||||||
|
3: Vector2i(3, 2),
|
||||||
|
4: Vector2i(0, 2),
|
||||||
|
5: Vector2i(1, 2),
|
||||||
|
6: Vector2i(2, 3),
|
||||||
|
7: Vector2i(3, 1),
|
||||||
|
8: Vector2i(1, 3),
|
||||||
|
9: Vector2i(0, 1),
|
||||||
|
10: Vector2i(3, 0),
|
||||||
|
11: Vector2i(2, 0),
|
||||||
|
12: Vector2i(1, 0),
|
||||||
|
13: Vector2i(2, 2),
|
||||||
|
14: Vector2i(1, 1),
|
||||||
|
15: Vector2i(2, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
@export_custom(PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial")
|
||||||
|
var display_material: Material:
|
||||||
|
get:
|
||||||
|
return display_material
|
||||||
|
set(new_material): # Custom setter so that it gets copied
|
||||||
|
display_material = new_material
|
||||||
|
if display_tilemap: # Copy over, only if display tilemap is initiated
|
||||||
|
display_tilemap.material = display_material
|
||||||
|
var display_tilemap: TileMapLayer = null
|
||||||
|
## Coordinates for the fully-filled tile in the Atlas that
|
||||||
|
## will be used to sketch in the World grid.
|
||||||
|
## Only this tile will be considered for autotiling.
|
||||||
|
var full_tile: Vector2i = Vector2i(2, 1)
|
||||||
|
## The opposed of full_tile. Used to erase sketched tiles.
|
||||||
|
var empty_tile: Vector2i = Vector2i(0, 3)
|
||||||
|
var is_isometric: bool = false
|
||||||
|
var _filled_cells: Dictionary = { }
|
||||||
|
var _emptied_cells: Dictionary = { }
|
||||||
|
var _tile_shape: TileSet.TileShape = TileSet.TileShape.TILE_SHAPE_SQUARE
|
||||||
|
var _tile_size: Vector2i = Vector2i(16, 16)
|
||||||
|
var _should_check_cells: bool = false
|
||||||
|
## Prevents checking the cells more than once when the entire tileset
|
||||||
|
## is being updated, which is indicated by `_should_check_cells`.
|
||||||
|
var _checked_cells: Dictionary = { }
|
||||||
|
var _atlas_id: int
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
set_process(true)
|
||||||
|
else: # Run in-game using signals for better performance
|
||||||
|
set_process(false)
|
||||||
|
self.changed.connect(_update_tileset, 1)
|
||||||
|
update_full_tileset()
|
||||||
|
# Fire copy upon any property change. More specific than _update_tileset
|
||||||
|
self.changed.connect(copy_properties, 1)
|
||||||
|
|
||||||
|
|
||||||
|
func _process(_delta): # Only used inside the editor
|
||||||
|
if not self.tile_set:
|
||||||
|
return
|
||||||
|
_update_tileset.call_deferred()
|
||||||
|
|
||||||
|
|
||||||
|
## Copies properties from parent TileMapDual to child display tilemap
|
||||||
|
func copy_properties() -> void:
|
||||||
|
# Both tilemaps must be the same, so we copy all relevant properties
|
||||||
|
# Tilemap
|
||||||
|
display_tilemap.tile_set = self.tile_set
|
||||||
|
# Rendering
|
||||||
|
display_tilemap.y_sort_origin = self.y_sort_origin
|
||||||
|
display_tilemap.x_draw_order_reversed = self.x_draw_order_reversed
|
||||||
|
display_tilemap.rendering_quadrant_size = self.rendering_quadrant_size
|
||||||
|
# Physics
|
||||||
|
display_tilemap.collision_enabled = self.collision_enabled
|
||||||
|
display_tilemap.use_kinematic_bodies = self.use_kinematic_bodies
|
||||||
|
display_tilemap.collision_visibility_mode = self.collision_visibility_mode
|
||||||
|
# Navigation
|
||||||
|
display_tilemap.navigation_enabled = self.navigation_enabled
|
||||||
|
display_tilemap.navigation_visibility_mode = self.navigation_visibility_mode
|
||||||
|
# Canvas item properties
|
||||||
|
display_tilemap.show_behind_parent = self.show_behind_parent
|
||||||
|
display_tilemap.top_level = self.top_level
|
||||||
|
display_tilemap.light_mask = self.light_mask
|
||||||
|
display_tilemap.visibility_layer = self.visibility_layer
|
||||||
|
display_tilemap.y_sort_enabled = self.y_sort_enabled
|
||||||
|
display_tilemap.modulate = self.modulate
|
||||||
|
|
||||||
|
# If user has set a material in the original slot, copy it over for redundancy
|
||||||
|
# Helps both migration to new version, and prevents user mistakes
|
||||||
|
if self.material:
|
||||||
|
display_material = self.material
|
||||||
|
|
||||||
|
# Set material for first time
|
||||||
|
display_tilemap.material = display_material
|
||||||
|
|
||||||
|
# Save any manually introduced alpha modulation:
|
||||||
|
if self.self_modulate.a != 0.0:
|
||||||
|
display_tilemap.self_modulate = self.self_modulate
|
||||||
|
self.self_modulate.a = 0.0 # Override modulation to prevent render bugs with certain shaders
|
||||||
|
|
||||||
|
self.material = null # Unset TileMapDual's material, to prevent render of it
|
||||||
|
|
||||||
|
|
||||||
|
## Update the size and shape of the tileset, displacing the display TileMapLayer accordingly.
|
||||||
|
func update_geometry() -> void:
|
||||||
|
is_isometric = self.tile_set.tile_shape == TileSet.TileShape.TILE_SHAPE_ISOMETRIC
|
||||||
|
var offset := Vector2(self.tile_set.tile_size) * -0.5
|
||||||
|
if is_isometric:
|
||||||
|
offset.x = 0
|
||||||
|
display_tilemap.position = offset
|
||||||
|
_tile_size = self.tile_set.tile_size
|
||||||
|
_tile_shape = self.tile_set.tile_shape
|
||||||
|
|
||||||
|
|
||||||
|
## Update the entire tileset, processing all the cells in the map.
|
||||||
|
func update_full_tileset() -> void:
|
||||||
|
if display_tilemap == null:
|
||||||
|
_set_display_tilemap()
|
||||||
|
elif display_tilemap.tile_set != self.tile_set: # TO-DO: merge with the above
|
||||||
|
_set_display_tilemap()
|
||||||
|
_should_check_cells = true
|
||||||
|
for cell in self.get_used_cells():
|
||||||
|
if _is_world_tile_sketched(cell) == 1 or _is_world_tile_sketched(cell) == 0:
|
||||||
|
update_tile(cell)
|
||||||
|
_should_check_cells = false
|
||||||
|
_checked_cells = { }
|
||||||
|
# _checked_cells is only used when updating
|
||||||
|
# the whole tilemap to avoid repeating checks.
|
||||||
|
# This is skipped when updating tiles individually.
|
||||||
|
|
||||||
|
|
||||||
|
func array_to_dict(array: Array) -> Dictionary:
|
||||||
|
var dict: Dictionary = { }
|
||||||
|
for item in array:
|
||||||
|
dict[item] = true
|
||||||
|
return dict
|
||||||
|
|
||||||
|
|
||||||
|
## Return the values that are not shared between the arrays
|
||||||
|
func exclude_dicts(a: Dictionary, b: Dictionary) -> Dictionary:
|
||||||
|
var result = a.duplicate()
|
||||||
|
for item in b:
|
||||||
|
if result.has(item):
|
||||||
|
result.erase(item)
|
||||||
|
else:
|
||||||
|
result[item] = true
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
## Takes a cell, and updates the overlapping tiles from the dual grid accordingly.
|
||||||
|
func update_tile(world_cell: Vector2i, recurse: bool = true) -> void:
|
||||||
|
_atlas_id = self.get_cell_source_id(world_cell)
|
||||||
|
|
||||||
|
# to not fall in a recursive loop because of a large space of emptiness in the map
|
||||||
|
if (!recurse and _atlas_id == -1):
|
||||||
|
return
|
||||||
|
|
||||||
|
var _actual_neighbors = _NEIGHBORS_ISOMETRIC if is_isometric else _NEIGHBORS
|
||||||
|
var _top_left = world_cell
|
||||||
|
var _low_left = display_tilemap.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.BOTTOM],
|
||||||
|
)
|
||||||
|
var _top_right = display_tilemap.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.RIGHT],
|
||||||
|
)
|
||||||
|
var _low_right = display_tilemap.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.BOTTOM_RIGHT],
|
||||||
|
)
|
||||||
|
_update_displayed_tile(_top_left)
|
||||||
|
_update_displayed_tile(_low_left)
|
||||||
|
_update_displayed_tile(_top_right)
|
||||||
|
_update_displayed_tile(_low_right)
|
||||||
|
|
||||||
|
# if atlas id is -1 the tile is empty, so to have a good rendering
|
||||||
|
# we need to update surroundings
|
||||||
|
if (_atlas_id == -1):
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.LEFT],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.TOP_LEFT],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.TOP],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.TOP_RIGHT],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.RIGHT],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.BOTTOM_RIGHT],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.BOTTOM],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
update_tile(
|
||||||
|
self.get_neighbor_cell(
|
||||||
|
world_cell,
|
||||||
|
_actual_neighbors[Direction.BOTTOM_LEFT],
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
## Public method to add and remove tiles, as
|
||||||
|
## TileMapDual.draw(cell, tile, atlas_id).
|
||||||
|
## 'cell' is a vector with the cell position.
|
||||||
|
## 'tile' is 1 to draw the full tile (default), 0 to draw the empty tile,
|
||||||
|
## and -1 to completely remove the tile.
|
||||||
|
## 'atlas_id' is the atlas id of the tileset to modify, 0 by default.
|
||||||
|
## This method replaces the deprecated 'fill_tile' and 'erase_tile' methods.
|
||||||
|
func draw(cell: Vector2i, tile: int = 1, atlas_id: int = 0) -> void:
|
||||||
|
# Prevents a crash if this is called on the first frame
|
||||||
|
if display_tilemap == null:
|
||||||
|
update_full_tileset()
|
||||||
|
var tile_to_use: Vector2i
|
||||||
|
if tile == 1:
|
||||||
|
tile_to_use = full_tile
|
||||||
|
if tile == 0:
|
||||||
|
tile_to_use = empty_tile
|
||||||
|
if tile == -1:
|
||||||
|
tile_to_use = Vector2i(-1, -1)
|
||||||
|
atlas_id = -1
|
||||||
|
set_cell(cell, atlas_id, tile_to_use)
|
||||||
|
update_tile(cell)
|
||||||
|
|
||||||
|
|
||||||
|
## Set the dual grid as a child of TileMapDual.
|
||||||
|
func _set_display_tilemap() -> void:
|
||||||
|
if not self.tile_set:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Add the display TileMapLayer, if it doesn't already exist
|
||||||
|
if not get_node_or_null("WorldTileMap"):
|
||||||
|
display_tilemap = TileMapLayer.new()
|
||||||
|
display_tilemap.name = "WorldTileMap"
|
||||||
|
add_child(display_tilemap)
|
||||||
|
|
||||||
|
copy_properties() # Copy properties from TileMapDual to displayed tilemap
|
||||||
|
|
||||||
|
update_geometry()
|
||||||
|
display_tilemap.clear()
|
||||||
|
|
||||||
|
|
||||||
|
## Update only the very specific tiles that have changed.
|
||||||
|
## Much more efficient than update_full_tileset.
|
||||||
|
## Called by signals when the tileset changes,
|
||||||
|
## or by _process inside the editor.
|
||||||
|
func _update_tileset() -> void:
|
||||||
|
if display_tilemap == null:
|
||||||
|
update_full_tileset()
|
||||||
|
return
|
||||||
|
if display_tilemap.tile_set != self.tile_set: # TO-DO: merge with the above
|
||||||
|
update_full_tileset()
|
||||||
|
return
|
||||||
|
if _tile_size != self.tile_set.tile_size or _tile_shape != self.tile_set.tile_shape:
|
||||||
|
update_geometry()
|
||||||
|
return
|
||||||
|
|
||||||
|
var _new_emptied_cells: Dictionary = array_to_dict(get_used_cells_by_id(-1, empty_tile))
|
||||||
|
var _new_filled_cells: Dictionary = array_to_dict(get_used_cells_by_id(-1, full_tile))
|
||||||
|
var _changed_cells: Dictionary = exclude_dicts(
|
||||||
|
_emptied_cells,
|
||||||
|
_new_emptied_cells,
|
||||||
|
).merged(exclude_dicts(_filled_cells, _new_filled_cells))
|
||||||
|
|
||||||
|
_emptied_cells = _new_emptied_cells
|
||||||
|
_filled_cells = _new_filled_cells
|
||||||
|
for cell in _changed_cells:
|
||||||
|
update_tile(cell)
|
||||||
|
|
||||||
|
|
||||||
|
func _update_displayed_tile(_display_cell: Vector2i) -> void:
|
||||||
|
# Avoid updating cells more than necessary
|
||||||
|
if _should_check_cells:
|
||||||
|
if _display_cell in _checked_cells:
|
||||||
|
return
|
||||||
|
_checked_cells[_display_cell] = true
|
||||||
|
|
||||||
|
var _actual_neighbors = _NEIGHBORS_ISOMETRIC if is_isometric else _NEIGHBORS
|
||||||
|
var _top_left = display_tilemap.get_neighbor_cell(
|
||||||
|
_display_cell,
|
||||||
|
_actual_neighbors[Direction.TOP_LEFT],
|
||||||
|
)
|
||||||
|
var _low_left = display_tilemap.get_neighbor_cell(
|
||||||
|
_display_cell,
|
||||||
|
_actual_neighbors[Direction.LEFT],
|
||||||
|
)
|
||||||
|
var _top_right = display_tilemap.get_neighbor_cell(
|
||||||
|
_display_cell,
|
||||||
|
_actual_neighbors[Direction.TOP],
|
||||||
|
)
|
||||||
|
var _low_right = _display_cell
|
||||||
|
|
||||||
|
# We perform a bitwise summation over the sketched neighbours
|
||||||
|
var _tile_key: int = 0
|
||||||
|
if _is_world_tile_sketched(_top_left) == 1:
|
||||||
|
_tile_key += Location.TOP_LEFT
|
||||||
|
if _is_world_tile_sketched(_low_left) == 1:
|
||||||
|
_tile_key += Location.LOW_LEFT
|
||||||
|
if _is_world_tile_sketched(_top_right) == 1:
|
||||||
|
_tile_key += Location.TOP_RIGHT
|
||||||
|
if _is_world_tile_sketched(_low_right) == 1:
|
||||||
|
_tile_key += Location.LOW_RIGHT
|
||||||
|
|
||||||
|
var _coords_atlas: Vector2i = _NEIGHBORS_TO_ATLAS[_tile_key]
|
||||||
|
display_tilemap.set_cell(_display_cell, _atlas_id, _coords_atlas)
|
||||||
|
|
||||||
|
|
||||||
|
## Return -1 if the cell is empty, 0 if sketched with the empty tile,
|
||||||
|
## and 1 if it is sketched with the fully-filled tile.
|
||||||
|
func _is_world_tile_sketched(_world_cell: Vector2i):
|
||||||
|
var _atlas_coords = get_cell_atlas_coords(_world_cell)
|
||||||
|
if _atlas_coords == full_tile:
|
||||||
|
return 1
|
||||||
|
if _atlas_coords == empty_tile:
|
||||||
|
return 0
|
||||||
|
return -1
|
||||||
1
addons/TileMapDual/tile_map_dual_legacy.gd.uid
Normal file
1
addons/TileMapDual/tile_map_dual_legacy.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dlyqj0u8ckhb0
|
||||||
175
addons/TileMapDual/tile_set_watcher.gd
Normal file
175
addons/TileMapDual/tile_set_watcher.gd
Normal file
|
|
@ -0,0 +1,175 @@
|
||||||
|
class_name TileSetWatcher
|
||||||
|
extends Resource
|
||||||
|
## Provides information about a TileSet and sends signals when it changes.
|
||||||
|
|
||||||
|
## Emitted when the parent TileMapDual's tile_set is cleared or replaced.
|
||||||
|
signal tileset_deleted
|
||||||
|
## Emitted when the parent TileMapDual's tile_set is created or replaced.
|
||||||
|
signal tileset_created
|
||||||
|
## Emitted when tile_set.tile_size is changed.
|
||||||
|
signal tileset_resized
|
||||||
|
## Emitted when the GridShape of the TileSet would be different.
|
||||||
|
signal tileset_reshaped
|
||||||
|
## Emitted when a new Atlas is added to this TileSet.
|
||||||
|
## Does not react to Scenes being added to the TileSet.
|
||||||
|
signal atlas_added(source_id: int, atlas: TileSetAtlasSource)
|
||||||
|
## Emitted when the watcher thinks that "Yes" was clicked for:
|
||||||
|
## 'Would you like to automatically create tiles in the atlas?'
|
||||||
|
signal atlas_autotiled(source_id: int, atlas: TileSetAtlasSource)
|
||||||
|
## Emitted when an atlas is added or removed,
|
||||||
|
## or when the terrains change in one of the Atlases.
|
||||||
|
## NOTE: Prefer connecting to TerrainDual.changed instead of TileSetWatcher.terrains_changed.
|
||||||
|
signal terrains_changed
|
||||||
|
|
||||||
|
## Caches the previous tile_set to see when it changes.
|
||||||
|
var tile_set: TileSet
|
||||||
|
## Caches the previous tile_size to see when it changes.
|
||||||
|
var tile_size: Vector2i
|
||||||
|
## caches the previous result of display.tileset_grid_shape(tile_set) to see when it changes.
|
||||||
|
var grid_shape: Display.GridShape
|
||||||
|
var _flag_tileset_deleted: bool = false
|
||||||
|
var _flag_tileset_created: bool = false
|
||||||
|
var _flag_tileset_resized: bool = false
|
||||||
|
var _flag_tileset_reshaped: bool = false
|
||||||
|
var _flag_atlas_added: bool = false
|
||||||
|
var _flag_terrains_changed: bool = false
|
||||||
|
var _flag_tileset_changed: bool = false
|
||||||
|
# Cached variables from the previous frame
|
||||||
|
# These are used to compare what changed between frames
|
||||||
|
var _cached_source_count: int = 0
|
||||||
|
var _cached_sids: Dictionary[int, AtlasWatcher] = { }
|
||||||
|
|
||||||
|
|
||||||
|
func _init(tile_set: TileSet) -> void:
|
||||||
|
# tileset_deleted.connect(func(): print('tileset_deleted'), 1)
|
||||||
|
# tileset_created.connect(func(): print('tileset_created'), 1)
|
||||||
|
# tileset_resized.connect(func(): print('tileset_resized'), 1)
|
||||||
|
# tileset_reshaped.connect(func(): print('tileset_reshaped'), 1)
|
||||||
|
atlas_added.connect(_atlas_added, 1)
|
||||||
|
update(tile_set)
|
||||||
|
|
||||||
|
|
||||||
|
## Checks if anything about the concerned TileMapDual's tile_set changed.
|
||||||
|
## Must be called by the TileMapDual every frame.
|
||||||
|
func update(tile_set: TileSet) -> void:
|
||||||
|
check_tile_set(tile_set)
|
||||||
|
check_flags()
|
||||||
|
|
||||||
|
|
||||||
|
## Emit update signals if the corresponding flags were set.
|
||||||
|
## Must only be run once per frame.
|
||||||
|
func check_flags() -> void:
|
||||||
|
if _flag_tileset_changed:
|
||||||
|
_flag_tileset_changed = false
|
||||||
|
_update_tileset()
|
||||||
|
if _flag_tileset_deleted:
|
||||||
|
_flag_tileset_deleted = false
|
||||||
|
_flag_tileset_reshaped = true
|
||||||
|
tileset_deleted.emit()
|
||||||
|
if _flag_tileset_created:
|
||||||
|
_flag_tileset_created = false
|
||||||
|
_flag_tileset_reshaped = true
|
||||||
|
tileset_created.emit()
|
||||||
|
if _flag_tileset_resized:
|
||||||
|
_flag_tileset_resized = false
|
||||||
|
tileset_resized.emit()
|
||||||
|
if _flag_tileset_reshaped:
|
||||||
|
_flag_tileset_reshaped = false
|
||||||
|
_flag_terrains_changed = true
|
||||||
|
tileset_reshaped.emit()
|
||||||
|
if _flag_atlas_added:
|
||||||
|
_flag_atlas_added = false
|
||||||
|
_flag_terrains_changed = true
|
||||||
|
if _flag_terrains_changed:
|
||||||
|
_flag_terrains_changed = false
|
||||||
|
terrains_changed.emit()
|
||||||
|
|
||||||
|
|
||||||
|
## Check if tile_set has been added, replaced, or deleted.
|
||||||
|
func check_tile_set(tile_set: TileSet) -> void:
|
||||||
|
if tile_set == self.tile_set:
|
||||||
|
return
|
||||||
|
if self.tile_set != null:
|
||||||
|
self.tile_set.changed.disconnect(_set_tileset_changed)
|
||||||
|
_cached_source_count = 0
|
||||||
|
_cached_sids.clear()
|
||||||
|
_flag_tileset_deleted = true
|
||||||
|
self.tile_set = tile_set
|
||||||
|
if self.tile_set != null:
|
||||||
|
self.tile_set.changed.connect(_set_tileset_changed, 1)
|
||||||
|
self.tile_set.emit_changed()
|
||||||
|
_flag_tileset_created = true
|
||||||
|
emit_changed()
|
||||||
|
|
||||||
|
|
||||||
|
func _atlas_added(_source_id: int, _atlas: TileSetAtlasSource) -> void:
|
||||||
|
_flag_atlas_added = true
|
||||||
|
# print('SIGNAL EMITTED: atlas_added(%s)' % {'source_id': _source_id, 'atlas': _atlas})
|
||||||
|
|
||||||
|
|
||||||
|
## Helper method to be called when the tile_set detects a change.
|
||||||
|
## Must be disconnected when the tile_set is changed.
|
||||||
|
func _set_tileset_changed() -> void:
|
||||||
|
_flag_tileset_changed = true
|
||||||
|
|
||||||
|
|
||||||
|
## Called when _flag_tileset_changed.
|
||||||
|
## Provides more detail about what changed.
|
||||||
|
func _update_tileset() -> void:
|
||||||
|
var tile_size = tile_set.tile_size
|
||||||
|
if self.tile_size != tile_size:
|
||||||
|
self.tile_size = tile_size
|
||||||
|
_flag_tileset_resized = true
|
||||||
|
var grid_shape = Display.tileset_gridshape(tile_set)
|
||||||
|
if self.grid_shape != grid_shape:
|
||||||
|
self.grid_shape = grid_shape
|
||||||
|
_flag_tileset_reshaped = true
|
||||||
|
_update_tileset_atlases()
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: detect automatic tile creation
|
||||||
|
## Checks if new atlases have been added.
|
||||||
|
## Does not check which ones were deleted.
|
||||||
|
func _update_tileset_atlases() -> void:
|
||||||
|
# Update all tileset sources
|
||||||
|
var source_count: int = tile_set.get_source_count()
|
||||||
|
|
||||||
|
# Only if an asset was added or removed
|
||||||
|
# FIXME?: may break on add+remove in 1 frame
|
||||||
|
if _cached_source_count == source_count:
|
||||||
|
return
|
||||||
|
_cached_source_count = source_count
|
||||||
|
|
||||||
|
# Process the new atlases in the TileSet
|
||||||
|
var sids: Dictionary[int, AtlasWatcher] = { }
|
||||||
|
for i in source_count:
|
||||||
|
var sid: int = tile_set.get_source_id(i)
|
||||||
|
if sid in _cached_sids:
|
||||||
|
sids[sid] = _cached_sids[sid]
|
||||||
|
continue
|
||||||
|
var source: TileSetSource = tile_set.get_source(sid)
|
||||||
|
if source is not TileSetAtlasSource:
|
||||||
|
push_warning(
|
||||||
|
"Non-Atlas TileSet found at index %i, source id %i.\n" % [i, source] +
|
||||||
|
"Dual Grids only support Atlas TileSets.",
|
||||||
|
)
|
||||||
|
sids[sid] = null
|
||||||
|
continue
|
||||||
|
var atlas: TileSetAtlasSource = source
|
||||||
|
# FIXME?: check if this needs to be disconnected
|
||||||
|
# SETUP:
|
||||||
|
# - add logging to check which Watcher's flag was changed
|
||||||
|
# - add a TileSet with an atlas to 2 TileMapDuals
|
||||||
|
# - remove the TileSet
|
||||||
|
# - modify the terrains on one of the atlases
|
||||||
|
# - check how many watchers were flagged:
|
||||||
|
# - if 2 watchers were flagged, this is bad.
|
||||||
|
# try to repeatedly add and remove the tileset.
|
||||||
|
# this could either cause the flag to happen multiple times,
|
||||||
|
# or it could stay at 2 watchers.
|
||||||
|
# - if 1 watcher was flagged, that is ok
|
||||||
|
sids[sid] = AtlasWatcher.new(self, sid, atlas)
|
||||||
|
atlas_added.emit(sid, atlas)
|
||||||
|
_flag_terrains_changed = true
|
||||||
|
# FIXME?: find which sid's were deleted
|
||||||
|
_cached_sids = sids
|
||||||
1
addons/TileMapDual/tile_set_watcher.gd.uid
Normal file
1
addons/TileMapDual/tile_set_watcher.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bjmo6oy8a4k2k
|
||||||
61
addons/TileMapDual/util.gd
Normal file
61
addons/TileMapDual/util.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
class_name Util
|
||||||
|
## Utility functions.
|
||||||
|
|
||||||
|
|
||||||
|
## Merges an Array of keys and an Array of values into a Dictionary.
|
||||||
|
static func arrays_to_dict(keys: Array, values: Array) -> Dictionary:
|
||||||
|
var out := { }
|
||||||
|
for i in keys.size():
|
||||||
|
out[keys[i]] = values[i]
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
## Swaps the X and Y axes of a Vector2i.
|
||||||
|
static func transpose_vec(v: Vector2i) -> Vector2i:
|
||||||
|
return Vector2i(v.y, v.x)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: transposed(TileSet.CellNeighbor) -> Tileset.CellNeighbor
|
||||||
|
## Reverses the direction of a CellNeighbor.
|
||||||
|
static func reverse_neighbor(neighbor: TileSet.CellNeighbor) -> TileSet.CellNeighbor:
|
||||||
|
return (neighbor + 8) % 16
|
||||||
|
|
||||||
|
|
||||||
|
## Returns a shorthand name for a CellNeighbor.
|
||||||
|
static func neighbor_name(neighbor: TileSet.CellNeighbor) -> String:
|
||||||
|
const DIRECTIONS := ['E', 'SE', 'S', 'SW', 'W', 'NW', 'N', 'NE']
|
||||||
|
return DIRECTIONS[neighbor >> 1]
|
||||||
|
|
||||||
|
|
||||||
|
## Returns a pretty-printable neighborhood.
|
||||||
|
static func neighborhood_str(neighborhood: Array) -> String:
|
||||||
|
var neighbors := array_of(-1, 16)
|
||||||
|
for i in neighborhood.size():
|
||||||
|
neighbors[neighborhood[i]] = i
|
||||||
|
|
||||||
|
var get := func(neighbor: TileSet.CellNeighbor) -> String:
|
||||||
|
var terrain = neighbors[neighbor]
|
||||||
|
return '-' if terrain == -1 else str(terrain)
|
||||||
|
|
||||||
|
var nw = get.call(TileSet.CELL_NEIGHBOR_TOP_LEFT_CORNER)
|
||||||
|
var n = get.call(TileSet.CELL_NEIGHBOR_TOP_CORNER)
|
||||||
|
var ne = get.call(TileSet.CELL_NEIGHBOR_TOP_RIGHT_CORNER)
|
||||||
|
var w = get.call(TileSet.CELL_NEIGHBOR_LEFT_CORNER)
|
||||||
|
var e = get.call(TileSet.CELL_NEIGHBOR_RIGHT_CORNER)
|
||||||
|
var sw = get.call(TileSet.CELL_NEIGHBOR_BOTTOM_LEFT_CORNER)
|
||||||
|
var s = get.call(TileSet.CELL_NEIGHBOR_BOTTOM_CORNER)
|
||||||
|
var se = get.call(TileSet.CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER)
|
||||||
|
|
||||||
|
return (
|
||||||
|
"%2s %2s %2s\n" % [nw, n, ne] +
|
||||||
|
"%2s C %2s\n" % [w, e] +
|
||||||
|
"%2s %2s %2s\n" % [sw, s, se]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
## Returns an Array of the given size, all filled with the given value.
|
||||||
|
static func array_of(value: Variant, size: int) -> Array[Variant]:
|
||||||
|
var out := []
|
||||||
|
out.resize(size)
|
||||||
|
out.fill(value)
|
||||||
|
return out
|
||||||
1
addons/TileMapDual/util.gd.uid
Normal file
1
addons/TileMapDual/util.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bfbksxcjuwdjt
|
||||||
|
|
@ -21,12 +21,11 @@ import/import_plugin/default_automatic_importer="Static Texture"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
window/size/viewport_width=450
|
window/size/viewport_width=640
|
||||||
window/size/viewport_height=360
|
window/size/viewport_height=360
|
||||||
window/size/window_width_override=900
|
window/size/window_width_override=1280
|
||||||
window/size/window_height_override=720
|
window/size/window_height_override=720
|
||||||
window/stretch/mode="viewport"
|
window/stretch/mode="viewport"
|
||||||
window/stretch/aspect="keep_height"
|
|
||||||
window/vsync/vsync_mode=3
|
window/vsync/vsync_mode=3
|
||||||
|
|
||||||
[dotnet]
|
[dotnet]
|
||||||
|
|
@ -35,7 +34,7 @@ project/assembly_name="Dancer"
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
enabled=PackedStringArray("res://addons/AsepriteWizard/plugin.cfg")
|
enabled=PackedStringArray("res://addons/AsepriteWizard/plugin.cfg", "res://addons/TileMapDual/plugin.cfg")
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
|
@ -100,4 +99,5 @@ textures/canvas_textures/default_texture_filter=0
|
||||||
rendering_device/driver.windows="d3d12"
|
rendering_device/driver.windows="d3d12"
|
||||||
renderer/rendering_method="gl_compatibility"
|
renderer/rendering_method="gl_compatibility"
|
||||||
renderer/rendering_method.mobile="gl_compatibility"
|
renderer/rendering_method.mobile="gl_compatibility"
|
||||||
|
environment/defaults/default_clear_color=Color(0.063487835, 0.09127209, 0.12370577, 1)
|
||||||
2d/snap/snap_2d_transforms_to_pixel=true
|
2d/snap/snap_2d_transforms_to_pixel=true
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Dancer;
|
namespace Dancer;
|
||||||
|
|
||||||
[Meta(typeof(IAutoNode))]
|
[Meta(typeof(IAutoNode)), Tool]
|
||||||
public sealed partial class Hitbox : Area2D
|
public sealed partial class Hitbox : Area2D
|
||||||
{
|
{
|
||||||
public override void _Notification(int what) => this.Notify(what);
|
public override void _Notification(int what) => this.Notify(what);
|
||||||
|
|
@ -12,7 +12,8 @@ public sealed partial class Hitbox : Area2D
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
[Export(PropertyHint.None, "suffix:s")]
|
||||||
private float LocalImmunity { get; set; }
|
private float LocalImmunity { get; set; }
|
||||||
private int LocalCountLimit { get; set; } = 1000;
|
[Export]
|
||||||
|
private int LocalCountLimit { get; set; } = 1;
|
||||||
|
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void BodyHitEventHandler(Hitbox hitbox, Node2D body);
|
public delegate void BodyHitEventHandler(Hitbox hitbox, Node2D body);
|
||||||
|
|
@ -22,6 +23,7 @@ public sealed partial class Hitbox : Area2D
|
||||||
|
|
||||||
public void OnResolved()
|
public void OnResolved()
|
||||||
{
|
{
|
||||||
|
ProcessMode = ProcessModeEnum.Disabled;
|
||||||
BodyEntered += OnEntered;
|
BodyEntered += OnEntered;
|
||||||
HitboxOwner.OnHitboxAdded(this);
|
HitboxOwner.OnHitboxAdded(this);
|
||||||
}
|
}
|
||||||
|
|
@ -59,6 +61,20 @@ public sealed partial class Hitbox : Area2D
|
||||||
entry.Immunity = Mathf.Max(0f, entry.Immunity);
|
entry.Immunity = Mathf.Max(0f, entry.Immunity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void StartAttack()
|
||||||
|
{
|
||||||
|
if (Engine.IsEditorHint()) Visible = true;
|
||||||
|
ProcessMode = ProcessModeEnum.Inherit;
|
||||||
|
foreach (var immunityEntry in _immunityEntries.Values)
|
||||||
|
immunityEntry.HitCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StopAttack()
|
||||||
|
{
|
||||||
|
if (Engine.IsEditorHint()) Visible = false;
|
||||||
|
ProcessMode = ProcessModeEnum.Disabled;
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class ImmunityEntry
|
private sealed class ImmunityEntry
|
||||||
{
|
{
|
||||||
public float Immunity { get; set; }
|
public float Immunity { get; set; }
|
||||||
|
|
|
||||||
12
src/combat/hitbox.tscn
Normal file
12
src/combat/hitbox.tscn
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
[gd_scene format=3 uid="uid://cva3ecq7vp3a4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="1_cask4"]
|
||||||
|
|
||||||
|
[node name="Hitbox" type="Area2D" unique_id=1918418417]
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 4
|
||||||
|
script = ExtResource("1_cask4")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=2048987579]
|
||||||
|
disabled = true
|
||||||
|
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||||
Binary file not shown.
|
|
@ -5,11 +5,9 @@
|
||||||
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="3_bu42x"]
|
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="3_bu42x"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8bh2b"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8bh2b"]
|
||||||
size = Vector2(22, 4)
|
size = Vector2(34, 2)
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_feb5d"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_feb5d"]
|
||||||
radius = 5.0
|
|
||||||
height = 14.0
|
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_lyo8d"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_lyo8d"]
|
||||||
radius = 60.0
|
radius = 60.0
|
||||||
|
|
@ -50,18 +48,6 @@ tracks/1/keys = {
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0]
|
"values": [0]
|
||||||
}
|
}
|
||||||
tracks/2/type = "value"
|
|
||||||
tracks/2/imported = false
|
|
||||||
tracks/2/enabled = true
|
|
||||||
tracks/2/path = NodePath("Body/StabHitbox/CollisionShape2D:disabled")
|
|
||||||
tracks/2/interp = 1
|
|
||||||
tracks/2/loop_wrap = true
|
|
||||||
tracks/2/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 1,
|
|
||||||
"values": [true]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_ba6cv"]
|
[sub_resource type="Animation" id="Animation_ba6cv"]
|
||||||
resource_name = "idle"
|
resource_name = "idle"
|
||||||
|
|
@ -122,8 +108,8 @@ tracks/1/keys = {
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_3ly8m"]
|
[sub_resource type="Animation" id="Animation_3ly8m"]
|
||||||
resource_name = "stab"
|
resource_name = "stab"
|
||||||
length = 0.9
|
length = 0.8333333
|
||||||
step = 0.1
|
step = 0.016666668
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
|
|
@ -143,10 +129,10 @@ tracks/1/path = NodePath("Body:frame")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
"times": PackedFloat32Array(0, 0.1, 0.5),
|
"times": PackedFloat32Array(0, 0.1, 0.5, 0.55, 0.6333333),
|
||||||
"transitions": PackedFloat32Array(1, 1, 1),
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0, 1, 2]
|
"values": [0, 1, 2, 3, 4]
|
||||||
}
|
}
|
||||||
tracks/2/type = "method"
|
tracks/2/type = "method"
|
||||||
tracks/2/imported = false
|
tracks/2/imported = false
|
||||||
|
|
@ -155,24 +141,29 @@ tracks/2/path = NodePath(".")
|
||||||
tracks/2/interp = 1
|
tracks/2/interp = 1
|
||||||
tracks/2/loop_wrap = true
|
tracks/2/loop_wrap = true
|
||||||
tracks/2/keys = {
|
tracks/2/keys = {
|
||||||
"times": PackedFloat32Array(0.9),
|
"times": PackedFloat32Array(0.8333333),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"values": [{
|
"values": [{
|
||||||
"args": [],
|
"args": [],
|
||||||
"method": &"OnAttackFinished"
|
"method": &"OnAttackFinished"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
tracks/3/type = "value"
|
tracks/3/type = "method"
|
||||||
tracks/3/imported = false
|
tracks/3/imported = false
|
||||||
tracks/3/enabled = true
|
tracks/3/enabled = true
|
||||||
tracks/3/path = NodePath("Body/StabHitbox/CollisionShape2D:disabled")
|
tracks/3/path = NodePath("Body/StabHitbox")
|
||||||
tracks/3/interp = 1
|
tracks/3/interp = 1
|
||||||
tracks/3/loop_wrap = true
|
tracks/3/loop_wrap = true
|
||||||
tracks/3/keys = {
|
tracks/3/keys = {
|
||||||
"times": PackedFloat32Array(0, 0.5, 0.7),
|
"times": PackedFloat32Array(0.5, 0.6333333),
|
||||||
"transitions": PackedFloat32Array(1, 1, 1),
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
"update": 1,
|
"values": [{
|
||||||
"values": [true, false, true]
|
"args": [],
|
||||||
|
"method": &"StartAttack"
|
||||||
|
}, {
|
||||||
|
"args": [],
|
||||||
|
"method": &"StopAttack"
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1i6dk"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_1i6dk"]
|
||||||
|
|
@ -186,10 +177,12 @@ _data = {
|
||||||
[node name="Birb" type="CharacterBody2D" unique_id=428810294]
|
[node name="Birb" type="CharacterBody2D" unique_id=428810294]
|
||||||
collision_layer = 4
|
collision_layer = 4
|
||||||
script = ExtResource("1_lyo8d")
|
script = ExtResource("1_lyo8d")
|
||||||
|
AttackDistance = 45.0
|
||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="Body" type="AnimatedSprite2D" parent="." unique_id=581143480]
|
[node name="Body" type="AnimatedSprite2D" parent="." unique_id=581143480]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
position = Vector2(7, -20)
|
||||||
sprite_frames = ExtResource("2_ba6cv")
|
sprite_frames = ExtResource("2_ba6cv")
|
||||||
animation = &"idle"
|
animation = &"idle"
|
||||||
offset = Vector2(9, -4)
|
offset = Vector2(9, -4)
|
||||||
|
|
@ -201,16 +194,17 @@ collision_mask = 2
|
||||||
script = ExtResource("3_bu42x")
|
script = ExtResource("3_bu42x")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/StabHitbox" unique_id=1331922714]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/StabHitbox" unique_id=1331922714]
|
||||||
position = Vector2(11, 2)
|
position = Vector2(19, 9)
|
||||||
shape = SubResource("RectangleShape2D_8bh2b")
|
shape = SubResource("RectangleShape2D_8bh2b")
|
||||||
disabled = true
|
debug_color = Color(0.99607843, 0, 0.23137255, 0.41960785)
|
||||||
debug_color = Color(0.8758822, 0.3187781, 0.34832907, 0.41960785)
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1744954023]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1744954023]
|
||||||
position = Vector2(0, 1)
|
position = Vector2(0, -15)
|
||||||
shape = SubResource("CapsuleShape2D_feb5d")
|
shape = SubResource("CapsuleShape2D_feb5d")
|
||||||
|
|
||||||
[node name="Detection" type="Area2D" parent="." unique_id=151830843]
|
[node name="Detection" type="Area2D" parent="." unique_id=151830843]
|
||||||
|
visible = false
|
||||||
|
position = Vector2(0, -22)
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 2
|
collision_mask = 2
|
||||||
monitorable = false
|
monitorable = false
|
||||||
|
|
@ -220,12 +214,13 @@ shape = SubResource("CircleShape2D_lyo8d")
|
||||||
debug_color = Color(0, 0.6, 0.69803923, 0.16862746)
|
debug_color = Color(0, 0.6, 0.69803923, 0.16862746)
|
||||||
|
|
||||||
[node name="Chase" type="Area2D" parent="." unique_id=172000915]
|
[node name="Chase" type="Area2D" parent="." unique_id=172000915]
|
||||||
|
visible = false
|
||||||
|
position = Vector2(0, -22)
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 2
|
collision_mask = 2
|
||||||
monitorable = false
|
monitorable = false
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Chase" unique_id=567870323]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Chase" unique_id=567870323]
|
||||||
position = Vector2(-1, 0)
|
|
||||||
shape = SubResource("CircleShape2D_ba6cv")
|
shape = SubResource("CircleShape2D_ba6cv")
|
||||||
debug_color = Color(0, 0.6, 0.69803923, 0)
|
debug_color = Color(0, 0.6, 0.69803923, 0)
|
||||||
|
|
||||||
|
|
@ -235,9 +230,9 @@ anchors_preset = 5
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_right = 0.5
|
anchor_right = 0.5
|
||||||
offset_left = -10.0
|
offset_left = -10.0
|
||||||
offset_top = -12.0
|
offset_top = -35.0
|
||||||
offset_right = 10.0
|
offset_right = 10.0
|
||||||
offset_bottom = -10.0
|
offset_bottom = -33.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
theme_override_styles/background = SubResource("StyleBoxFlat_lyo8d")
|
theme_override_styles/background = SubResource("StyleBoxFlat_lyo8d")
|
||||||
theme_override_styles/fill = SubResource("StyleBoxFlat_ba6cv")
|
theme_override_styles/fill = SubResource("StyleBoxFlat_ba6cv")
|
||||||
|
|
|
||||||
236
src/game.tscn
236
src/game.tscn
File diff suppressed because one or more lines are too long
BIN
src/level/background.aseprite
(Stored with Git LFS)
Normal file
BIN
src/level/background.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/level/background.aseprite.import
Normal file
21
src/level/background.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://cbjps58vfmyeb"
|
||||||
|
path="res://.godot/imported/background.aseprite-16e00d362c23a39a421f665d96ce4601.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/level/background.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/background.aseprite-16e00d362c23a39a421f665d96ce4601.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
BIN
src/level/neon_box.aseprite
(Stored with Git LFS)
Normal file
BIN
src/level/neon_box.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/level/neon_box.aseprite.import
Normal file
21
src/level/neon_box.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://b0grslwquoxek"
|
||||||
|
path="res://.godot/imported/neon_box.aseprite-fb78d07d04f567fce9d25f6697873e5a.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/level/neon_box.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/neon_box.aseprite-fb78d07d04f567fce9d25f6697873e5a.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
BIN
src/level/neon_box_selector.aseprite
(Stored with Git LFS)
Normal file
BIN
src/level/neon_box_selector.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/level/neon_box_selector.aseprite.import
Normal file
21
src/level/neon_box_selector.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://dg5wulm2tav4t"
|
||||||
|
path="res://.godot/imported/neon_box_selector.aseprite-715dec900389455a0fc3afc6a5726980.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/level/neon_box_selector.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/neon_box_selector.aseprite-715dec900389455a0fc3afc6a5726980.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
BIN
src/level/tiles.aseprite
(Stored with Git LFS)
Normal file
BIN
src/level/tiles.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/level/tiles.aseprite.import
Normal file
21
src/level/tiles.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://d2m74vkdtcimf"
|
||||||
|
path="res://.godot/imported/tiles.aseprite-310a34210037ec686e073a30d5adba8f.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/level/tiles.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/tiles.aseprite-310a34210037ec686e073a30d5adba8f.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
19
src/level/tiles.gdshader
Normal file
19
src/level/tiles.gdshader
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
shader_type canvas_item;
|
||||||
|
|
||||||
|
uniform sampler2D emissive :
|
||||||
|
hint_default_transparent, source_color, filter_nearest;
|
||||||
|
|
||||||
|
void vertex() {}
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
COLOR.rgb = vec3(texture_sdf(screen_uv_to_sdf(SCREEN_UV))/10.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void light() {
|
||||||
|
// Called for every pixel for every light affecting the CanvasItem.
|
||||||
|
// Uncomment to replace the default light processing function with this one.
|
||||||
|
LIGHT = vec4(LIGHT_COLOR.rgb * COLOR.rgb * LIGHT_ENERGY, LIGHT_COLOR.a);
|
||||||
|
LIGHT = vec4(0.1);
|
||||||
|
//LIGHT = vec4(1, 1, 1, 1);
|
||||||
|
//SHADOW_MODULATE = vec4(1, 1, 1, 1);
|
||||||
|
}
|
||||||
1
src/level/tiles.gdshader.uid
Normal file
1
src/level/tiles.gdshader.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cv1vyt3ex306g
|
||||||
Binary file not shown.
|
|
@ -1,21 +0,0 @@
|
||||||
[remap]
|
|
||||||
|
|
||||||
importer="aseprite_wizard.plugin.static-texture"
|
|
||||||
type="PortableCompressedTexture2D"
|
|
||||||
uid="uid://dkxcdqm8dgdq7"
|
|
||||||
path="res://.godot/imported/tiles_0.aseprite-88b641c9e3407952b30dd9ebb5ab058f.res"
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://src/level/tiles_0.aseprite"
|
|
||||||
dest_files=["res://.godot/imported/tiles_0.aseprite-88b641c9e3407952b30dd9ebb5ab058f.res"]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
layer/exclude_layers_pattern=""
|
|
||||||
layer/only_visible_layers=false
|
|
||||||
layer/split_layers=false
|
|
||||||
first_frame_only=true
|
|
||||||
sheet/sheet_type="packed"
|
|
||||||
sheet/sheet_columns=16
|
|
||||||
sheet/scale=1
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Dancer;
|
namespace Dancer;
|
||||||
|
|
||||||
[Meta(typeof(IAutoNode))]
|
[Meta(typeof(IAutoNode))]
|
||||||
public sealed partial class Player : CharacterBody2D, IAttackable
|
public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner, IProvide<IHitboxOwner>
|
||||||
{
|
{
|
||||||
public override void _Notification(int what) => this.Notify(what);
|
public override void _Notification(int what) => this.Notify(what);
|
||||||
|
|
||||||
|
|
@ -21,13 +20,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
|
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s")]
|
[Export(PropertyHint.None, "suffix:px/s")]
|
||||||
public float WalkMaxSpeed { get; set; } = 110.0f;
|
public float WalkMaxSpeed { get; set; } = 130.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||||
public float WalkAccel { get; set; } = 600.0f;
|
public float WalkAccel { get; set; } = 900.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||||
public float AirAccel { get; set; } = 180.0f;
|
public float AirAccel { get; set; } = 210.0f;
|
||||||
|
|
||||||
[Export(PropertyHint.None, "suffix:s")]
|
[Export(PropertyHint.None, "suffix:s")]
|
||||||
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
||||||
|
|
@ -50,23 +49,24 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
public float DownInputAngle { get; set; } = Mathf.Pi / 4;
|
public float DownInputAngle { get; set; } = Mathf.Pi / 4;
|
||||||
|
|
||||||
[Export] public float MaxHealth { get; set; } = 5f;
|
[Export] public float MaxHealth { get; set; } = 5f;
|
||||||
public float Health { get; set; }
|
[Export] public float Health { get; set; }
|
||||||
|
[Export] public bool CanTurn { get; set; } = true;
|
||||||
|
|
||||||
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
||||||
|
|
||||||
private float _jumpAscentRemainingTime;
|
private float _jumpAscentRemainingTime;
|
||||||
private bool _isJumping;
|
private bool _isJumping;
|
||||||
private float _jumpAllowedTime;
|
private float _jumpAllowedTime;
|
||||||
private Vector2 _currentDirection = Vector2.Zero;
|
private Vector2 _currentDirection = Vector2.Zero;
|
||||||
private bool _isFacingRight = true;
|
private bool _isFacingRight = true;
|
||||||
|
|
||||||
private AnimationNodeStateMachinePlayback _playback = null!;
|
private AnimationNodeStateMachinePlayback _playback = null!;
|
||||||
private List<BufferedInput> _inputBuffer = [];
|
private List<BufferedInput> _inputBuffer = [];
|
||||||
|
|
||||||
[Node] private AnimationTree AnimationTree { get; set; } = null!;
|
[Node] private AnimationTree AnimationTree { get; set; } = null!;
|
||||||
|
|
||||||
public override void _Ready()
|
public void OnReady()
|
||||||
{
|
{
|
||||||
|
this.Provide();
|
||||||
|
SetPhysicsProcess(true);
|
||||||
Health = MaxHealth;
|
Health = MaxHealth;
|
||||||
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
|
_playback = AnimationTree.Get("parameters/playback").As<AnimationNodeStateMachinePlayback>();
|
||||||
}
|
}
|
||||||
|
|
@ -101,16 +101,13 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public void OnPhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
var deltaF = (float)delta;
|
var deltaF = (float)delta;
|
||||||
// Temporary copy of the velocity for easier editing.
|
// Temporary copy of the velocity for easier editing.
|
||||||
var velocity = Velocity;
|
var velocity = Velocity;
|
||||||
|
|
||||||
if (_currentDirection.X < 0)
|
if (CanTurn) AdjustFacing();
|
||||||
_isFacingRight = false;
|
|
||||||
else if (_currentDirection.X > 0)
|
|
||||||
_isFacingRight = true;
|
|
||||||
|
|
||||||
// Walking on the floor
|
// Walking on the floor
|
||||||
if (IsOnFloor())
|
if (IsOnFloor())
|
||||||
|
|
@ -171,6 +168,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AdjustFacing()
|
||||||
|
{
|
||||||
|
if (_currentDirection.X < 0)
|
||||||
|
_isFacingRight = false;
|
||||||
|
else if (_currentDirection.X > 0)
|
||||||
|
_isFacingRight = true;
|
||||||
|
}
|
||||||
|
|
||||||
private bool IsHoldingWall()
|
private bool IsHoldingWall()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
@ -199,15 +204,6 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
_inputBuffer.RemoveAt(0);
|
_inputBuffer.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
var inputBuffer = new StringBuilder();
|
|
||||||
foreach (var bufferedInput in _inputBuffer)
|
|
||||||
{
|
|
||||||
inputBuffer.Append($"{bufferedInput}, ");
|
|
||||||
}
|
|
||||||
|
|
||||||
GD.Print(inputBuffer);
|
|
||||||
}
|
|
||||||
// Check new commands
|
// Check new commands
|
||||||
for (var i = 0; i < _inputBuffer.Count; i++)
|
for (var i = 0; i < _inputBuffer.Count; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -236,7 +232,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
else if (input.Event.IsActionPressed("attack"))
|
else if (input.Event.IsActionPressed("attack"))
|
||||||
{
|
{
|
||||||
inputFound = true;
|
inputFound = true;
|
||||||
Slash();
|
Attack();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputFound)
|
if (inputFound)
|
||||||
|
|
@ -249,6 +245,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
|
|
||||||
private void GroundJump()
|
private void GroundJump()
|
||||||
{
|
{
|
||||||
|
AdjustFacing();
|
||||||
_jumpAllowedTime = 0.0f;
|
_jumpAllowedTime = 0.0f;
|
||||||
_jumpAscentRemainingTime = JumpAscentMaxTime;
|
_jumpAscentRemainingTime = JumpAscentMaxTime;
|
||||||
_isJumping = true;
|
_isJumping = true;
|
||||||
|
|
@ -256,6 +253,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
|
|
||||||
private void WallJump()
|
private void WallJump()
|
||||||
{
|
{
|
||||||
|
AdjustFacing();
|
||||||
_jumpAllowedTime = 0.0f;
|
_jumpAllowedTime = 0.0f;
|
||||||
Velocity += GetWallNormal() * 200.0f;
|
Velocity += GetWallNormal() * 200.0f;
|
||||||
Velocity = Velocity with { Y = Mathf.Min(0, Velocity.Y) };
|
Velocity = Velocity with { Y = Mathf.Min(0, Velocity.Y) };
|
||||||
|
|
@ -270,16 +268,11 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Slash()
|
private void Attack()
|
||||||
{
|
{
|
||||||
|
AdjustFacing();
|
||||||
Velocity += (_isFacingRight ? Vector2.Right : Vector2.Left) * SlashSpeedBoost;
|
Velocity += (_isFacingRight ? Vector2.Right : Vector2.Left) * SlashSpeedBoost;
|
||||||
_playback.Travel("attack");
|
_playback.Travel("front_kick");
|
||||||
|
|
||||||
var instance = GD.Load<PackedScene>("res://src/player/slash_projectile.tscn")
|
|
||||||
.Instantiate<SlashProjectile>();
|
|
||||||
AddChild(instance);
|
|
||||||
instance.GlobalTransform = GetNode<Node2D>("%HandAttachment").GlobalTransform;
|
|
||||||
instance.HitboxEntered += OnEnemyHit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsInputVecDown(Vector2 vec)
|
private bool IsInputVecDown(Vector2 vec)
|
||||||
|
|
@ -287,14 +280,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.1f;
|
return Mathf.Abs(vec.AngleTo(Vector2.Down)) < DownInputAngle && vec.Length() > 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEnemyHit(Node2D enemy)
|
private void OnEnemyHit(Hitbox hitbox, Node2D enemy)
|
||||||
{
|
{
|
||||||
if (enemy is not IAttackable attackable) return;
|
if (enemy is not IAttackable attackable) return;
|
||||||
attackable.GetAttacked(new()
|
attackable.GetAttacked(new()
|
||||||
{
|
{
|
||||||
Attacker = this,
|
Attacker = this,
|
||||||
Damage = 1.0f,
|
Damage = 1.0f,
|
||||||
Impulse = Vector2.Down * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f,
|
Impulse = Vector2.Up * 1000.0f + (enemy.Position - Position).Normalized() * 1000.0f,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -309,4 +302,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable
|
||||||
public required InputEvent Event { get; init; }
|
public required InputEvent Event { get; init; }
|
||||||
public ulong Time { get; init; }
|
public ulong Time { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnHitboxAdded(Hitbox hitbox) => hitbox.BodyHit += OnEnemyHit;
|
||||||
|
public void OnHitboxRemoved(Hitbox hitbox) => hitbox.BodyHit -= OnEnemyHit;
|
||||||
|
IHitboxOwner IProvide<IHitboxOwner>.Value() => this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
src/player/light.aseprite
(Stored with Git LFS)
Normal file
BIN
src/player/light.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/player/light.aseprite.import
Normal file
21
src/player/light.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://i6xi16yki1r5"
|
||||||
|
path="res://.godot/imported/light.aseprite-43635fe79226150b3143726afd3c6190.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/player/light.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/light.aseprite-43635fe79226150b3143726afd3c6190.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
Binary file not shown.
|
|
@ -16,6 +16,6 @@ layer/exclude_layers_pattern=""
|
||||||
layer/only_visible_layers=true
|
layer/only_visible_layers=true
|
||||||
layer/split_layers=false
|
layer/split_layers=false
|
||||||
first_frame_only=false
|
first_frame_only=false
|
||||||
sheet/sheet_type="horizontal"
|
sheet/sheet_type="columns"
|
||||||
sheet/sheet_columns=12
|
sheet/sheet_columns=8
|
||||||
sheet/scale=1
|
sheet/scale=1
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
[gd_scene format=3 uid="uid://ce2k04khaub8n"]
|
[gd_scene format=3 uid="uid://ce2k04khaub8n"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://b5iey2typf2tb" path="res://src/player/Player.cs" id="1_244u8"]
|
[ext_resource type="Script" uid="uid://b5iey2typf2tb" path="res://src/player/Player.cs" id="1_244u8"]
|
||||||
[ext_resource type="Script" uid="uid://bhijvek6js88u" path="res://src/spring/Spring2D.cs" id="2_mf2ua"]
|
|
||||||
[ext_resource type="Texture2D" uid="uid://d0dy3j0qdycqf" path="res://src/player/player.aseprite" id="2_yw30f"]
|
[ext_resource type="Texture2D" uid="uid://d0dy3j0qdycqf" path="res://src/player/player.aseprite" id="2_yw30f"]
|
||||||
[ext_resource type="Texture2D" uid="uid://blw6f2ktsrcmg" path="res://src/player/hair.aseprite" id="3_qjkh3"]
|
[ext_resource type="Texture2D" uid="uid://i6xi16yki1r5" path="res://src/player/light.aseprite" id="3_mf2ua"]
|
||||||
|
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="4_244u8"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_e2o6t"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jiejy"]
|
||||||
radius = 4.0
|
size = Vector2(10, 28)
|
||||||
height = 14.0
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_244u8"]
|
||||||
|
size = Vector2(27.5, 20)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5f2sf"]
|
||||||
|
size = Vector2(13.59375, 20)
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_yw30f"]
|
[sub_resource type="Animation" id="Animation_yw30f"]
|
||||||
resource_name = "RESET"
|
resource_name = "RESET"
|
||||||
|
|
@ -25,6 +30,112 @@ tracks/0/keys = {
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0]
|
"values": [0]
|
||||||
}
|
}
|
||||||
|
tracks/1/type = "value"
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/path = NodePath(".:CanTurn")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [true]
|
||||||
|
}
|
||||||
|
tracks/2/type = "value"
|
||||||
|
tracks/2/imported = false
|
||||||
|
tracks/2/enabled = true
|
||||||
|
tracks/2/path = NodePath("Body/FrontKick/CollisionShape2D:disabled")
|
||||||
|
tracks/2/interp = 1
|
||||||
|
tracks/2/loop_wrap = true
|
||||||
|
tracks/2/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [false]
|
||||||
|
}
|
||||||
|
tracks/3/type = "value"
|
||||||
|
tracks/3/imported = false
|
||||||
|
tracks/3/enabled = true
|
||||||
|
tracks/3/path = NodePath("Body/FrontKick/CollisionShape2D2:disabled")
|
||||||
|
tracks/3/interp = 1
|
||||||
|
tracks/3/loop_wrap = true
|
||||||
|
tracks/3/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [false]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_g6k8r"]
|
||||||
|
resource_name = "front_kick"
|
||||||
|
length = 0.55
|
||||||
|
step = 0.016666668
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Body:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.050000004, 0.116666675, 0.2, 0.28333333, 0.36666667, 0.45),
|
||||||
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [9, 10, 11, 12, 13, 14, 9]
|
||||||
|
}
|
||||||
|
tracks/1/type = "value"
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/path = NodePath(".:CanTurn")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PackedFloat32Array(0, 0.45),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [false, true]
|
||||||
|
}
|
||||||
|
tracks/2/type = "method"
|
||||||
|
tracks/2/imported = false
|
||||||
|
tracks/2/enabled = true
|
||||||
|
tracks/2/path = NodePath("Body/FrontKick")
|
||||||
|
tracks/2/interp = 1
|
||||||
|
tracks/2/loop_wrap = true
|
||||||
|
tracks/2/keys = {
|
||||||
|
"times": PackedFloat32Array(0.05, 0.36666667),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"values": [{
|
||||||
|
"args": [],
|
||||||
|
"method": &"StartAttack"
|
||||||
|
}, {
|
||||||
|
"args": [],
|
||||||
|
"method": &"StopAttack"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
tracks/3/type = "value"
|
||||||
|
tracks/3/imported = false
|
||||||
|
tracks/3/enabled = true
|
||||||
|
tracks/3/path = NodePath("Body/FrontKick/CollisionShape2D:disabled")
|
||||||
|
tracks/3/interp = 1
|
||||||
|
tracks/3/loop_wrap = true
|
||||||
|
tracks/3/keys = {
|
||||||
|
"times": PackedFloat32Array(0.050000004, 0.28333336),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [false, true]
|
||||||
|
}
|
||||||
|
tracks/4/type = "value"
|
||||||
|
tracks/4/imported = false
|
||||||
|
tracks/4/enabled = true
|
||||||
|
tracks/4/path = NodePath("Body/FrontKick/CollisionShape2D2:disabled")
|
||||||
|
tracks/4/interp = 1
|
||||||
|
tracks/4/loop_wrap = true
|
||||||
|
tracks/4/keys = {
|
||||||
|
"times": PackedFloat32Array(0.050000004, 0.20000002),
|
||||||
|
"transitions": PackedFloat32Array(1, 1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [true, false]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_qjkh3"]
|
[sub_resource type="Animation" id="Animation_qjkh3"]
|
||||||
resource_name = "idle"
|
resource_name = "idle"
|
||||||
|
|
@ -44,26 +155,9 @@ tracks/0/keys = {
|
||||||
"values": [0]
|
"values": [0]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_g6k8r"]
|
|
||||||
resource_name = "slash"
|
|
||||||
length = 0.20000167
|
|
||||||
step = 0.05
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("Body:frame")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 1,
|
|
||||||
"values": [6]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_boad6"]
|
[sub_resource type="Animation" id="Animation_boad6"]
|
||||||
resource_name = "walk"
|
resource_name = "run"
|
||||||
length = 0.400005
|
length = 0.8
|
||||||
loop_mode = 1
|
loop_mode = 1
|
||||||
step = 0.1
|
step = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
|
|
@ -73,10 +167,10 @@ tracks/0/path = NodePath("Body:frame")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3),
|
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
|
||||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0, 1, 2, 3]
|
"values": [1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_rgyib"]
|
[sub_resource type="Animation" id="Animation_rgyib"]
|
||||||
|
|
@ -100,20 +194,20 @@ tracks/0/keys = {
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_rgyib"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_rgyib"]
|
||||||
_data = {
|
_data = {
|
||||||
&"RESET": SubResource("Animation_yw30f"),
|
&"RESET": SubResource("Animation_yw30f"),
|
||||||
|
&"front_kick": SubResource("Animation_g6k8r"),
|
||||||
&"idle": SubResource("Animation_qjkh3"),
|
&"idle": SubResource("Animation_qjkh3"),
|
||||||
&"slash": SubResource("Animation_g6k8r"),
|
&"run": SubResource("Animation_boad6"),
|
||||||
&"walk": SubResource("Animation_boad6"),
|
|
||||||
&"wall_hold": SubResource("Animation_rgyib")
|
&"wall_hold": SubResource("Animation_rgyib")
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_qjkh3"]
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_qjkh3"]
|
||||||
animation = &"slash"
|
animation = &"front_kick"
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yw30f"]
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_yw30f"]
|
||||||
animation = &"idle"
|
animation = &"idle"
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g6k8r"]
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g6k8r"]
|
||||||
animation = &"walk"
|
animation = &"run"
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_boad6"]
|
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_boad6"]
|
||||||
animation = &"wall_hold"
|
animation = &"wall_hold"
|
||||||
|
|
@ -150,15 +244,15 @@ advance_expression = "not IsHoldingWall()"
|
||||||
|
|
||||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_yllr7"]
|
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_yllr7"]
|
||||||
allow_transition_to_self = true
|
allow_transition_to_self = true
|
||||||
states/attack/node = SubResource("AnimationNodeAnimation_qjkh3")
|
states/front_kick/node = SubResource("AnimationNodeAnimation_qjkh3")
|
||||||
states/attack/position = Vector2(604.5, 41.5)
|
states/front_kick/position = Vector2(604.5, 41.5)
|
||||||
states/idle/node = SubResource("AnimationNodeAnimation_yw30f")
|
states/idle/node = SubResource("AnimationNodeAnimation_yw30f")
|
||||||
states/idle/position = Vector2(428.5, 88.5)
|
states/idle/position = Vector2(428.5, 88.5)
|
||||||
states/walk/node = SubResource("AnimationNodeAnimation_g6k8r")
|
states/run/node = SubResource("AnimationNodeAnimation_g6k8r")
|
||||||
states/walk/position = Vector2(628.5, 203.5)
|
states/run/position = Vector2(628.5, 203.5)
|
||||||
states/wall_hold/node = SubResource("AnimationNodeAnimation_boad6")
|
states/wall_hold/node = SubResource("AnimationNodeAnimation_boad6")
|
||||||
states/wall_hold/position = Vector2(362.82965, 231.5)
|
states/wall_hold/position = Vector2(362.82965, 231.5)
|
||||||
transitions = ["attack", "idle", SubResource("AnimationNodeStateMachineTransition_boad6"), "idle", "attack", SubResource("AnimationNodeStateMachineTransition_rgyib"), "Start", "idle", SubResource("AnimationNodeStateMachineTransition_hg6s5"), "idle", "walk", SubResource("AnimationNodeStateMachineTransition_8t03j"), "walk", "idle", SubResource("AnimationNodeStateMachineTransition_2ieo8"), "walk", "attack", SubResource("AnimationNodeStateMachineTransition_ebec5"), "idle", "wall_hold", SubResource("AnimationNodeStateMachineTransition_yllr7"), "wall_hold", "idle", SubResource("AnimationNodeStateMachineTransition_kb6p2")]
|
transitions = ["front_kick", "idle", SubResource("AnimationNodeStateMachineTransition_boad6"), "idle", "front_kick", SubResource("AnimationNodeStateMachineTransition_rgyib"), "Start", "idle", SubResource("AnimationNodeStateMachineTransition_hg6s5"), "idle", "run", SubResource("AnimationNodeStateMachineTransition_8t03j"), "run", "idle", SubResource("AnimationNodeStateMachineTransition_2ieo8"), "run", "front_kick", SubResource("AnimationNodeStateMachineTransition_ebec5"), "idle", "wall_hold", SubResource("AnimationNodeStateMachineTransition_yllr7"), "wall_hold", "idle", SubResource("AnimationNodeStateMachineTransition_kb6p2")]
|
||||||
graph_offset = Vector2(-59.670364, -27)
|
graph_offset = Vector2(-59.670364, -27)
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
[node name="Player" type="CharacterBody2D" unique_id=500011307]
|
||||||
|
|
@ -170,17 +264,26 @@ floor_max_angle = 0.24783675
|
||||||
script = ExtResource("1_244u8")
|
script = ExtResource("1_244u8")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=84142517]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=84142517]
|
||||||
position = Vector2(0, 1)
|
position = Vector2(0, -14)
|
||||||
shape = SubResource("CapsuleShape2D_e2o6t")
|
shape = SubResource("RectangleShape2D_jiejy")
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="." unique_id=1975474809]
|
[node name="Camera2D" type="Camera2D" parent="." unique_id=1975474809]
|
||||||
|
position = Vector2(0, -16)
|
||||||
process_callback = 0
|
process_callback = 0
|
||||||
limit_enabled = false
|
limit_enabled = false
|
||||||
|
|
||||||
|
[node name="PointLight2D" type="PointLight2D" parent="." unique_id=1795955896]
|
||||||
|
position = Vector2(0, -16)
|
||||||
|
energy = 0.1
|
||||||
|
shadow_color = Color(0, 0, 0, 1)
|
||||||
|
texture = ExtResource("3_mf2ua")
|
||||||
|
|
||||||
[node name="Body" type="Sprite2D" parent="." unique_id=567060128]
|
[node name="Body" type="Sprite2D" parent="." unique_id=567060128]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
texture = ExtResource("2_yw30f")
|
texture = ExtResource("2_yw30f")
|
||||||
hframes = 7
|
offset = Vector2(0, -24)
|
||||||
|
hframes = 8
|
||||||
|
vframes = 2
|
||||||
metadata/_aseprite_wizard_interface_config_ = {
|
metadata/_aseprite_wizard_interface_config_ = {
|
||||||
"animation_section": false,
|
"animation_section": false,
|
||||||
"layer_section": false,
|
"layer_section": false,
|
||||||
|
|
@ -211,23 +314,34 @@ metadata/_aseprite_wizard_config_ = {
|
||||||
}
|
}
|
||||||
metadata/_aseprite_wizard_source_file_hash_ = "61168df4a163c039cfaab97f4fccb905"
|
metadata/_aseprite_wizard_source_file_hash_ = "61168df4a163c039cfaab97f4fccb905"
|
||||||
|
|
||||||
[node name="Spring2D" type="Node2D" parent="Body" unique_id=1050714188]
|
|
||||||
show_behind_parent = true
|
|
||||||
script = ExtResource("2_mf2ua")
|
|
||||||
|
|
||||||
[node name="Hair" type="Sprite2D" parent="Body/Spring2D" unique_id=796557000]
|
|
||||||
position = Vector2(-2, 2)
|
|
||||||
texture = ExtResource("3_qjkh3")
|
|
||||||
|
|
||||||
[node name="HandAttachment" type="Node2D" parent="Body" unique_id=1002134601]
|
[node name="HandAttachment" type="Node2D" parent="Body" unique_id=1002134601]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
position = Vector2(3, 2)
|
position = Vector2(0, -14)
|
||||||
|
|
||||||
|
[node name="FrontKick" type="Area2D" parent="Body" unique_id=1918418417]
|
||||||
|
process_mode = 4
|
||||||
|
visible = false
|
||||||
|
position = Vector2(0, -16)
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 4
|
||||||
|
script = ExtResource("4_244u8")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="Body/FrontKick" unique_id=2048987579]
|
||||||
|
position = Vector2(5, 7)
|
||||||
|
shape = SubResource("RectangleShape2D_244u8")
|
||||||
|
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||||
|
|
||||||
|
[node name="CollisionShape2D2" type="CollisionShape2D" parent="Body/FrontKick" unique_id=734742131]
|
||||||
|
position = Vector2(16, -2)
|
||||||
|
shape = SubResource("RectangleShape2D_5f2sf")
|
||||||
|
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1251324400]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1251324400]
|
||||||
libraries/ = SubResource("AnimationLibrary_rgyib")
|
libraries/ = SubResource("AnimationLibrary_rgyib")
|
||||||
|
|
||||||
[node name="AnimationTree" type="AnimationTree" parent="AnimationPlayer" unique_id=1839424284]
|
[node name="AnimationTree" type="AnimationTree" parent="AnimationPlayer" unique_id=1839424284]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
deterministic = false
|
||||||
root_node = NodePath("%AnimationTree/../..")
|
root_node = NodePath("%AnimationTree/../..")
|
||||||
tree_root = SubResource("AnimationNodeStateMachine_yllr7")
|
tree_root = SubResource("AnimationNodeStateMachine_yllr7")
|
||||||
advance_expression_base_node = NodePath("../..")
|
advance_expression_base_node = NodePath("../..")
|
||||||
|
|
|
||||||
BIN
src/player/player_old.aseprite
(Stored with Git LFS)
Normal file
BIN
src/player/player_old.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/player/player_old.aseprite.import
Normal file
21
src/player/player_old.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://ddaoshqpfh1t4"
|
||||||
|
path="res://.godot/imported/player_old.aseprite-47ad749bdb952bbe0ea8d9f38e3427b5.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/player/player_old.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/player_old.aseprite-47ad749bdb952bbe0ea8d9f38e3427b5.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
BIN
src/player/player_tiny.aseprite
(Stored with Git LFS)
Normal file
BIN
src/player/player_tiny.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
21
src/player/player_tiny.aseprite.import
Normal file
21
src/player/player_tiny.aseprite.import
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="aseprite_wizard.plugin.static-texture"
|
||||||
|
type="PortableCompressedTexture2D"
|
||||||
|
uid="uid://nwgwml48hdv"
|
||||||
|
path="res://.godot/imported/player_tiny.aseprite-d334ea88c331655ae2e03f376620970f.res"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://src/player/player_tiny.aseprite"
|
||||||
|
dest_files=["res://.godot/imported/player_tiny.aseprite-d334ea88c331655ae2e03f376620970f.res"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
layer/exclude_layers_pattern=""
|
||||||
|
layer/only_visible_layers=false
|
||||||
|
layer/split_layers=false
|
||||||
|
first_frame_only=true
|
||||||
|
sheet/sheet_type="packed"
|
||||||
|
sheet/sheet_columns=12
|
||||||
|
sheet/scale=1
|
||||||
|
|
@ -1,32 +1,20 @@
|
||||||
[gd_scene format=3 uid="uid://bikcpm0fyl4pd"]
|
[gd_scene format=3 uid="uid://bikcpm0fyl4pd"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://jdmsv25yp25v" path="res://src/player/attack.aseprite" id="1_3il12"]
|
|
||||||
[ext_resource type="Script" uid="uid://0n1gv56pcc74" path="res://src/player/SlashProjectile.cs" id="1_bi0sp"]
|
[ext_resource type="Script" uid="uid://0n1gv56pcc74" path="res://src/player/SlashProjectile.cs" id="1_bi0sp"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cva3ecq7vp3a4" path="res://src/combat/hitbox.tscn" id="2_bi0sp"]
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_3il12"]
|
[sub_resource type="Animation" id="Animation_3il12"]
|
||||||
length = 0.001
|
length = 0.001
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("Attack:frame")
|
tracks/0/path = NodePath("Hitbox/CollisionShape2D:disabled")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0),
|
"times": PackedFloat32Array(0),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
"values": [0]
|
|
||||||
}
|
|
||||||
tracks/1/type = "value"
|
|
||||||
tracks/1/imported = false
|
|
||||||
tracks/1/enabled = true
|
|
||||||
tracks/1/path = NodePath("Hitbox/CollisionShape2D:disabled")
|
|
||||||
tracks/1/interp = 1
|
|
||||||
tracks/1/loop_wrap = true
|
|
||||||
tracks/1/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 1,
|
|
||||||
"values": [true]
|
"values": [true]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,25 +22,13 @@ tracks/1/keys = {
|
||||||
resource_name = "attack"
|
resource_name = "attack"
|
||||||
length = 0.4
|
length = 0.4
|
||||||
step = 0.1
|
step = 0.1
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "method"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("Attack:frame")
|
tracks/0/path = NodePath(".")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0, 0.1, 0.2),
|
|
||||||
"transitions": PackedFloat32Array(1, 1, 1),
|
|
||||||
"update": 1,
|
|
||||||
"values": [0, 1, 2]
|
|
||||||
}
|
|
||||||
tracks/1/type = "method"
|
|
||||||
tracks/1/imported = false
|
|
||||||
tracks/1/enabled = true
|
|
||||||
tracks/1/path = NodePath(".")
|
|
||||||
tracks/1/interp = 1
|
|
||||||
tracks/1/loop_wrap = true
|
|
||||||
tracks/1/keys = {
|
|
||||||
"times": PackedFloat32Array(0.4),
|
"times": PackedFloat32Array(0.4),
|
||||||
"transitions": PackedFloat32Array(1),
|
"transitions": PackedFloat32Array(1),
|
||||||
"values": [{
|
"values": [{
|
||||||
|
|
@ -60,13 +36,13 @@ tracks/1/keys = {
|
||||||
"method": &"OnAttackFinished"
|
"method": &"OnAttackFinished"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
tracks/2/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/2/imported = false
|
tracks/1/imported = false
|
||||||
tracks/2/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/2/path = NodePath("Hitbox/CollisionShape2D:disabled")
|
tracks/1/path = NodePath("Hitbox/CollisionShape2D:disabled")
|
||||||
tracks/2/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/2/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/2/keys = {
|
tracks/1/keys = {
|
||||||
"times": PackedFloat32Array(0, 0.1, 0.3),
|
"times": PackedFloat32Array(0, 0.1, 0.3),
|
||||||
"transitions": PackedFloat32Array(1, 1, 1),
|
"transitions": PackedFloat32Array(1, 1, 1),
|
||||||
"update": 1,
|
"update": 1,
|
||||||
|
|
@ -79,30 +55,23 @@ _data = {
|
||||||
&"attack": SubResource("Animation_eb3da")
|
&"attack": SubResource("Animation_eb3da")
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_u7cw4"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_qydbd"]
|
||||||
size = Vector2(32, 10)
|
size = Vector2(32, 10)
|
||||||
|
|
||||||
[node name="SlashProjectile" type="Node2D" unique_id=541992074]
|
[node name="SlashProjectile" type="Node2D" unique_id=541992074]
|
||||||
script = ExtResource("1_bi0sp")
|
script = ExtResource("1_bi0sp")
|
||||||
|
|
||||||
[node name="Attack" type="Sprite2D" parent="." unique_id=30274790]
|
|
||||||
position = Vector2(16, -3)
|
|
||||||
texture = ExtResource("1_3il12")
|
|
||||||
hframes = 3
|
|
||||||
|
|
||||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1896907748]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="." unique_id=1896907748]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
libraries/ = SubResource("AnimationLibrary_12t1i")
|
libraries/ = SubResource("AnimationLibrary_12t1i")
|
||||||
autoplay = &"attack"
|
autoplay = &"attack"
|
||||||
|
|
||||||
[node name="Hitbox" type="Area2D" parent="." unique_id=133086557]
|
[node name="Hitbox" parent="." unique_id=1918418417 instance=ExtResource("2_bi0sp")]
|
||||||
collision_layer = 8
|
|
||||||
collision_mask = 4
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" unique_id=1668475985]
|
[node name="CollisionShape2D" parent="Hitbox" index="0" unique_id=2048987579]
|
||||||
position = Vector2(21, -5)
|
position = Vector2(23, -7)
|
||||||
shape = SubResource("RectangleShape2D_u7cw4")
|
shape = SubResource("RectangleShape2D_qydbd")
|
||||||
disabled = true
|
|
||||||
debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
|
|
||||||
|
|
||||||
[connection signal="body_entered" from="Hitbox" to="." method="OnHitboxBodyEntered"]
|
[connection signal="body_entered" from="Hitbox" to="." method="OnHitboxBodyEntered"]
|
||||||
|
|
||||||
|
[editable path="Hitbox"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue