57 lines
2.0 KiB
GDScript
57 lines
2.0 KiB
GDScript
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<<value)
|
|
$BitSelectorMask.text = '%s\n%s\n%s' % [bin2str(mask&0xff), bin2str((mask>>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)
|