You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

479 lines
16 KiB

<?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="2.7">
</plugin>
<!-- 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>
</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>
</aliases>
<!-- Script -->
<script>
<![CDATA[
require 'movewindow'
clock_seasons = {
Sun = {138, 3, 19, 1, "Light"},
Scourge = {168, 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 = {131, 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}
local win = "AardClock_" .. GetPluginID()
local font = "f"
windowinfo = movewindow.install(win, 7, miniwin.create_absolute_location, true, nil, {mouseup = MoveMouseUp, mousedown = MoveMouseDown})
checked_time = false
local footer_text = {}
local font_families = utils.getfontfamilies()
if font_families["Monoid"] then
font_name = "Monoid"
font_size = 8
elseif font_families["Dina"] then
font_name = "Dina"
font_size = 8
elseif font_families["Lucida Sans Console"] then
font_name = "Lucida Sans Console"
font_size = 10
else
font_name = "Consolas"
font_size = 10
end
WindowCreate(win, 0, 0, 0, 0, 1, 0, 0)
WindowFont(win, font, font_name, font_size, true)
local font_height = WindowFontInfo(win, font, 1)
local font_width = WindowTextWidth(win, font, " ", 1)
window_width = (20 * font_width) + 11
local cx = math.floor((window_width-5)/2) + 3
local cy = cx + font_height
canRedraw = true
bgDay = 'khaki'
bgNight = 'navy'
textDay = 'black'
textNight = 'white'
hourTime = 12
bgColour = 'khaki'
textColour = 'black'
handDay = 'black'
handNight = 'yellow'
handColour = 'black'
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
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 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()
WindowDrawImage(win, "background", 0, 0, WindowInfo(win, 3), WindowInfo(win, 4), miniwin.image_stretch)
local x = 5
local y = clock_numbers[6].pos.posy + font_height * 2
WindowText(win, font, seasonEnd, center(seasonEnd), font_height/2, 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, font_height*1.5, 0, 0, ColourNameToRGB(textColour))
local cdiml, cdimt = font_width, 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), 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)
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
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))
WindowRectOp(win, 4, 1, 1, WindowInfo(win, 3)-1, WindowInfo(win, 4)-1, ColourNameToRGB("black"), ColourNameToRGB("black")) -- 9, 15 + 0x1000 + 0x4000)
WindowSetZOrder(win, 50)
WindowShow(win, true)
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
dTime = hourTime .. "pm"
else
dTime = hourTime .. "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 checkColours()
local sunrise, sunset = clock_seasons[clock_current.Season][2], clock_seasons[clock_current.Season][3]
if rTime >= sunrise and rTime < sunset then
bgColour = bgDay
textColour = textDay
handColour = handDay
bgImage = "cloud"
elseif rTime >= sunset or rTime < sunrise then
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])
dTime = hourTime .. "am"
else
rTime = tonumber(args[1]) + 12
dTime = hourTime .. "pm"
end
end
checkColours()
updateTime()
checked_time = true
EnableTrigger("GetTime", false)
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 canRedraw then
if checked_time then
last_tick = last_tick or os.clock()
local s = os.clock() - last_tick
updateTime()
drawFace()
drawHand(math.min(30, s), 60, 30)
hourHandTime = hourTime + s/30
drawHand(hourHandTime, 45, 12)
Redraw()
end
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 OnPluginDisable()
WindowDelete(win)
end
function OnPluginSaveState()
movewindow.save_state(win)
end
function MoveMouseDown()
canRedraw = false
print("Mousedown!")
end
function MoveMouseUp()
canRedraw = true
print("Mouseup!")
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
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"
async_ok, async = pcall (require, "async")
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
]]>
</script>
</muclient>