@ -6,14 +6,14 @@
<!-- Plugin "Aardwolf_Clock" generated by Plugin Wizard -->
<!-- Plugin "Aardwolf_Clock" generated by Plugin Wizard -->
<muclient >
<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= " 2.8 4">
<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= " 4.00 ">
</plugin>
</plugin>
<!-- Triggers -->
<!-- Triggers -->
<triggers >
<triggers >
<trigger enabled= "n" match= "^\s+\*\s+It is ((?:\d+|Noon|Midnight))((?:p|a))?m? on 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 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>
</trigger>
</triggers>
</triggers>
@ -41,9 +41,12 @@
<script >
<script >
< ![CDATA[
< ![CDATA[
require 'movewindow'
require 'movewindow'
require 'themed_miniwindows'
clock_seasons = {
async_ok, async = pcall (require, "async")
clock_seasons = {
Sun = {138, 3, 19, 1, "Light"},
Sun = {138, 3, 19, 1, "Light"},
Scourge = {162, 9, 18, 2, "Disease"},
Scourge = {162, 9, 18, 2, "Disease"},
River = {138, 7, 18, 3, "Water"},
River = {138, 7, 18, 3, "Water"},
@ -64,9 +67,9 @@
Tornado = {142, 7, 21, 18, "Air"},
Tornado = {142, 7, 21, 18, "Air"},
Stone = {120, 7, 21, 19, "Bash"},
Stone = {120, 7, 21, 19, "Bash"},
Magi = {138, 6, 19, 20, "Magic"},
Magi = {138, 6, 19, 20, "Magic"},
}
}
clock_season_order = {
clock_season_order = {
"Sun",
"Sun",
"Scourge",
"Scourge",
"River",
"River",
@ -87,55 +90,65 @@
"Tornado",
"Tornado",
"Stone",
"Stone",
"Magi"
"Magi"
}
}
clock_current = {Season = "Sun", day = 1, order = 1}
local win = "AardClock_" .. GetPluginID()
clock_current = {Season = "Sun", day = 1, order = 1}
local font = "f"
windowinfo = movewindow.install(win, 7, miniwin.create_absolute_location, true, nil)
win = "AardClock_Crowley"
font = "f"
checked_time = false
checked_time = false
local footer_text = {}
footer_text = {}
local font_families = utils.getfontfamilies()
font_families = utils.getfontfamilies()
if font_families["Monoid"] then
if font_families["Monoid"] then
font_name = "Monoid"
font_name = "Monoid"
font_size = 8
font_size = 8
elseif font_families["Dina"] then
elseif font_families["Dina"] then
font_name = "Dina"
font_name = "Dina"
font_size = 8
font_size = 8
elseif font_families["Lucida Sans Console"] then
elseif font_families["Lucida Sans Console"] then
font_name = "Lucida Sans Console"
font_name = "Lucida Sans Console"
font_size = 10
font_size = 10
else
else
font_name = "Consolas"
font_name = "Consolas"
font_size = 10
font_size = 10
end
end
WindowCreate(win, 0, 0, 0, 0, 1, 0, 0)
clockWin = ThemedBasicWindow(
WindowFont(win, font, font_name, font_size, true)
win, -- id
local font_height = WindowFontInfo(win, font, 1)
0, -- default_left_position
local font_width = WindowTextWidth(win, font, " ", 1)
0, -- default_top_position
0, -- default_width
window_width = (20 * font_width) + 11
0, -- default_height
local cx = math.floor((window_width-5)/2) + 3
"AardClock", -- title
local cy = cx + font_height
"center", -- title alignment
false, -- is_temporary
bgDay = 'khaki'
1, -- resizer_type
bgNight = 'navy'
nil, -- do_while_resizing
textDay = 'black'
nil, -- do_after_resizing
textNight = 'white'
nil, -- do_on_delete
hourTime = 12
fontName, -- title_font_name
bgColour = 'khaki'
fontSize, -- title_font_size
textColour = 'black'
true -- defer_showing
handDay = 'black'
)
handNight = 'yellow'
handColour = 'black'
require 'tprint'
--tprint(clockWin)
function round(v)
WindowFont(win, font, clockWin.title_font_name, clockWin.title_font_size, true)
title_height = WindowFontInfo(win, font, 1) + 5
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
function round(v)
local r = 0
local r = 0
if type(v) == 'number' then
if type(v) == 'number' then
i, f = math.modf(v)
i, f = math.modf(v)
@ -146,9 +159,9 @@
end
end
end
end
return r
return r
end
end
function findPos(t)
function findPos(t)
local spt = 12.0
local spt = 12.0
local r = 62
local r = 62
local offset = 0
local offset = 0
@ -169,9 +182,35 @@
local y = 10 + round(cy - diff * r * c)
local y = 10 + round(cy - diff * r * c)
return {posx = x - offset, posy = y}
return {posx = x - offset, posy = y}
end
end
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
function drawHand(t, r, subset)
clock_numbers = {}
for i = 1,12 do
table.insert(clock_numbers, {text = i, pos = findPos(i)})
end
endy = clock_numbers[6].pos.posy
starty = clock_numbers[12].pos.posy
window_height = font_height + title_height + 5 + endy + starty + (font_height * (#footer_text + 2)) -- font_height * 10
clockWin:resize(window_width, window_height)
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 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 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 tcx = (startx + endx)/2 -- + startx
@ -187,9 +226,9 @@
local y2 = 1 + round(tcy - 0.9 * r * c)
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)
WindowLine(win, x1, y1, x2, y2, ColourNameToRGB(handColour), miniwin.pen_solid + miniwin.pen_join_miter + miniwin.pen_endcap_round, 2)
end
end
function circleDraw(x, y, r)
function circleDraw(x, y, r)
local y9, x12, y3, x6 = findPos(9), findPos(12), findPos(3), findPos(6)
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 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 tcx = (startx + endx)/2 -- + startx
@ -197,22 +236,23 @@
local left, top, right, bottom = tcx - r, tcy - r, tcx + r, tcy + r
local left, top, right, bottom = tcx - r, tcy - r, tcx + r, tcy + r
return {l = left, t = top, r = right, b = bottom}
return {l = left, t = top, r = right, b = bottom}
end
end
function drawFace()
function drawFace()
clockWin:blank()
WindowDrawImage(win, "background", 0, 0, (WindowInfo(win, 3) or 0), (WindowInfo(win, 4) or 0), miniwin.image_stretch)
WindowDrawImage(win, "background", 0, 0, (WindowInfo(win, 3) or 0), (WindowInfo(win, 4) or 0), miniwin.image_stretch)
local x = 5
local x = 5
local y = clock_numbers[6].pos.posy + font_height * 2
local y = clock_numbers[6].pos.posy + title_height + font_height * 2
WindowText(win, font, seasonEnd, center(seasonEnd), font_height/2, 0, 0, ColourNameToRGB(textColour))
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 sunr = (clock_seasons[clock_current.Season][2] or 1) .. "am"
local suns = ((tonumber(clock_seasons[clock_current.Season][3]) - 12) or 12) .. "pm"
local suns = ((tonumber(clock_seasons[clock_current.Season][3]) - 12) or 12) .. "pm"
WindowText(win, font, sunr, x, font_height*1.5, 0, 0, ColourNameToRGB(textColour))
WindowText(win, font, sunr, x, title_height + font_height*1.5, 0, 0, ColourNameToRGB(textColour))
local cdiml, cdimt = font_width, font_height*2.5
local cdiml, cdimt = font_width, title_height + font_height*2.5
local cdimr, cdimb = cdiml + font_width*2, cdimt + (font_width*2)
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)
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("yellow"), 2, 1, ColourNameToRGB("yellow"), 0)
@ -220,7 +260,7 @@
cdiml = (WindowInfo(win, 3) - 5) - font_width*3
cdiml = (WindowInfo(win, 3) - 5) - font_width*3
cdimr = cdiml + font_width*2
cdimr = cdiml + font_width*2
WindowText(win, font, suns, ((WindowInfo(win, 3) -5) - font_width*4), font_height*1.5, 0, 0, ColourNameToRGB(textColour))
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)
WindowCircleOp(win, 1, cdiml, cdimt, cdimr, cdimb, ColourNameToRGB("orangered"), 2, 1, ColourNameToRGB("orangered"), 0)
@ -242,7 +282,6 @@
for _,v in ipairs(clock_numbers) do
for _,v in ipairs(clock_numbers) do
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
WindowText(win, font, v.text, v.pos.posx, v.pos.posy, 0, 0, ColourNameToRGB(textColour))
end
end
WindowText(win, font, (dTime or ""), center((dTime or "")), y, 0, 0, ColourNameToRGB(textColour))
WindowText(win, font, (dTime or ""), center((dTime or "")), y, 0, 0, ColourNameToRGB(textColour))
@ -253,20 +292,20 @@
y = y + font_height
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))
WindowText(win, font, string.format("[ %s ]", footer_text.DamType), center(string.format("[ %s ]", footer_text.DamType)), y, 0, 0, ColourNameToRGB(textColour))
WindowRectOp(win, 4, 1, 1, WindowInfo(win, 3)-1, WindowInfo(win, 4)-1, ColourNameToRGB("black"), ColourNameToRGB("black")) -- 9, 15 + 0x1000 + 0x4000)
WindowRectOp(win, 4, 1, 1, WindowInfo(win, 3)-1, WindowInfo(win, 4)-1, ColourNameToRGB("black"), ColourNameToRGB("black")) -- 9, 15 + 0x1000 + 0x4000)
WindowSetZOrder(win, 50)
clockWin:dress_window()
WindowShow(win, true)
Redraw()
end
end
function center(t)
function center(t)
local twid = WindowTextWidth(win, font, t or 0)
local twid = WindowTextWidth(win, font, t or 0)
local cdiff = window_width - twid
local cdiff = window_width - twid
return cdiff/2
return cdiff/2
end
end
function OnPluginBroadcast (msg, id, name, text)
function OnPluginBroadcast (msg, id, name, text)
if (id == '3e7dedbe37e44942dd46d264') then
if (id == '3e7dedbe37e44942dd46d264') then
if (text == 'comm.tick') then
if (text == 'comm.tick') then
if checked_time then
if checked_time then
@ -298,18 +337,18 @@
end
end
end
end
end
end
end
end
function OnPluginConnect()
function OnPluginConnect()
checked_time = false
checked_time = false
end
end
function forceUpdateTime()
function forceUpdateTime()
EnableTrigger("GetTime")
EnableTrigger("GetTime")
Send(" time")
Send(" time")
end
end
function checkColours()
function checkColours()
local sunrise, sunset = clock_seasons[clock_current.Season][2], clock_seasons[clock_current.Season][3]
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
if rTime >= sunrise and rTime < sunset t h e n
@ -326,9 +365,9 @@
end
end
WindowLoadImage(win, "background", GetInfo(66) .. "/worlds/plugins/images/" .. bgImage .. ".png")
WindowLoadImage(win, "background", GetInfo(66) .. "/worlds/plugins/images/" .. bgImage .. ".png")
end
end
function getTime(name, line, args)
function getTime(name, line, args)
clock_current = {Season = args[4], day = tonumber(args[3]), order = clock_seasons[args[4]][4]}
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]}
footer_text = {Day = tonumber(args[3]), Season = args[4], Cycle = clock_seasons[args[4]][1], DamType = clock_seasons[args[4]][5]}
@ -356,9 +395,10 @@
checked_time = true
checked_time = true
EnableTrigger("GetTime", false)
EnableTrigger("GetTime", false)
end
clockWin:show()
end
function updateTime()
function updateTime()
seasonEnd = "Season ends: "
seasonEnd = "Season ends: "
local days, hours, cday = clock_seasons[clock_current.Season][1], rTime, clock_current.day
local days, hours, cday = clock_seasons[clock_current.Season][1], rTime, clock_current.day
@ -371,22 +411,25 @@
local rH, rM = math.floor(mins_left/60), math.floor(mins_left%60)
local rH, rM = math.floor(mins_left/60), math.floor(mins_left%60)
seasonEnd = seasonEnd .. rH .. "h " .. rM .. "m"
seasonEnd = seasonEnd .. rH .. "h " .. rM .. "m"
end
--clockWin.title = seasonEnd
end
function onTimer()
function onTimer()
if checked_time then
if checked_time then
last_tick = last_tick or os.clock()
last_tick = last_tick or os.clock()
local s = os.clock() - last_tick
local s = os.clock() - last_tick
updateTime()
updateTime()
clockWin:blank()
drawFace()
drawFace()
drawHand(math.min(30, s), 60, 30)
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
drawHand(hourHandTime, 45, 12)
--clockWin:dress_window()
Redraw()
Redraw()
end
end
end
end
function updateDay()
function updateDay()
if clock_current.day == clock_seasons[clock_current.Season][1] then
if clock_current.day == clock_seasons[clock_current.Season][1] then
if clock_current.order == #clock_season_order then
if clock_current.order == #clock_season_order then
clock_current.order = 1
clock_current.order = 1
@ -403,52 +446,19 @@
footer_text = {Day = clock_current.day, Cycle = clock_seasons[clock_current.Season][1], Season = clock_current.Season, DamType = clock_seasons[clock_current.Season][5]}
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
end
function OnPluginDisable()
WindowDelete(win)
end
function OnPluginSaveState()
movewindow.save_state(win)
end
function OnPluginClose()
OnPluginDisable()
end
function OnPluginInstall()
PLUGIN_VERSION = GetPluginInfo(GetPluginID(), 19)
PLUGIN_NAME = GetPluginInfo(GetPluginID(), 1)
seasonEnd = ""
clock_numbers = {}
for i = 1,12 do
table.insert(clock_numbers, {text = i, pos = findPos(i)})
end
local endy = clock_numbers[6].pos.posy
function update_plugin()
local starty = clock_numbers[12].pos.posy
local window_height = font_height + 5 + endy + starty + (font_height * (#footer_text + 2)) -- font_height * 10
WindowCreate(win, windowinfo.window_left, windowinfo.window_top, window_width, window_height, windowinfo.window_mode, windowinfo.window_flags + miniwin.create_keep_hotspots, ColourNameToRGB("black"))
movewindow.add_drag_handler (win, 0, 0, 0, window_height)
end
function update_plugin()
raw = "https://raw.githubusercontent.com/AardCrowley/Aardwolf-Scripts/master/Aardwolf_Clock%20V2/Aardwolf_Clock.xml"
raw = "https://raw.githubusercontent.com/AardCrowley/Aardwolf-Scripts/master/Aardwolf_Clock%20V2/Aardwolf_Clock.xml"
async_ok, async = pcall (require, "async")
if async_ok then
if async_ok then
plugin_page = async.doAsyncRemoteRequest(raw, raw_get, "HTTPS")
plugin_page = async.doAsyncRemoteRequest(raw, raw_get, "HTTPS")
else
else
ColourNote("white", "blue", "Error on plugin update!")
ColourNote("white", "blue", "Error on plugin update!")
end
end
end
end
function raw_get(retval, page, status, headers, full_status, request_url)
function raw_get(retval, page, status, headers, full_status, request_url)
if status == 200 then
if status == 200 then
raw_version = tonumber(string.match(page, '%s+version="([0-9%.]+)">'))
raw_version = tonumber(string.match(page, '%s+version="([0-9%.]+)">'))
end
end
@ -470,14 +480,14 @@
end
end
raw_version = nil
raw_version = nil
end -- end Update code
end -- end Update code
function onHelp()
function onHelp()
ColourNote("orange", "", "AardClock Help (Generic until I make it better)")
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 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", "", "aardclock update -- automatically update the plugin when new versions come out")
ColourNote("orange", "", "aardlock help -- what you're reading now...")
ColourNote("orange", "", "aardlock help -- what you're reading now...")
end
end
]]>
]]>
</script>
</script>