Skip to content

Commit

Permalink
Merge branch 'master' into ui-olympUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruor committed Oct 30, 2023
2 parents b58382c + 8aafa91 commit 5a31af5
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 105 deletions.
2 changes: 2 additions & 0 deletions src/debug_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ function debugUtils.reloadEverything()
debugUtils.reloadScenes()
debugUtils.redrawMap()
debugUtils.reloadUI()

sceneHandler.sendEvent("editorDebugReloadEverything")
end

function debugUtils.restartLuaInstance()
Expand Down
1 change: 1 addition & 0 deletions src/defaults/config/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ return {
toolActionButton = 1,
contextMenuButton = 2,
canvasMoveButton = 2,
canvasZoomExtentsButton = 3,
objectCloneButton = 3,

copyUsesClipboard = true,
Expand Down
2 changes: 1 addition & 1 deletion src/entities/fling_bird.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ flingBird.name = "flingBird"
flingBird.depth = 0
flingBird.nodeLineRenderType = "line"
flingBird.texture = "characters/bird/Hover04"
flingBird.nodeLimits = {1, -1}
flingBird.nodeLimits = {0, -1}
flingBird.placements = {
name = "fling_bird",
data = {
Expand Down
13 changes: 3 additions & 10 deletions src/helpers/fake_tiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,9 @@ end
function fakeTilesHelper.getTilesOptions(layer)
layer = layer or "tilesFg"

local validTiles = brushes.getValidTiles(layer, false)
local tileOptions = {}
local validTiles = brushes.getMaterialLookup(layer, false)

for id, path in pairs(validTiles) do
local displayName = brushes.cleanMaterialPath(path)

tileOptions[displayName] = id
end

return tileOptions
return validTiles
end

-- Returns a function to be up to date with any XML changes
Expand Down Expand Up @@ -291,4 +284,4 @@ function fakeTilesHelper.getFieldInformation(materialKey, layer)
end
end

return fakeTilesHelper
return fakeTilesHelper
76 changes: 76 additions & 0 deletions src/input_devices/viewport_device.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
local configs = require("configs")
local viewportHandler = require("viewport_handler")
local mapItemUtils = require("map_item_utils")
local loadedState = require("loaded_state")
local utils = require("utils")

local viewportDevice = {}

function viewportDevice.mousedragmoved(x, y, dx, dy, button, istouch)
local movementButton = configs.editor.canvasMoveButton
local viewport = viewportHandler.viewport

if button == movementButton then
viewport.x -= dx
viewport.y -= dy

viewportHandler.persistCamera()

return true
end
end

function viewportDevice.mousemoved(x, y, dx, dy, istouch)
local viewport = viewportHandler.viewport

if istouch then
viewport.x -= dx
viewport.y -= dy

viewportHandler.persistCamera()

return true
end
end

function viewportDevice.mouseclicked(x, y, button, istouch, presses)
local zoomToExtentsButton = configs.editor.canvasZoomExtentsButton
local map = loadedState.map

if not map then
return
end

if button == zoomToExtentsButton and presses % 2 == 0 then
local tlx, tly, brx, bry = mapItemUtils.getMapBounds(map)
local rectangle = utils.rectangle(tlx, tly, brx - tlx, bry - tly)

viewportHandler.zoomToRectangle(rectangle)
viewportHandler.persistCamera()
end
end

function viewportDevice.resize(width, height)
viewportHandler.updateSize(width, height)
end

function viewportDevice.wheelmoved(dx, dy)
if dy > 0 then
viewportHandler.zoomIn()

return true

elseif dy < 0 then
viewportHandler.zoomOut()

return true
end
end

function viewportDevice.visible(visible)
local viewport = viewportHandler.viewport

viewport.visible = visible
end

return viewportDevice
2 changes: 1 addition & 1 deletion src/launch_arguments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function launchArguments.updateArguments(raw)
launchArguments.rawArguments = raw
launchArguments.parsed = parser:parse(arguments)

return launchArguments._parsed
return launchArguments.parsed
end

launchArguments.arguments = {}
Expand Down
6 changes: 5 additions & 1 deletion src/libraries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ function libraries.registerLibrary(filename, registerAt, verbose)
registerAt = registerAt or libraries.registeredLibraries

local pathNoExt = utils.stripExtension(filename)
local filenameNoExt = utils.filename(pathNoExt, "/")
local library = utils.rerequire(pathNoExt)

if type(library) ~= "table" then
return
end

local name = library.name or pathNoExt

registerAt[name] = library
Expand Down
16 changes: 2 additions & 14 deletions src/map_image.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
local loadedState = require("loaded_state")
local utils = require("utils")
local celesteRender = require("celeste_render")
local viewportHandler = require("viewport_handler")
local mapItemUtils = require("map_item_utils")

local mapImageGenerator = {}

function mapImageGenerator.getMapBounds(map)
local rectangles = {}

for _, room in ipairs(map.rooms) do
local rectangle = utils.rectangle(room.x, room.y, room.width, room.height)

table.insert(rectangles, rectangle)
end

return utils.rectangleBounds(rectangles)
end

local function getImageState(map)
local imageState = utils.deepcopy(loadedState)

local tlx, tly, brx, bry = mapImageGenerator.getMapBounds(map)
local tlx, tly, brx, bry = mapItemUtils.getMapBounds(map)
local width, height = brx - tlx, bry - tly

imageState.map = map
Expand Down
12 changes: 12 additions & 0 deletions src/map_item_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ local celesteRender = require("celeste_render")

local mapItemUtils = {}

function mapItemUtils.getMapBounds(map)
local rectangles = {}

for _, room in ipairs(map.rooms) do
local rectangle = utils.rectangle(room.x, room.y, room.width, room.height)

table.insert(rectangles, rectangle)
end

return utils.rectangleBounds(rectangles)
end

function mapItemUtils.deleteRoom(map, room)
for i, r in ipairs(map.rooms) do
if r.name == room.name then
Expand Down
8 changes: 6 additions & 2 deletions src/scene_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,20 @@ function sceneHandler.changeScene(name)
prevScene:exit(name)
end

local hasFirstEntered = newScene._firstEnter

sceneHandler.currentScene = name

if not newScene._firstEnter then
if not hasFirstEntered then
newScene._firstEnter = true

newScene:firstEnter(prevName)
end

newScene:enter(prevName)

sceneHandler.sendEvent("editorSceneChanged", name, prevName, not hasFirstEntered)

sceneHandler.wipeDuration = sceneHandler.defaultWipeDuration
sceneHandler.wipeRemaining = sceneHandler.wipeDuration
sceneHandler.wipeRenderedOnce = false
Expand Down Expand Up @@ -172,4 +176,4 @@ function sceneHandler.loadExternalScenes()
pluginLoader.loadPlugins(filenames, nil, sceneHandler.addSceneFromFilename)
end

return sceneHandler
return sceneHandler
4 changes: 2 additions & 2 deletions src/scenes/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function editorScene:firstEnter()
local updater = require("updater")
local hotkeyHandler = require("hotkey_handler")

local viewportHandler = require("viewport_handler")
local viewportDevice = require("input_devices.viewport_device")
local hotkeyDevice = hotkeyHandler.createHotkeyDevice(standardHotkeys)
local backupDevice = backups.createBackupDevice()
local userInterfaceDevice = require("ui.ui_device")
Expand All @@ -59,7 +59,7 @@ function editorScene:firstEnter()

inputDevice.newInputDevice(self.inputDevices, inputCaptureDevice)
inputDevice.newInputDevice(self.inputDevices, userInterfaceDevice)
inputDevice.newInputDevice(self.inputDevices, viewportHandler.device)
inputDevice.newInputDevice(self.inputDevices, viewportDevice)
inputDevice.newInputDevice(self.inputDevices, hotkeyDevice)
inputDevice.newInputDevice(self.inputDevices, backupDevice)
inputDevice.newInputDevice(self.inputDevices, mapLoaderDevice)
Expand Down
52 changes: 37 additions & 15 deletions src/tools/selection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ local dragMovementTotalX, dragMovementTotalY = 0, 0

local selectionRectangle = nil
local selectionCompleted = true
local selectionTargets = {}
local selectionPreviews = {}
local selectionTargets = state.selectionToolTargets
local selectionPreviews = state.selectionToolPreviews
local selectionCycleTargets = {}
local selectionCycleIndex = 1

Expand Down Expand Up @@ -101,9 +101,32 @@ local selectionRotationKeys = {
{"itemRotateRight", 1}
}

function tool.load()
tool.setSelectionTargets({})
tool.setSelectionPreviews({})
end

function tool.unselect()
selectionPreviews = {}
selectionTargets = {}
tool.setSelectionTargets({})
tool.setSelectionPreviews({})
end

function tool.getSelectionTargets()
return state.selectionToolTargets
end

function tool.getSelectionPreviews()
return state.selectionToolPreviews
end

function tool.setSelectionTargets(targets)
state.selectionToolTargets = targets
selectionTargets = targets
end

function tool.setSelectionPreviews(previews)
state.selectionToolPreviews = previews
selectionPreviews = previews
end

function tool.setLayer(layer)
Expand Down Expand Up @@ -136,10 +159,10 @@ local function selectionChanged(x, y, width, height, fromClick)
end

selectionCycleTargets = newSelections
selectionPreviews = {selectionCycleTargets[selectionCycleIndex]}
tool.setSelectionPreviews({selectionCycleTargets[selectionCycleIndex]})

else
selectionPreviews = newSelections
tool.setSelectionPreviews(newSelections)
selectionCycleTargets = {}
selectionCycleIndex = 0
end
Expand Down Expand Up @@ -661,8 +684,7 @@ local function pasteItems(room, layer, targets)
end
end

selectionTargets = newTargets

tool.setSelectionTargets(newTargets)
tiles.selectionsChanged(newTargets)

return relevantLayers
Expand Down Expand Up @@ -1045,13 +1067,13 @@ local function updateSelectionTargetsFromPreviews(keepExisting)
end

else
selectionTargets = selectionPreviews
tool.setSelectionTargets(selectionPreviews)
end
end

local function selectionStarted(x, y)
selectionRectangle = utils.rectangle(x, y, 0, 0)
selectionPreviews = {}
tool.setSelectionPreviews({})
selectionCompleted = false
resizeDirection = nil
resizeDirectionPreview = nil
Expand All @@ -1073,7 +1095,7 @@ local function selectionFinished(x, y, fromClick)
updateSelectionTargetsFromPreviews(addModifier)
tiles.selectionsChanged(selectionTargets)

selectionPreviews = {}
tool.setSelectionPreviews({})
end
end

Expand Down Expand Up @@ -1430,13 +1452,13 @@ function tool.keypressed(key, scancode, isrepeat)
end

function tool.editorMapLoaded(item, itemType)
selectionPreviews = {}
selectionTargets = {}
tool.setSelectionTargets({})
tool.setSelectionPreviews({})
end

function tool.editorMapTargetChanged(item, itemType)
selectionPreviews = {}
selectionTargets = {}
tool.setSelectionTargets({})
tool.setSelectionPreviews({})
end

function tool.draw()
Expand Down
3 changes: 2 additions & 1 deletion src/triggers/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ event.fieldInformation = {
event.placements = {
name = "event",
data = {
event = ""
event = "",
onSpawn = false,
}
}

Expand Down
Loading

0 comments on commit 5a31af5

Please sign in to comment.