dcearth/main.lua

94 lines
2.7 KiB
Lua
Raw Normal View History

2023-04-28 17:35:52 +00:00
local love = assert( love, "This tool requires LOVE: love2d.org" )
--assert( require('mobdebug') ).start() --remote debugger
local map = require 'map.map'
local button = require 'ui.button'
local mainmenu = require 'ui.menu.mainmenu'
local Camera = require 'ui.camera'
2023-04-28 17:35:52 +00:00
function love.load()
love.filesystem.setIdentity( "dcearth", false )
2024-04-29 01:21:32 +00:00
love.keyboard.setKeyRepeat( true )
love.graphics.setNewFont( 14 )
2023-04-28 17:35:52 +00:00
end
function love.directorydropped( path )
2024-04-28 01:38:23 +00:00
if map.path then
assert( love.filesystem.unmount( map.path ) )
map.loaded = false
end
love.filesystem.mount( path, "" )
return map.load( path )
end
2023-04-28 17:35:52 +00:00
function love.update( dt )
local tx, ty = 0, 0
local moveCamera = false
if love.keyboard.isScancodeDown( "w" ) then moveCamera = true; ty = ty + dt * 150 / Camera.zoom end
if love.keyboard.isScancodeDown( "a" ) then moveCamera = true; tx = tx - dt * 150 / Camera.zoom end
if love.keyboard.isScancodeDown( "s" ) then moveCamera = true; ty = ty - dt * 150 / Camera.zoom end
if love.keyboard.isScancodeDown( "d" ) then moveCamera = true; tx = tx + dt * 150 / Camera.zoom end
2024-05-02 00:32:07 +00:00
if love.keyboard.isScancodeDown( "q" ) then Camera.Zoom( dt * 400 ) end
if love.keyboard.isScancodeDown( "e" ) then Camera.Zoom( -dt* 400 ) end
if moveCamera then Camera.Translate( tx, ty ) end
2023-07-28 23:23:08 +00:00
2023-04-28 17:35:52 +00:00
end
function love.draw()
if not map.loaded then
2024-04-28 01:38:23 +00:00
local w, h = love.graphics.getDimensions()
2024-04-29 01:21:32 +00:00
return love.graphics.printf( "Drag and drop folder to begin.", w / 2 - 200, h / 2 - 128, 400, "center")
end
love.graphics.push( "all" )
map.draw()
love.graphics.pop()
2023-07-28 23:23:08 +00:00
mainmenu.draw()
end
function love.resize(w, h)
Camera.Resize( w, h )
end
function love.wheelmoved(x, y)
2024-05-02 00:32:07 +00:00
Camera.Zoom( (y > 0) and 3 or -3 )
end
2024-04-28 01:38:23 +00:00
function love.mousepressed( x, y, mouseButton, istouch, presses )
local wx, wy = Camera.GetWorldCoordinate( x, y )
2024-04-29 01:21:32 +00:00
2024-07-20 03:09:53 +00:00
return button.mousepressed( x, y )
end
function love.mousemoved( x, y, dx, dy, istouch )
2024-04-28 01:38:23 +00:00
if not map.loaded then return end
--mouse over menu
if y < mainmenu.menuHeight then
button.selectIn( x, y )
--mouse on map
else
if map.selectionLocked then return end
if map.editLayer and map.editLayer.selectNearest then
map.selected = map.editLayer:selectNearest( Camera.GetWorldCoordinate( x, y ) )
end
end
2023-04-28 17:35:52 +00:00
end
2024-04-28 01:38:23 +00:00
function love.keypressed(key, code, isRepeat)
if code == "up" then return button.selectPrev() end
if code == "down" then return button.selectNext() end
if code == "right" then return button.selectNextInGroup() end
if code == "left" then return button.selectPrevInGroup() end
2024-04-28 01:38:23 +00:00
if code == "return" then return button.selected:callback() end
if key == "c" then
map.selectionLocked = not( map.selectionLocked )
end
end
2024-07-20 03:09:53 +00:00
function love.textinput()
2023-04-28 17:35:52 +00:00
end