2022-01-19 15:13:13 +00:00
|
|
|
function EditorStep()
|
|
|
|
palette = palette or false
|
|
|
|
AnimateTiles()
|
|
|
|
if Keybind:HasPressed(Keybind.editor.palette) then
|
|
|
|
if palette then
|
|
|
|
palette = false
|
2022-01-19 20:57:45 +00:00
|
|
|
palette_scroll_x = nil
|
|
|
|
palette_scroll_y = nil
|
2022-01-19 15:13:13 +00:00
|
|
|
else
|
2022-01-19 20:57:45 +00:00
|
|
|
palette = true
|
|
|
|
palette_scroll_x = 0
|
|
|
|
palette_scroll_y = 0
|
2022-01-19 15:13:13 +00:00
|
|
|
end
|
|
|
|
end
|
2022-01-22 22:10:21 +00:00
|
|
|
if love.keyboard.isDown('a',"left") then
|
|
|
|
Camera.pos.x = Camera.pos.x - 3*game.scale
|
|
|
|
end
|
|
|
|
if love.keyboard.isDown('d',"right") then
|
|
|
|
Camera.pos.x = Camera.pos.x + 3*game.scale
|
|
|
|
end
|
|
|
|
if love.keyboard.isDown("up", "w") then
|
|
|
|
Camera.pos.y = Camera.pos.y - 3*game.scale
|
|
|
|
end
|
|
|
|
if love.keyboard.isDown("down", "s") then
|
|
|
|
Camera.pos.y = Camera.pos.y + 3*game.scale
|
|
|
|
end
|
2022-01-19 15:13:13 +00:00
|
|
|
end
|
|
|
|
|
2022-01-19 20:57:45 +00:00
|
|
|
function EditorScroll(y)
|
|
|
|
if palette then
|
|
|
|
if love.keyboard.isDown("lshift") then
|
|
|
|
palette_scroll_y = palette_scroll_y + y
|
|
|
|
else
|
|
|
|
palette_scroll_x = palette_scroll_x + y
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local oscale = game.scale
|
|
|
|
game.scale = math.max(0.1,game.scale + y/16)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-19 15:13:13 +00:00
|
|
|
function EditorDraw()
|
2022-01-22 22:10:21 +00:00
|
|
|
GameworldDrawPrepare()
|
|
|
|
GameworldDrawBackground()
|
|
|
|
GridDisplay()
|
|
|
|
GameworldDrawForeground()
|
|
|
|
GameworldDrawEnd()
|
2022-01-29 07:49:45 +00:00
|
|
|
EditorDoEdit()
|
2022-01-22 22:10:21 +00:00
|
|
|
|
|
|
|
DrawSelectingPaletteTile()
|
2022-01-19 15:13:13 +00:00
|
|
|
if palette then
|
2022-01-19 20:57:45 +00:00
|
|
|
EditorDoPalette()
|
2022-01-19 15:13:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
function EditorDoEdit()
|
2022-01-29 07:49:45 +00:00
|
|
|
local mouse_x = love.mouse.getX()
|
|
|
|
local mouse_y = love.mouse.getY()
|
|
|
|
local horizontal = 1 + math.floor(((mouse_x/game.scale) / tileProperties.width) + (Camera.pos.x / tileProperties.width))
|
|
|
|
local vertical = 1 + math.floor(((mouse_y/game.scale) / tileProperties.height) + (Camera.pos.y / tileProperties.height))
|
|
|
|
local expand_h = 0
|
|
|
|
local expand_v = 0
|
|
|
|
local LevelWidth = LevelGetTileWidth()
|
|
|
|
local LevelHeight = LevelGetTileHeight()
|
|
|
|
|
|
|
|
if horizontal > LevelWidth then
|
|
|
|
expand_h = horizontal-LevelWidth
|
|
|
|
elseif horizontal < 0 then
|
|
|
|
expand_h = horizontal
|
|
|
|
end
|
|
|
|
if vertical > LevelHeight then
|
|
|
|
expand_v = vertical-LevelHeight
|
|
|
|
elseif vertical < 0 then
|
|
|
|
expand_v = vertical
|
|
|
|
end
|
|
|
|
love.graphics.print("> " .. horizontal .. ", " .. vertical)
|
|
|
|
love.graphics.print("> " .. LevelWidth .. "(" .. expand_h .. "), " .. LevelHeight .. "(".. expand_v .. ")", 0, 10)
|
2022-01-22 22:10:21 +00:00
|
|
|
|
2022-01-29 10:52:57 +00:00
|
|
|
if not palette then
|
2022-01-29 07:49:45 +00:00
|
|
|
if LevelTiles[vertical] ~= nil
|
|
|
|
and LevelTiles[vertical][horizontal] ~= nil
|
2022-01-22 22:10:21 +00:00
|
|
|
and love.keyboard.isDown("lshift") ~= true
|
|
|
|
and love.keyboard.isDown("lctrl") ~= true
|
2022-01-29 07:49:45 +00:00
|
|
|
and selecting_tile ~= nil
|
2022-01-22 22:10:21 +00:00
|
|
|
then
|
2022-01-29 10:52:57 +00:00
|
|
|
if Keybind:CheckDown(Keybind.generic.lclick) then
|
|
|
|
InstanceTile(vertical,horizontal,selecting_tile)
|
|
|
|
elseif Keybind:CheckDown(Keybind.generic.rclick)
|
|
|
|
InstanceTile(vertical,horizontal,0)
|
|
|
|
end
|
|
|
|
LevelReloadTiles()
|
2022-01-29 07:49:45 +00:00
|
|
|
--[[
|
|
|
|
elseif love.keyboard.isDown("lshift") then
|
|
|
|
--ExpandCanvas(math.sign(expand_h),math.sign(expand_v))
|
2022-01-22 22:10:21 +00:00
|
|
|
|
|
|
|
if expand_h < 0 then
|
|
|
|
Camera.pos.x = Camera.pos.x - expand_h*tileProperties.scale*tileProperties.width
|
|
|
|
end
|
|
|
|
if expand_v < 0 then
|
|
|
|
Camera.pos.y = Camera.pos.y - expand_v*tileProperties.scale*tileProperties.height
|
|
|
|
end
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
elseif love.keyboard.isDown("lctrl") then
|
|
|
|
--ReduceCanvas(math.sign(expand_h),math.sign(expand_v))
|
2022-01-22 22:10:21 +00:00
|
|
|
|
|
|
|
if expand_h < 0 then
|
|
|
|
Camera.pos.x = Camera.pos.x - expand_h*tileProperties.scale*tileProperties.width
|
|
|
|
end
|
|
|
|
if expand_v < 0 then
|
|
|
|
Camera.pos.y = Camera.pos.y - expand_v*tileProperties.scale*tileProperties.height
|
2022-01-29 07:49:45 +00:00
|
|
|
end]]
|
2022-01-22 22:10:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function DrawSelectingPaletteTile()
|
2022-01-29 07:49:45 +00:00
|
|
|
if selecting_tile ~= nil and selecting_tile ~= 0 then
|
2022-01-22 22:10:21 +00:00
|
|
|
|
|
|
|
local mouse_x = tileProperties.width * math.floor((love.mouse.getX()/game.scale) / tileProperties.width) - Camera.pos.x % tileProperties.width
|
|
|
|
local mouse_y = tileProperties.height * math.floor((love.mouse.getY()/game.scale) / tileProperties.height) - Camera.pos.y % tileProperties.height
|
|
|
|
|
|
|
|
love.graphics.draw(
|
|
|
|
LevelData.tileset,
|
|
|
|
TileIndex[selecting_tile],
|
|
|
|
mouse_x,
|
|
|
|
mouse_y
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-19 20:57:45 +00:00
|
|
|
function EditorDoPalette()
|
|
|
|
|
|
|
|
local width = LevelData.tileset:getPixelWidth()/tileProperties.width
|
2022-01-19 15:13:13 +00:00
|
|
|
local height = LevelData.tileset:getPixelHeight()/tileProperties.height
|
|
|
|
|
2022-01-19 20:57:45 +00:00
|
|
|
love.graphics.setColor(0,0,0,1)
|
|
|
|
love.graphics.rectangle(
|
|
|
|
"fill",
|
|
|
|
(palette_scroll_x + 1) * (tileProperties.width+1),
|
|
|
|
(palette_scroll_y + 1) * (tileProperties.height+1),
|
|
|
|
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width),
|
|
|
|
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
love.graphics.setColor(1,1,1,1)
|
|
|
|
local position_x = 1
|
|
|
|
local position_y = 1
|
|
|
|
for i = 1, #TileIndex-width-1 do
|
|
|
|
|
|
|
|
local tile_x = (palette_scroll_x + position_x) * (tileProperties.width+1)
|
|
|
|
local tile_y = (palette_scroll_y + position_y) * (tileProperties.height+1)
|
|
|
|
|
|
|
|
love.graphics.draw(
|
|
|
|
LevelData.tileset,
|
|
|
|
TileIndex[i],
|
|
|
|
tile_x,
|
|
|
|
tile_y,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
1
|
|
|
|
)
|
2022-01-29 07:49:45 +00:00
|
|
|
if Keybind:CheckDown(Keybind.generic.lclick) then
|
2022-01-19 20:57:45 +00:00
|
|
|
local mouse_x = love.mouse.getX()
|
|
|
|
local mouse_y = love.mouse.getY()
|
|
|
|
|
2022-01-22 22:10:21 +00:00
|
|
|
if mouse_x > (tile_x) * game.scale
|
|
|
|
and mouse_x < (tile_x + tileProperties.width) * game.scale
|
|
|
|
and mouse_y > (tile_y) * game.scale
|
|
|
|
and mouse_y < (tile_y + tileProperties.height) * game.scale
|
2022-01-19 20:57:45 +00:00
|
|
|
then
|
2022-01-22 22:10:21 +00:00
|
|
|
selecting_tile = position_x + ((position_y-1) * width)
|
2022-01-19 20:57:45 +00:00
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
love.graphics.print(selecting_tile .. " | " .. tile_x .. ", " .. tile_y, 0, 20)
|
2022-01-19 20:57:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-29 07:49:45 +00:00
|
|
|
if Keybind:CheckDown(Keybind.generic.rclick) then
|
2022-01-29 10:52:57 +00:00
|
|
|
selecting_tile = nil
|
2022-01-29 07:49:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if selecting_tile ~= nil and selecting_tile ~= 0 and i == selecting_tile then
|
2022-01-19 20:57:45 +00:00
|
|
|
love.graphics.setColor(1,0,1,1)
|
|
|
|
love.graphics.rectangle(
|
|
|
|
"line",
|
|
|
|
tile_x,
|
|
|
|
tile_y,
|
|
|
|
tileProperties.width,
|
|
|
|
tileProperties.height
|
|
|
|
)
|
|
|
|
love.graphics.setColor(1,1,1,1)
|
|
|
|
end
|
|
|
|
|
|
|
|
position_x = position_x + 1
|
|
|
|
|
|
|
|
if position_x > width then
|
|
|
|
position_x = position_x - width
|
|
|
|
position_y = position_y + 1
|
|
|
|
end
|
2022-01-19 15:13:13 +00:00
|
|
|
end
|
|
|
|
|
2022-01-19 20:57:45 +00:00
|
|
|
|
|
|
|
love.graphics.rectangle(
|
|
|
|
"line",
|
|
|
|
(palette_scroll_x + 1) * (tileProperties.width+1),
|
|
|
|
(palette_scroll_y + 1) * (tileProperties.height+1),
|
|
|
|
1 + LevelData.tileset:getPixelWidth() * ((tileProperties.width+1) / tileProperties.width),
|
|
|
|
1 + LevelData.tileset:getPixelHeight()* ((tileProperties.height+1) / tileProperties.height)
|
2022-01-19 15:13:13 +00:00
|
|
|
)
|
|
|
|
end
|