shipcompass.lua

--- Compass for general shipboard use. Packaged up all nice and pretty. I think so, anyway.
--@classmod ShipCompass



--------------------------------------------------------------------------------
--- Public methods.
-- For creating and Initialising ShipCompass object.
-- @section Public
--------------------------------------------------------------------------------

ShipCompass = {}

----------------------------------------
--- Creates a new instance of the ShipCompass class and its display
-- @tparam string _instanceName Name for the consoles and such. Should be identical to object's unique name.
-- @tparam int _x X screen coordinate of ShipCompass's top-left point.
-- @tparam int _y Y screen coordinate of ShipCompass's top-left point.
-- @treturn table A new instance of the ShipCompass class.
-- @usage compass = ShipCompass:new("compass",14,587)
function ShipCompass:new(_instanceName, _x, _y)

    ShipCompass.__index = ShipCompass
    local self = setmetatable({}, ShipCompass)

    self._instanceName = tostring(_instanceName)

    self.container = Geyser.Label:new({
        name = self._instanceName..".container",
        x = _x, y = _y,
        width = 483, height = 456,
    })

    self.courseNeedle = Geyser.Label:new({
        name = self._instanceName..".courseNeedle",
        x = 42, y = 22,
        width = 310, height = 310,
    }, self.container)

    self.windNeedle = Geyser.Label:new({
        name = self._instanceName..".windNeedle",
        x = 42, y = 22,
        width = 310, height = 310,
    }, self.container)

    self.bearingNeedle = Geyser.Label:new({
        name = self._instanceName..".bearingNeedle",
        x = 35, y = 20,
        width = 324, height = 324,
    }, self.container)

    self.container:setStyleSheet([[background-color: #00000000;]])

    self.bearingNeedle:raise()
    self.windNeedle:raise()
    self.courseNeedle:raise()

    self:setCourseNeedle("n")
    self:setWindNeedle("n")
    self:setBearingNeedle(0)

    self._updateHandler = self._updateHandler or registerAnonymousEventHandler("ship done with prompt", self._instanceName..":update")

    return self

end





--------------------------------------------------------------------------------
--- Private methods.
-- ***Privatise these, you silly bird.***
-- @todo Privatise these methods!
-- @section Public
--------------------------------------------------------------------------------

----------------------------------------
--- Sets the orientation of the course needle.
-- @tparam string _direction Direction in short format.
-- @usage compass:setCourseNeedle("nw")
function ShipCompass:setCourseNeedle(_direction)

    _direction = string.lower(_direction)

    self.courseNeedle:setStyleSheet([[
        background-color: #00000000;
        border-image: url(]]..cloudDir:gsub("\\","/")..[[GUI/images/needles/big16/]].._direction..[[.png);
    ]])

    self.courseNeedle._displayed = _direction

end

----------------------------------------
--- Sets the orientation of the wind needle.
-- @tparam string _direction Direction in short format.
-- @usage compass:setWindNeedle("ne")
function ShipCompass:setWindNeedle(_direction)

    _direction = string.lower(_direction)

    self.windNeedle:setStyleSheet([[
        background-color: #00000000;
        border-image: url(]]..cloudDir:gsub("\\","/")..[[GUI/images/needles/bigred16/]].._direction..[[.png);
    ]])

    self.windNeedle._displayed = _direction

end



----------------------------------------
--- Sets the orientation of the bearing needle.
-- @tparam int _direction Direction in rounded degrees.
-- @usage compass:setBearingNeedle(270)
function ShipCompass:setBearingNeedle(_direction)

    _direction = string.lower(_direction)

    self.bearingNeedle:setStyleSheet([[
        background-color: #00000000;
        border-image: url(]]..cloudDir:gsub("\\","/")..[[GUI/images/needles/outer360/]].._direction..[[.png);
    ]])

    self.bearingNeedle._displayed = _direction

end



----------------------------------------
--- Sets the orientation of the bearing needle.
-- @tparam int to_X X coordinate to move top-left point of container to, in screen coordinates.
-- @tparam int to_Y Y coordinate to move top-left point of container to, in screen coordinates.
-- @usage compass:move(273,270)
function ShipCompass:move(to_X,to_Y)

    self.container:move(to_X,to_Y)

end




----------------------------------------
--- Updates needles. Has event handler to handle it trigger-free.
-- Ship:processPrompt
-- @tparam args Takes in prompt data from event handler.
function ShipCompass:update(...)

    local promptTable = arg[2]

    self:setCourseNeedle  (promptTable._course)
    self:setWindNeedle    (promptTable._windDirection)
    --self:setBearingNeedle (0)

end
generated by LDoc 1.4.3 Last updated 2021-01-24 20:08:44