69 lines
2.6 KiB
GDScript3
69 lines
2.6 KiB
GDScript3
|
#warning-ignore-all:shadowed_variable
|
||
|
#warning-ignore-all:unused_argument
|
||
|
const STRUCT := preload('res://scripts/struct.gd')
|
||
|
const GRAPHICS := preload('res://scripts/loaders/snes/graphics.gd')
|
||
|
|
||
|
class TileSNESMode7 extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS.mode7_to_tile(buffer.get_data(64))
|
||
|
|
||
|
class TileSNESMode7c extends STRUCT.StructType:
|
||
|
# Note that this will give a palette offset of 0, you will need to postprocess the values.
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS.mode7_compressed_to_tile(buffer.get_data(32)[1])
|
||
|
|
||
|
class TileSNES4bpp extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS._4plane_to_tile(buffer.get_data(32)[1])
|
||
|
|
||
|
class TileSNES3bpp extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS._3plane_to_tile(buffer.get_data(24)[1])
|
||
|
|
||
|
class TileSNES2bpp extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS._2plane_to_tile(buffer.get_data(16)[1])
|
||
|
|
||
|
class TileSNES1bpp extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS._1plane_to_tile(buffer.get_data(8)[1])
|
||
|
|
||
|
class ColorBGR555 extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
return GRAPHICS.bgr555_to_color(buffer.get_u16())
|
||
|
|
||
|
class PaletteOf555 extends STRUCT.StructType:
|
||
|
var length: int = 16
|
||
|
func _init(length: int):
|
||
|
self.length = length
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
var array := PoolColorArray()
|
||
|
for i in self.length:
|
||
|
array.append(GRAPHICS.bgr555_to_color(buffer.get_u16()))
|
||
|
return array
|
||
|
|
||
|
class ItemCost extends STRUCT.StructType:
|
||
|
func get_value(buffer: StreamPeer, leftover_bits: Array):
|
||
|
var b0 := buffer.get_u8()
|
||
|
var mantissa := buffer.get_u8()
|
||
|
var exponent := b0 & 0x3F
|
||
|
var is_sellable := (b0 & 0x80) == 0
|
||
|
var is_sellprice_5gil := (b0 & 0x40) == 0x40
|
||
|
var buy_price := mantissa * int(pow(10, exponent))
|
||
|
var sell_price := -1 if not is_sellable else (5 if is_sellprice_5gil else buy_price/2)
|
||
|
return {'buy_price': buy_price, 'sell_price': sell_price}
|
||
|
|
||
|
static func get_structtypes() -> Dictionary:
|
||
|
return {
|
||
|
'TileSNESMode7': TileSNESMode7.new(),
|
||
|
'TileSNESMode7c': TileSNESMode7c.new(),
|
||
|
'TileSNES4bpp': TileSNES4bpp.new(),
|
||
|
'TileSNES3bpp': TileSNES3bpp.new(),
|
||
|
'TileSNES2bpp': TileSNES2bpp.new(),
|
||
|
'TileSNES1bpp': TileSNES1bpp.new(),
|
||
|
'ColorBGR555': ColorBGR555.new(),
|
||
|
'Palette16Of555': PaletteOf555.new(16),
|
||
|
'Palette128Of555': PaletteOf555.new(128),
|
||
|
'ItemCost': ItemCost.new(),
|
||
|
}
|