<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, May 15, 2018, 11:45 AM -->
<!-- MuClient version 5.06 - pre -->
<!-- Plugin "Aardwolf_Clock" generated by Plugin Wizard -->
<muclient >
<plugin name= "Aardwolf_Clock" author= "Crowley, with help from Fiendish" id= "28a36788fa20aa062e760ee2" language= "Lua" purpose= "Displays a realtime clock based on Aardwolf game time" save_state= "y" date_written= "2018-05-15 11:43:22" requires= "4.90" version= "5.00" >
</plugin>
<!-- Triggers -->
<triggers >
<trigger enabled= "n" match= "^\s+\*\s+It is ((?:\d+|Noon|Midnight))((?:p|a))?m? (?:in the daytime|in the evening|during the night) of the (\d+)(?:rd|th|nd|st) day of the Season of (?:the )?(\w+).*$" script= "getTime" regexp= "y" sequence= "100" omit_from_output= "n" name= "GetTime" >
</trigger>
</triggers>
<!-- Timers -->
<timers >
<timer script= "onTimer" second= "0.25" offset_second= "0.00" name= "clockTimer" enabled= "y" >
</timer>
</timers>
<!-- Aliases -->
<aliases >
<alias enabled= "y" match= "aardclock update" script= "update_plugin" sequence= "100" >
</alias>
<alias enabled= "y" match= "aardclock time" script= "forceUpdateTime" sequence= "100" >
</alias>
<alias enabled= "y" match= "aardclock help" script= "onHelp" sequence= "100" >
</alias>
</aliases>
<!-- Script -->
<script >
< ![CDATA[
require 'movewindow'
require 'themed_miniwindows'
async_ok, async = pcall (require, "async")
local s = 0
clock_seasons = {
Sun = {138, 3, 19, 1, "Light"},
Scourge = {162, 9, 18, 2, "Disease"},
River = {138, 7, 18, 3, "Water"},
Song = {150, 6, 19, 4, "Sonic"},
Energy = {148, 6, 20, 5, "Energy"},
Nature = {140, 5, 19, 6, "Earth"},
Snake = {142, 5, 20, 7, "Poison"},
Sword = {140, 7, 18, 8, "Slash"},
Freeze = {148, 9, 19, 9, "Cold"},
Thought = {148, 8, 20, 10, "Mental"},
Darkness = {134, 10, 18, 11, "Shadow"},
Corrosion = {136, 8, 20, 12, "Acid"},
Dagger = {120, 9, 18, 13, "Pierce"},
Storm = {140, 8, 19, 14, "Electric"},
Piety = {143, 7, 18, 15, "Holy"},
Suffering = {135, 6, 19, 16, "Negative"},
Burning = {144, 7, 20, 17, "Fire"},
Tornado = {142, 7, 21, 18, "Air"},
Stone = {120, 7, 21, 19, "Bash"},
Magi = {138, 6, 19, 20, "Magic"},
}
clock_season_order = {
"Sun",
"Scourge",
"River",
"Song",
"Energy",
"Nature",
"Snake",
"Sword",
"Freeze",
"Thought",
"Darkness",
"Corrosion",
"Dagger",
"Storm",
"Piety",
"Suffering",
"Burning",
"Tornado",
"Stone",
"Magi"
}
clock_current = {Season = "Sun", day = 1, order = 1}
win = "AardClock_Crowley"
font = "f"
checked_time = false
footer_text = {}
font_name = GetAlphaOption("output_font_name")
font_size = GetOption("output_font_height")
if not GetVariable("showTitleBar") then
SetVariable("showTitleBar", "true")
end
if not GetVariable("showDigital") then
SetVariable("showDigital", "false")
end
function findPos(t)
local spt = 12.0
local r = 62
local offset = 0
if t > 6 then
offset = font_width
elseif t< = 6 then
offset = font_width/2
end
local a = 2 * math.pi * (spt-t) / spt
local diff = 0.9 -- default 0.9
local s = math.sin(a)
local c = math.cos(a)
local x = 1 + round(cx - diff * r * s)
local y = 10 + round(cy - diff * r * c)
return {posx = x - offset, posy = y}
end
function createWindow()
clockWin = ThemedBasicWindow(
win, -- id
0, -- default_left_position
0, -- default_top_position
0, -- default_width
0, -- default_height
GetVariable("showTitleBar") == "true" and "AardClock" or nil, -- title
"center", -- title alignment
false, -- is_temporary
1, -- resizer_type
nil, -- do_while_resizing
nil, -- do_after_resizing
nil, -- do_on_delete
fontName, -- title_font_name
fontSize, -- title_font_size
true -- defer_showing
)
table.insert(clockWin.menu_table, "Show title bar")
table.insert(clockWin.menu_table, "Hide title bar")
table.insert(clockWin.menu_table, "Compact mode")
table.insert(clockWin.menu_table, "Full mode")
table.insert(
clockWin.menu_handlers,
function()
showTitleBar()
end
)
table.insert(
clockWin.menu_handlers,
function()
hideTitleBar()
end
)
table.insert(
clockWin.menu_handlers,
function()
showDigital()
end
)
table.insert(
clockWin.menu_handlers,
function()
showAnalog()
end
)
WindowFont(win, font, clockWin.title_font_name, clockWin.title_font_size, true)
title_height = (GetVariable("showTitleBar") == "true" and (WindowFontInfo(win, font, 1) + 5)) or 0
WindowFont(win, font, font_name, font_size, true)
font_height = WindowFontInfo(win, font, 1)
font_width = WindowTextWidth(win, font, " ", 1)
window_width = (20 * font_width) + 11
cx = math.floor((window_width-5)/2) + 3
cy = cx + font_height + title_height
clock_numbers = {}
for i = 1,12 do
table.insert(clock_numbers, {text = i, pos = findPos(i)})
end
endy = GetVariable("showDigital") == "false" and clock_numbers[6].pos.posy or (#footer_text + 5) * font_height
starty = GetVariable("showDigital") == "false" and clock_numbers[12].pos.posy or 0
window_height = font_height + title_height + 5 + endy + starty + (font_height * (#footer_text + 2))
clockWin:resize(window_width, window_height)
end
createWindow()
function showDigital()
SetVariable("showDigital", "true")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
function showAnalog()
SetVariable("showDigital", "false")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
function showTitleBar()
SetVariable("showTitleBar", "true")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
function hideTitleBar()
SetVariable("showTitleBar", "false")
SaveState()
clockWin:hide()
createWindow()
Execute("aardclock time")
end
require 'tprint'
function round(v)
local r = 0
if type(v) == 'number' then
i, f = math.modf(v)
if f >0.5 then
r = i + 1
else
r = i
end
end
return r
end
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
bgDay = 'khaki'
bgNight = 'navy'
textDay = 'black'
textNight = 'white'
hourTime = 12
bgColour = 'khaki'
textColour = 'black'
handDay = 'black'
handNight = 'yellow'
handColour = 'black'
function drawHand(t, r, subset)
local y9, x12, y3, x6 = findPos(9), findPos(12), findPos(3), findPos(6)
local startx, starty, endx, endy = x12.posx + (font_width)/2, y9.posy + (font_height/2), x6.posx + font_width/2, y3.posy + font_height/2
local tcx = (startx + endx)/2 -- + startx
local tcy = (starty + endy)/2 -- + starty
local spt = subset
local a = 2 * math.pi * (spt-t)/ spt
local s = math.sin(a)
local c = math.cos(a)
local x1 = 1 + round(tcx + 0.1 * r * s)
local y1 = 1 + round(tcy + 0.1 * r * c)
local x2 = 1 + round(tcx - 0.9 * r * s)
local y2 = 1 + round(tcy - 0.9 * r * c)
WindowLine(win, x1, y1, x2, y2, ColourNameToRGB(handColour), miniwin.pen_solid + miniwin.pen_join_miter + miniwin.pen_endcap_round, 2)
end
function circleDraw(x, y, r)
local y9, x12, y3, x6 = findPos(9), findPos(12), findPos(3), findPos(6)
local startx, starty, endx, endy = x12.posx + (font_width)/2, y9.posy + (font_height/2), x6.posx + font_width/2, y3.posy + font_height/2
local tcx = (startx + endx)/2 -- + startx
local tcy = (starty + endy)/2 -- + starty
local left, top, right, bottom = tcx - r, tcy - r, tcx + r, tcy + r
return {l = left, t = top, r = right, b = bottom}
end
function drawFace()
clockWin:blank()
WindowDrawImage(win, "background", 0, 0, (WindowInfo(win, 3) or 0), (WindowInfo(win, 4) or 0), miniwin.image_stretch)
local addPos = GetVariable("showDigital") == "false" and clock_numbers[6].pos.posy or 10
local x = 5
local y = (title_height + font_height * 2) + addPos
WindowText(win, font, seasonEnd, center(seasonEnd), font_height/2 + title_height, 0, 0, ColourNameToRGB(textColour))
local sunr = (clock_seasons[clock_current.Season][2] or 1) .. "am"
local suns = ((tonumber(clock_seasons[clock_current.Season][3]) - 12) or 12) .. "pm"
WindowText(win, font, sunr, x, title_height + font_height*1.5, 0, 0, ColourNameToRGB(textColour))
local cdiml, cdimt = font_width, title_height + font_height*2.5
local cdimr, cdimb = cdiml + font_width*2, cdimt + (font_width*2)
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("yellow"), 2, 1, ColourNameToRGB("yellow"), 0)
cdiml = (WindowInfo(win, 3) - 5) - font_width*3
cdimr = cdiml + font_width*2
WindowText(win, font, suns, ((WindowInfo(win, 3) -5) - font_width*4), title_height + font_height*1.5, 0, 0, ColourNameToRGB(textColour))
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("orangered"), 2, 1, ColourNameToRGB("orangered"), 0)
sqdim = circleDraw(cx, cy, 68)
if GetVariable("showDigital") == "false" then
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
sqdim = circleDraw(cx, cy, 70)
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
sqdim = circleDraw(cx, cy, 71)
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
sqdim = circleDraw(cx, cy, 72)
WindowCircleOp(win, 1, sqdim.l, sqdim.t, sqdim.r, sqdim.b, ColourNameToRGB(handColour), 0, 1, 0, 1)
for _,v in ipairs(clock_numbers) do
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
end
end
if GetVariable("showDigital") == "true" then
dTime = string.format("%s:%02d%s", tostring(hourTime), math.floor(s)*2, postTime)
else
dTime = hourTime .. postTime
end
WindowText(win, font, (dTime or ""), center((dTime or "")), y, 0, 0, ColourNameToRGB(textColour))
y = y + font_height
WindowText(win, font, string.format("[ Day %d of %d ]", footer_text.Day, footer_text.Cycle), center(string.format("[ Day %d of %d ]", footer_text.Day, footer_text.Cycle)), y, 0, 0, ColourNameToRGB(textColour))
y = y + font_height
WindowText(win, font, string.format("Season of %s", footer_text.Season), center(string.format("Season of %s", footer_text.Season)), y, 0, 0, ColourNameToRGB(textColour))
y = y + font_height
WindowText(win, font, string.format("[ %s ]", footer_text.DamType), center(string.format("[ %s ]", footer_text.DamType)), y, 0, 0, ColourNameToRGB(textColour))
if GetVariable("showDigital") == "true" then
y = y + font_height
WindowText(win, font, "[ Next tick: " .. 30 - math.floor(s) .. " ]", center("[ Next tick: " .. 30 - math.floor(s) .. " ]"), y, 0, 0, ColourNameToRGB(textColour))
--clockWin:resize(window_width, y+font_height)
end
WindowRectOp(win, 4, 1, 1, WindowInfo(win, 3)-1, WindowInfo(win, 4)-1, ColourNameToRGB("black"), ColourNameToRGB("black")) -- 9, 15 + 0x1000 + 0x4000)
clockWin:dress_window()
--clockWin:resize(window_width, window_height)
Redraw()
end
function center(t)
local twid = WindowTextWidth(win, font, t or 0)
local cdiff = window_width - twid
return cdiff/2
end
function OnPluginBroadcast (msg, id, name, text)
if (id == '3e7dedbe37e44942dd46d264') then
if (text == 'comm.tick') then
if checked_time then
if hourTime == 12 then
hourTime = 1
else
hourTime = hourTime + 1
end
if rTime == 23 then
rTime = 0
updateDay()
else
rTime = rTime + 1
end
if rTime >= 12 then
postTime = "pm"
else
postTime = "am"
end
checkColours()
ResetTimer("clockTimer")
last_tick = os.clock()
onTimer()
else
EnableTrigger("GetTime")
Send(" time")
end
end
end
end
function OnPluginConnect()
checked_time = false
end
function forceUpdateTime()
EnableTrigger("GetTime")
Send(" time")
end
function checkColours()
local sunrise, sunset = clock_seasons[clock_current.Season][2], clock_seasons[clock_current.Season][3]
if rTime >= sunrise and rTime < sunset t h e n
bgColour = bgDay
textColour = textDay
handColour = handDay
bgImage = "cloud"
elseif rTime >= sunset or rTime < sunrise t h e n
bgColour = bgNight
textColour = textNight
handColour = handNight
sunsetColour = textColour
bgImage = "darkstone"
end
WindowLoadImage(win, "background", GetInfo(66) .. "/worlds/plugins/images/" .. bgImage .. ".png")
end
function getTime(name, line, args)
clock_current = {Season = args[4], day = tonumber(args[3]), order = clock_seasons[args[4]][4]}
footer_text = {Day = tonumber(args[3]), Season = args[4], Cycle = clock_seasons[args[4]][1], DamType = clock_seasons[args[4]][5]}
if args[1] == "Noon" then
hourTime = 12
rTime = 12
elseif args[1] == "Midnight" then
hourTime = 12
rTime = 0
else
hourTime = tonumber(args[1])
if args[2] == "a" then
rTime = tonumber(args[1])
postTime = "am"
else
rTime = tonumber(args[1]) + 12
postTime = "pm"
end
end
checkColours()
updateTime()
checked_time = true
EnableTrigger("GetTime", false)
clockWin:show()
end
function updateTime()
seasonEnd = "Season ends: "
local days, hours, cday = clock_seasons[clock_current.Season][1], rTime, clock_current.day
local days_left = days - cday
local days_mins_left = (days_left-1) * 12
local day_mins_left = 24 - (rTime * 0.5)
local mins_left = days_mins_left + day_mins_left
local rH, rM = math.floor(mins_left/60), math.floor(mins_left%60)
seasonEnd = seasonEnd .. rH .. "h " .. rM .. "m"
end
function onTimer()
if checked_time then
last_tick = last_tick or os.clock()
s = os.clock() - last_tick
updateTime()
clockWin:blank()
drawFace()
if GetVariable("showDigital") == "false" then
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
end
Redraw()
end
end
function updateDay()
if clock_current.day == clock_seasons[clock_current.Season][1] then
if clock_current.order == #clock_season_order then
clock_current.order = 1
clock_current.Season = "Sun"
clock_current.day = 1
else
clock_current.order = clock_current.order + 1
clock_current.Season = clock_season_order[clock_current.order]
clock_current.day = 1
end
else
clock_current.day = clock_current.day + 1
end
footer_text = {Day = clock_current.day, Cycle = clock_seasons[clock_current.Season][1], Season = clock_current.Season, DamType = clock_seasons[clock_current.Season][5]}
end
function update_plugin()
raw = "https://raw.githubusercontent.com/AardCrowley/Aardwolf-Scripts/master/Aardwolf_Clock%20V2/Aardwolf_Clock.xml"
if async_ok then
plugin_page = async.doAsyncRemoteRequest(raw, raw_get, "HTTPS")
else
ColourNote("white", "blue", "Error on plugin update!")
end
end
function raw_get(retval, page, status, headers, full_status, request_url)
if status == 200 then
raw_version = tonumber(string.match(page, '%s+version="([0-9%.]+)">'))
end
if raw_version == PLUGIN_VERSION then
ColourNote("white", "blue", PLUGIN_NAME .. " is up-to-date.")
elseif raw_version > PLUGIN_VERSION then
ColourNote("white", "blue", "Updating from version " .. PLUGIN_VERSION .. " to " .. raw_version .. ". Do not touch anything!")
local file = io.open(GetPluginInfo(GetPluginID(), 6), "w")
file:write(page)
file:close()
if "" == GetAlphaOption("script_prefix") then
SetAlphaOption("script_prefix", "\\\\\\")
end
Execute(GetAlphaOption("script_prefix") .. "DoAfterSpecial(1, \"ReloadPlugin('" .. GetPluginID() .. "')\", sendto.script)")
ColourNote("white", "blue", "Update complete!")
end
raw_version = nil
end -- end Update code
function onHelp()
ColourNote("orange", "", "AardClock Help (Generic until I make it better)")
ColourNote("orange", "", "aardclock time -- force an update of time, useful for disconnections and reboots")
ColourNote("orange", "", "aardclock update -- automatically update the plugin when new versions come out")
ColourNote("orange", "", "aardlock help -- what you're reading now...")
end
]]>
</script>
</muclient>