From daf4c54cd5ba2b267aae4fbe2b8a0c49828fcf0e Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Thu, 27 Jul 2023 16:41:49 +0930 Subject: [PATCH] Move map blocks to a test scene --- Node2D.gd | 48 ------------------------------ Node2D.tscn | 27 ----------------- scripts/loaders/map_loader.gd | 37 ++++++++++++++++------- test/worldmap_blocks.gd | 56 +++++++++++++++++++++++++++++++++++ test/worldmap_blocks.tscn | 23 ++++++++++++++ 5 files changed, 105 insertions(+), 86 deletions(-) create mode 100644 test/worldmap_blocks.gd create mode 100644 test/worldmap_blocks.tscn diff --git a/Node2D.gd b/Node2D.gd index bc2f66e..94333ad 100644 --- a/Node2D.gd +++ b/Node2D.gd @@ -2,20 +2,7 @@ extends Node2D var PC = load('PC.tscn') var PCs = [] -var worldmap_blocks = [] var sfx_buttons = [] -var block_labels = [] - -func bin2str(bin: int) -> String: - var string := '' - for i in 8: - if i == 4: - string += ' ' - if ((bin >> 7-i) & 0x01) != 0: - string += '1' - else: - string += '0' - return string func _ready(): Engine.set_target_fps(60) @@ -35,42 +22,7 @@ func _ready(): # PCs[-1].material.set_shader_param('palette', SpriteLoader.character_battle_sprite_palette_textures[45]) # PCs[-1].texture = SpriteLoader.weapon_textures['Fist'] # add_child(PCs[-1]) - for i in 3: - worldmap_blocks.append(TextureRect.new()) - worldmap_blocks[-1].texture = SpriteLoader.worldmap_block_atlas_textures[i] - # worldmap_blocks[-1].texture = SpriteLoader.worldmap_tile_atlas_textures[i] - worldmap_blocks[-1].material = SpriteLoader.shader_material.duplicate() - worldmap_blocks[-1].material.set_shader_param('palette', SpriteLoader.worldmap_palette_textures[i]) - worldmap_blocks[-1].rect_scale *= 3 - worldmap_blocks[-1].rect_position.x = i*256*3 - worldmap_blocks[-1].rect_position.y = 280 - add_child(worldmap_blocks[-1]) - var x0 = i*256*3 + 4 - var y0 = 280 + 12 - for block in 0xC0: - var label = Label.new() - var p = MapLoader.worldmap_block_properties[i][block] - label.text = '%s\n%s\n%s' % [bin2str(p&0xff), bin2str((p>>8)&0xff), bin2str(p>>16)] - label.add_color_override('font_color_shadow', Color.black) - label.add_constant_override('shadow_as_outline', true) - label.rect_position.x = x0 + (block%16) * 48 - label.rect_position.y = y0 + (block/16) * 48 - label.rect_scale /= 2 - add_child(label) - block_labels.append(label) _create_sfx_buttons() - $BitSelector.connect('value_changed', self, '_update_block_mask') - -func _update_block_mask(value: int): - var mask = 0xFFFFFF if (value<0) else (1<>8)&0xff), bin2str(mask>>16)] - for i in block_labels.size(): - var p = MapLoader.worldmap_block_properties[i/0xC0][i%0xC0] - if (p & mask) > 0: - block_labels[i].add_color_override('font_color', Color.white) - else: - block_labels[i].add_color_override('font_color', Color.black) - func _create_sfx_buttons(): diff --git a/Node2D.tscn b/Node2D.tscn index db79c16..37d7b70 100644 --- a/Node2D.tscn +++ b/Node2D.tscn @@ -23,31 +23,4 @@ text = "Stand" items = [ "Stand", null, false, 0, null, "Guard", null, false, 1, null, "Walk", null, false, 2, null, "Down", null, false, 3, null, "R_Swing", null, false, 4, null, "L_Swing", null, false, 5, null, "Cheer", null, false, 6, null, "Recoil", null, false, 7, null, "Chant", null, false, 8, null ] selected = 0 -[node name="BitSelector" type="SpinBox" parent="Node2D"] -anchor_bottom = 0.67 -margin_left = 60.0 -margin_top = 180.0 -margin_right = 160.0 -margin_bottom = 204.0 -rect_scale = Vector2( 0.5, 0.5 ) -min_value = -1.0 -max_value = 23.0 -value = -1.0 - -[node name="BitSelectorMask" type="Label" parent="Node2D"] -anchor_bottom = 0.67 -margin_left = 120.0 -margin_top = 170.0 -margin_right = 220.0 -margin_bottom = 218.0 -rect_scale = Vector2( 0.5, 0.5 ) -text = "1111 -1111 -1111" - -[node name="ColorRect" type="ColorRect" parent="."] -visible = false -anchor_right = 1.0 -anchor_bottom = 1.0 - [connection signal="item_selected" from="Node2D/OptionButton" to="Node2D" method="_on_OptionButton_item_selected"] diff --git a/scripts/loaders/map_loader.gd b/scripts/loaders/map_loader.gd index 50d973e..bb63f19 100644 --- a/scripts/loaders/map_loader.gd +++ b/scripts/loaders/map_loader.gd @@ -4,32 +4,47 @@ extends Node # 3 bytes # Byte0: movement properties # 0x01 = passable on foot -# 0x02 = passable on chocobo?? +# 0x02 = passable on chocobo? # 0x04 = passable on black chocobo -# 0x08 = passable on hiryuu?? -# 0x10 = set on deep water tiles, and all undersea tiles that aren't cliffs -# 0x20 = set on deep water tiles only (not undersea) -# 0x40 = Pretty much every tile aboveground has this. No undersea. -# 0x80 = only set on clear sea floor. Submarine pathable?? +# 0x08 = passable on hiryuu? +# 0x10 = passable in submarine? set on deep water tiles, and all undersea tiles that aren't cliffs +# 0x20 = passable in ship? set on deep water tiles only (not undersea) - can submerge? +# 0x40 = passable in airship? Pretty much every tile aboveground has this. No undersea. +# 0x80 = only set on clear sea floor. Submarine pathable/can surface? # Byte1: movement properties # 0x01 = (water flips) can move from this block rightwards # 0x02 = (water flips) can move from this block leftwards # 0x04 = (water flips) can move from this block downwards # 0x08 = (water flips) can move from this block upwards -# 0x10 = most aboveground water tiles -# 0x20 = -# 0x40 = -# 0x80 = Things airship can't land on?? +# 0x10 = Chocobo can't land/dismount. most aboveground water tiles +# 0x20 = Black Chocobo can't land. +# 0x40 = Hiryuu can't land. +# 0x80 = Airship can't land. # Byte2: movement properties # 0x01 = Set on forests, deep water, void. # 0x02 = Set on deep water, void, desert. # 0x04 = Only set on diagonal land corners and Galuf World swamp # 0x08 = No hits. # 0x10 = Mountains and Exdeath's Castle -# 0x20 = Only set on forests. Can land Black Chocobo? ...also waterfall, but not lower bounds of forests +# 0x20 = Set on first two rows of forests, also waterfall, but not lower bounds of forests # 0x40 = Shallow water. # 0x80 = +# Vehicle landing bit masks: [00 10 20 40 00 00 80] - & with Byte1, if 1, can't land +# Vehicle IDs: [None, Chocobo, BlkChocobo, Hiryuu, Submarine, Ship, Airship] + +# Worldmap animations +# World 1 (and probably 3) +# Sea tiles and waterfall tiles have a scrolling effect in tile data +# This may require setting up a proper tile indirect lookup shader +# Shifting sands and the portal have cycling palettes: $6C and $6D swap every frame, $51 through $55 scroll left (i.e. $55->$54, $51->$55) +# This will be best hardcoded as a 10 palette cycle +# World 2: +# Sea tiles have a horizontal scrolling effect in tile data (addresses $1880, $18C0, $1C80, $1CC0) +# ASM at C09660 BF 21 86 7F LDA $7F8621,X +# Probably going to shader this effect instead of storing hundreds of frames +# No palette cycling + var worldmap_block_properties = [] func load_worldmap_block_properties(rom: File): rom.seek(0x0FEA00) diff --git a/test/worldmap_blocks.gd b/test/worldmap_blocks.gd new file mode 100644 index 0000000..ba9e847 --- /dev/null +++ b/test/worldmap_blocks.gd @@ -0,0 +1,56 @@ +extends Node2D +var worldmap_blocks = [] +var block_labels = [] + + +func bin2str(bin: int) -> String: + var string := '' + for i in 8: + if i == 4: + string += ' ' + if ((bin >> 7-i) & 0x01) != 0: + string += '1' + else: + string += '0' + return string + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + var _scale := 5 + var _size = Vector2.ONE * 16 * _scale + for i in 3: + worldmap_blocks.append(TextureRect.new()) + worldmap_blocks[-1].texture = SpriteLoader.worldmap_block_atlas_textures[i] + # worldmap_blocks[-1].texture = SpriteLoader.worldmap_tile_atlas_textures[i] + worldmap_blocks[-1].material = SpriteLoader.shader_material.duplicate() + worldmap_blocks[-1].material.set_shader_param('palette', SpriteLoader.worldmap_palette_textures[i]) + worldmap_blocks[-1].rect_scale *= _scale + var pos = Vector2(i * 256 * _scale, 50) + worldmap_blocks[-1].rect_position = pos + add_child(worldmap_blocks[-1]) + # x0 += 4 * _scale + # y0 += 12 * _scale + for block in 0xC0: + var label = Label.new() + var p = MapLoader.worldmap_block_properties[i][block] + label.text = '%s\n%s\n%s' % [bin2str(p&0xff), bin2str((p>>8)&0xff), bin2str(p>>16)] + label.add_color_override('font_color_shadow', Color.black) + label.add_constant_override('shadow_as_outline', true) + label.rect_position = pos + (Vector2(block%16, block/16) * _size) + label.rect_size = _size + label.align = Label.ALIGN_CENTER + label.valign = Label.VALIGN_CENTER + add_child(label) + block_labels.append(label) + $BitSelector.connect('value_changed', self, '_update_block_mask') + +func _update_block_mask(value: int): + var mask = 0xFFFFFF if (value<0) else (1<>8)&0xff), bin2str(mask>>16)] + for i in block_labels.size(): + var p = MapLoader.worldmap_block_properties[i/0xC0][i%0xC0] + if (p & mask) > 0: + block_labels[i].add_color_override('font_color', Color.white) + else: + block_labels[i].add_color_override('font_color', Color.black) diff --git a/test/worldmap_blocks.tscn b/test/worldmap_blocks.tscn new file mode 100644 index 0000000..f559825 --- /dev/null +++ b/test/worldmap_blocks.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://test/worldmap_blocks.gd" type="Script" id=1] + +[node name="worldmap_blocks" type="Node2D"] +script = ExtResource( 1 ) + +[node name="BitSelector" type="SpinBox" parent="."] +anchor_bottom = 0.67 +margin_right = 100.0 +margin_bottom = 24.0 +min_value = -1.0 +max_value = 23.0 +value = -1.0 + +[node name="BitSelectorMask" type="Label" parent="."] +anchor_bottom = 0.67 +margin_left = 120.0 +margin_right = 220.0 +margin_bottom = 48.0 +text = "1111 +1111 +1111"