2022-07-22 19:31:40 +00:00
|
|
|
-- Copyright (c) 2022 David Vogel
|
|
|
|
--
|
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
2022-07-23 18:43:04 +00:00
|
|
|
local Vec2 = require("noita-api.vec2")
|
2022-07-22 19:31:40 +00:00
|
|
|
|
|
|
|
-------------
|
|
|
|
-- Classes --
|
|
|
|
-------------
|
|
|
|
|
|
|
|
local CameraAPI = {}
|
|
|
|
|
|
|
|
------------------------
|
|
|
|
-- Noita API wrappers --
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
---
|
|
|
|
---@param strength number
|
|
|
|
---@param position Vec2|nil -- Defaults to camera position if not set.
|
2022-08-27 12:32:01 +00:00
|
|
|
function CameraAPI.ScreenShake(strength, position)
|
2022-07-22 19:31:40 +00:00
|
|
|
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
|
2022-07-23 15:45:06 +00:00
|
|
|
function CameraAPI.GetPos()
|
2022-07-22 19:31:40 +00:00
|
|
|
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
|