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