removed last globals for editor palette

This commit is contained in:
binarycat 2022-03-11 16:04:38 -05:00
parent 719c6cc5af
commit 97de68e34b

View File

@ -1,12 +1,16 @@
assert(editor == nil) assert(editor == nil)
editor = { editor = {
room_mode = false, room_mode = false,
palette_mode = false, --palette_mode = false,
palette = {
active = false,
scroll = Point:new(0, 0),
},
pan = { fixed = false, speed = 3 }, pan = { fixed = false, speed = 3 },
} }
function stepEditor() function stepEditor()
editor.palette_mode = editor.palette_mode or false
animateTiles() animateTiles()
if Keybind:checkPressed(Keybind.editor.room_mode) then if Keybind:checkPressed(Keybind.editor.room_mode) then
if love.keyboard.isDown("lshift") then if love.keyboard.isDown("lshift") then
@ -17,15 +21,7 @@ function stepEditor()
editor.room_points = {} editor.room_points = {}
end end
if Keybind:checkPressed(Keybind.editor.palette_mode) then if Keybind:checkPressed(Keybind.editor.palette_mode) then
if editor.palette_mode then editor.palette.active = not editor.palette.active
editor.palette_mode = false
palette_scroll_x = nil
palette_scroll_y = nil
else
editor.palette_mode = true
palette_scroll_x = 0
palette_scroll_y = 0
end
end end
@ -50,7 +46,7 @@ function stepEditor()
Camera.pos = Camera.pos + cvel Camera.pos = Camera.pos + cvel
if editor.palette_mode then if editor.palette.active then
if Keybind:checkPressed(Keybind.editor.palette_change) then if Keybind:checkPressed(Keybind.editor.palette_change) then
local next = false local next = false
local export = nil local export = nil
@ -103,11 +99,12 @@ function stepEditor()
end end
function scrollEditor(y) function scrollEditor(y)
if editor.palette_mode then if editor.palette.active then
local scr = editor.palette.scroll
if love.keyboard.isDown("lshift") then if love.keyboard.isDown("lshift") then
palette_scroll_y = palette_scroll_y + y scr.y = scr.y + y
else else
palette_scroll_x = palette_scroll_x + y scr.x = scr.x + y
end end
else else
game.scale = math.max(0.1,game.scale + y/16) game.scale = math.max(0.1,game.scale + y/16)
@ -128,7 +125,7 @@ function drawEditor()
drawSelectingPaletteTile() drawSelectingPaletteTile()
if editor.palette_mode then if editor.palette.active then
doEditorPalette() doEditorPalette()
end end
end end
@ -191,7 +188,7 @@ function doEditorEdit()
else else
drawTextBox("Select bottom right of new room", 0, 20) drawTextBox("Select bottom right of new room", 0, 20)
end end
elseif not editor.palette_mode then elseif not editor.palette.active then
if LevelTiles[vertical] ~= nil if LevelTiles[vertical] ~= nil
and LevelTiles[vertical][horizontal] ~= nil and LevelTiles[vertical][horizontal] ~= nil
and love.keyboard.isDown("lshift") ~= true and love.keyboard.isDown("lshift") ~= true
@ -266,8 +263,8 @@ function doEditorPalette()
love.graphics.setColor(0,0,0,1) love.graphics.setColor(0,0,0,1)
love.graphics.rectangle( love.graphics.rectangle(
"fill", "fill",
(palette_scroll_x + 1) * (tile_properties.width+1), (editor.palette.scroll.x + 1) * (tile_properties.width+1),
(palette_scroll_y + 1) * (tile_properties.height+1), (editor.palette.scroll.y + 1) * (tile_properties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width), 1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width),
1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height) 1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height)
) )
@ -277,8 +274,8 @@ function doEditorPalette()
local position_y = 1 local position_y = 1
for i = 1, #TileIndex-width-1 do for i = 1, #TileIndex-width-1 do
local tile_x = (palette_scroll_x + position_x) * (tile_properties.width+1) local tile_x = (editor.palette.scroll.x + position_x) * (tile_properties.width+1)
local tile_y = (palette_scroll_y + position_y) * (tile_properties.height+1) local tile_y = (editor.palette.scroll.y + position_y) * (tile_properties.height+1)
love.graphics.draw( love.graphics.draw(
LevelData.tileset, LevelData.tileset,
@ -330,8 +327,8 @@ function doEditorPalette()
love.graphics.rectangle( love.graphics.rectangle(
"line", "line",
(palette_scroll_x + 1) * (tile_properties.width+1), (editor.palette.scroll.x + 1) * (tile_properties.width+1),
(palette_scroll_y + 1) * (tile_properties.height+1), (editor.palette.scroll.y + 1) * (tile_properties.height+1),
1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width), 1 + LevelData.tileset:getPixelWidth() * ((tile_properties.width+1) / tile_properties.width),
1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height) 1 + LevelData.tileset:getPixelHeight()* ((tile_properties.height+1) / tile_properties.height)
) )
@ -348,8 +345,8 @@ function doEditorPalette()
drawTextBox( drawTextBox(
output, output,
(palette_scroll_x + 1+width) * (tile_properties.width+1), (editor.palette.scroll.x + 1+width) * (tile_properties.width+1),
(palette_scroll_y + 1) * (tile_properties.height+1) (editor.palette.scroll.y + 1) * (tile_properties.height+1)
) )
end end