noita-mapcap/files/libraries/noita-api/camera.lua
David Vogel 98dfb5fbb0 Cleanup, Refactoring and Fixes
- Remove unused util functions
- Put util stuff into its own namespace
- Move all initialization stuff into root init.lua
- Move progressBarString function into ui.lua
- Fix ffi.load error message
- Fix DebugAPI.BiomeMapGetFilename
- Move JSON lib into Noita API wrapper
- Move Vec2 lib into Noita API wrapper
- Move compatibility stuff into Noita API wrapper
- Emulate package tables if in restricted API mode
- Emulate require if in restricted API mode
- Use require instead of dofile_once everywhere
- Fix WrapID method to accept nil
- Add EmmyLua annotations for the default Noita API
- Add README.md to Noita API wrapper
2022-07-23 17:36:21 +02:00

57 lines
1.4 KiB
Lua

-- Copyright (c) 2022 David Vogel
--
-- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT
local Vec2 = require("libraries.noita-api.vec2")
-------------
-- Classes --
-------------
---@class NoitaCameraAPI
local CameraAPI = {}
------------------------
-- Noita API wrappers --
------------------------
---
---@param strength number
---@param position Vec2|nil -- Defaults to camera position if not set.
function CameraAPI.Screenshake(strength, position)
if position == nil then
return GameScreenshake(strength)
end
return GameScreenshake(strength, position.x, position.y)
end
---Returns the center position of the viewport in world/virtual coordinates.
---@return Vec2
function CameraAPI.Pos()
return Vec2(GameGetCameraPos())
end
---Sets the center position of the viewport in world/virtual coordinates.
---@param position Vec2
function CameraAPI.SetPos(position)
return GameSetCameraPos(position.x, position.y)
end
---
---@param isFree boolean
function CameraAPI.SetCameraFree(isFree)
return GameSetCameraFree(isFree)
end
---Returns the camera boundary rectangle in world/virtual coordinates.
---This may not be 100% pixel perfect with regards to what you see on the screen.
---@return Vec2 topLeft
---@return Vec2 bottomRight
function CameraAPI.Bounds()
local x, y, w, h = GameGetCameraBounds()
return Vec2(x, y), Vec2(x + w, y + h)
end
return CameraAPI