Skip to content

Commit

Permalink
resize slx
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Apr 25, 2024
1 parent 48247cc commit 877cd1b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Scenes/Buffers.gd
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ func resize_all_data_structures(new_width, new_height):
oDataLiquid.resize(new_width, new_height, 0)
oDataFakeSlab.resize(new_width, new_height, 0)

#oDataSlx.resize(new_width, new_height, 0)
oDataSlx.resize_bottom_right(new_width, new_height, 0)
22 changes: 14 additions & 8 deletions Scenes/DataSlx.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ func clear_img():
slxImgData.fill(Color(0,0,0,1))
slxTexData.set_data(slxImgData)

#func set_tileset_value(x,y):
# var value = Color8(oSlabStyle.paintSlabStyle,0,0)
# slxImgData.lock()
# slxImgData.set_pixel(x,y,value)
# slxImgData.unlock()
# slxTexData.set_data(slxImgData)
# oDisplaySlxNumbers.update_grid()

func set_tileset_shape(shapePositionArray):
var value = Color8(oSlabStyle.paintSlabStyle,0,0)
slxImgData.lock()
Expand All @@ -32,3 +24,17 @@ func get_tileset_value(x,y):
var r = slxImgData.get_pixel(x,y).r8
slxImgData.unlock()
return r

func resize_bottom_right(new_width: int, new_height: int, fillValue: int):
var resized_image = Image.new()
resized_image.create(new_width, new_height, false, slxImgData.get_format())

var fill_color = Color8(fillValue, 0, 0)
resized_image.fill(fill_color)

var copy_width = min(slxImgData.get_width(), new_width)
var copy_height = min(slxImgData.get_height(), new_height)

resized_image.blit_rect(slxImgData, Rect2(0, 0, copy_width, copy_height), Vector2.ZERO)

slxImgData = resized_image
5 changes: 3 additions & 2 deletions Scenes/ReadData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func read_slx(buffer):
# 2 = Tileset 1
# 3 = Tileset 2, etc.
oDataSlx.slxImgData.create(M.xSize, M.ySize, false, Image.FORMAT_RGB8)
oDataSlx.slxTexData.create_from_image(oDataSlx.slxImgData, 0)

oDataSlx.slxImgData.lock()
for ySlab in M.ySize:
for xSlab in M.xSize:
Expand All @@ -105,7 +105,8 @@ func read_slx(buffer):
# Red value will be used to store the slx value
oDataSlx.slxImgData.set_pixel(xSlab, ySlab, Color8(lower4bits,0,0,255))
oDataSlx.slxImgData.unlock()
oDataSlx.slxTexData.set_data(oDataSlx.slxImgData)

oDataSlx.slxTexData.create_from_image(oDataSlx.slxImgData, 0)

func new_slx():
oDataSlx.slxImgData.create(M.xSize, M.ySize, false, Image.FORMAT_RGB8)
Expand Down
2 changes: 2 additions & 0 deletions Scenes/WriteData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,10 @@ func write_inf():
func write_slx():
var buffer = StreamPeerBuffer.new()
var slx_data = oDataSlx.slxImgData.get_data()

for i in range(0, slx_data.size(), 3):
buffer.put_8(slx_data[i])

return buffer


Expand Down

0 comments on commit 877cd1b

Please sign in to comment.