add love.system.getOS and improve message box styling

This commit is contained in:
banepwn 2020-04-04 03:33:22 -04:00
parent eeeb79651b
commit 870f0d2f8f
6 changed files with 97 additions and 6 deletions

View File

@ -12,6 +12,7 @@
<!-- Tip: To run your own Lua on the fly, run `fengari.load("your code here")()` in console -->
<div id="infatuated-msgbox" data-hidden="true">
<span id="infatuated-msgbox-title">Title</span>
<button aria-label="Close" id="infatuated-msgbox-close">&times;</button>
<hr>
<span id="infatuated-msgbox-text">Message</span>
<div id="infatuated-msgbox-buttons">

View File

@ -4,6 +4,7 @@ local function print(...)
end
infatuated = {}
infatuated.print = print
infatuated.version = "11.3"
infatuated.conf = {
identity = nil,
@ -210,6 +211,7 @@ infatuated.thread = coroutine.create(function()
require "modules.handlers"
require "modules.image"
require "modules.math"
require "modules.system"
require "modules.timer"
require "modules.window"

View File

@ -13,3 +13,20 @@ function love.math.colorFromBytes(r, g, b, a)
return clamp(r/256), clamp(g/256), clamp(b/256)
end
end
function love.math.setRandomSeed(n, n2)
assert(type(n) == "number", "bad argument #1 to setRandomSeed (expected number)")
assert(not n2, "not implemented")
infatuated.randomseed = n
math.randomseed(n)
end
function love.math.random(n1, n2)
if n1 then
if n2 then
return math.random(n1)
else
return math.random(n1, n2)
end
else
return math.random()
end
end

36
modules/system.lua Normal file
View File

@ -0,0 +1,36 @@
love.system = {}
local window = infatuated.js.global.window
--local orientation = window.orientation or (window.screen and (window.screen.orientation or window.screen.mozOrientation or window.screen.msOrientation))
local useragent = window.navigator and window.navigator.userAgent:lower() or ""
local platform = window.navigator and (window.navigator.platform.." "):match("^(.-) "):lower() or ""
local platformIDs = {
android = "Android",
blackberry = "Android",
nintendo = "Android",
psp = "Android",
iphone = "iOS",
ipod = "iOS",
ipad = "iOS",
macintosh = "OS X",
macintel = "OS X",
macppc = "OS X",
mac68k = "OS X",
freebsd = "Linux",
openbsd = "Linux",
linux = "Linux",
x11 = "Linux",
playstation = "Linux",
orbisos = "Linux",
windows = "Windows",
win16 = "Windows",
win32 = "Windows",
win64 = "Windows",
wince = "Windows" -- amirite
}
function love.system.getOS()
if useragent:find("android") then return "Android" end -- fucking "Linux 50m3_r4nd0m_5h1t"
if useragent:find("iphone") then return "iOS" end -- fucking "general Mobile Device"
return platformIDs[platform] or platform:find("mobile") and "Android" or "Windows"
end
love._os = love.system.getOS() -- 0.8.0 compatibility
infatuated.print("Detected OS as %s", love._os)

View File

@ -14,8 +14,9 @@ function love.window.showMessageBox(title, message, buttonlist, mbtype, attachto
if type(buttonlist) == "string" then
attachtowindow = mbtype
mbtype = buttonlist
buttonlist = {"OK"}
buttonlist = nil
end
local shouldreturn = buttonlist ~= nil
buttonlist = buttonlist or {"OK"}
mbtype = mbtype or "info"
attachtowindow = attachtowindow or true
@ -23,11 +24,11 @@ function love.window.showMessageBox(title, message, buttonlist, mbtype, attachto
assert(type(mbtype) == "string", "bad argument #4 to title (string expected)")
assert(type(attachtowindow) == "boolean", "bad argument #5 to title (boolean expected)")
local co = assert(coroutine.running(infatuated.thread), "must be run in a coroutine")
local ret
local retval
infatuated.msgbox:show(title, message, buttonlist, function(i)
ret = i
retval = i
coroutine.resume(infatuated.thread)
end)
coroutine.yield()
return ret
return shouldreturn and retval or true
end

View File

@ -3,6 +3,9 @@ body {
color: #ddd;
font-family: monospace;
}
* {
transition: all 0.1s;
}
#infatuated-canvas,
#infatuated-msgbox {
position: absolute;
@ -13,10 +16,36 @@ body {
#infatuated-msgbox-title {
font-weight: bold;
}
#infatuated-msgbox-close {
font-weight: bold;
float: right;
width: 1.25em;
text-align: center;
border-radius: 1em;
border: none;
padding: 0;
background: #f700;
color: #ddd;
}
#infatuated-msgbox-close:focus,
#infatuated-msgbox-close:hover {
background: #f70;
color: #000;
cursor: pointer;
}
#infatuated-msgbox-close:focus,
#infatuated-msgbox-close:focus *,
#infatuated-msgbox-buttons button:focus *,
#infatuated-msgbox-buttons button:focus {
/* WHY DOESN'T THIS WORK???? */
outline: none;
}
#infatuated-msgbox {
background: #222;
border: 1px solid #777;
box-shadow: #000 0 0 25px;
border-radius: 0.25em;
padding: 2em;
z-index: 3;
}
@ -42,14 +71,19 @@ body {
position: relative;
margin: 1rem auto 0 auto;
}
button {
#infatuated-msgbox-buttons button {
background: #333;
color: #eee;
border: 1px solid #777;
font-family: monospace;
text-align: center;
}
button:not(:last-child) {
#infatuated-msgbox-buttons button:focus,
#infatuated-msgbox-buttons button:hover {
background: #444;
box-shadow: #fff7 0 0 0.25em;
}
#infatuated-msgbox-buttons button:not(:last-child) {
margin-right: 0.5rem;
}
#infatuated-canvas {