phigros.tools

Timers, toasts and files

Everything below hands out plain Lua copies: mods watch the game, they never steer it. Custom charts add songs to it (Custom charts), they don't change how the game's own play.

scene()

The current scene's name: "ChapterSelector", "SongSelector", "Level"...

print(scene()) --> SongSelector
if scene() == "Level" then toast("Later") end

Returns string

after(seconds, fn)

Runs fn once in seconds.

after(2, function() toast("Two seconds later") end)
ParameterType
secondsnumber
fnfun()

Returns fun() (cancel)

every(seconds, fn)

Runs fn every seconds.

local stop = every(0.5, function() print(stats().combo) end)
stop() -- it doesn't run again
ParameterType
secondsnumber
fnfun()

Returns fun() (cancel)

now()

Seconds since the game started.

local start = now()
local list = records()
print(("%d records in %.3f s"):format(#list, now() - start)) --> 84 records in 0.012 s

Returns number

ToastOptions

FieldType
seconds?numberat most 10
icon?Iconone of ui.icon's icons
avatar?stringa player's avatar, the game's key of it
tap?fun()runs when tapped, as a button's function does

toast(message, options?)

A message at the bottom left of the screen, for 4 seconds unless told: three show at once, the next ones wait their turn. Never over a song: one made meanwhile shows once it's left. One saying what another on screen or waiting says isn't made, whatever its icon. A tap dismisses a toast, and so does the function it returns.

toast("Saved")
toast("Saved", 8)
local dismiss = toast("Update ready", { seconds = 10, icon = "star", tap = function() end })
ParameterType
messageany
options?number|ToastOptionsseconds, 10 at most, a negative time is an error

Returns fun() (dismiss)

image(path)

A Sprite from a png or jpg next to the mod's file.

local logo = image("logo.png") -- logo.png next to init.lua
phigrospp.ui.rect(parent, "my-logo", { 40, 40 }, { 128, 128 }, { 1, 1, 1, 1 }).sprite = logo
ParameterType
pathstring

Returns Sprite

phigrospp.dir()

The mod's folder: installed/<owner>/<name>/, mods/<name>/, or mods/ for a single file.

print(phigrospp.dir()) --> /sdcard/Android/data/sh.molly.phigrosplusplus/files/phigros++/mods/hello/
local notes = phigrospp.read(phigrospp.dir() .. "notes.txt")

Returns string

phigrospp.read(path)

A whole file. bundle/<path> reads a file of the bundle.

local text = phigrospp.read(phigrospp.root .. "/my-mod.json")
local words = phigrospp.read("bundle/words.txt") -- a file of the bundle
ParameterType
pathstring

Returns string

phigrospp.json.encode(object)

A table as json, and back. The table is flat: its values are strings, numbers and booleans.

print(phigrospp.json.encode({ plays = 3, name = "hi" })) --> {"plays":3,"name":"hi"}
print(phigrospp.json.decode('{"version":"0.3.0"}').version) --> 0.3.0
ParameterType
objecttable

Returns string

phigrospp.json.decode(json)

ParameterType
jsonstring

Returns any

phigrospp.write(path, data)

Writes a whole file, through a temporary one so a crash never leaves half of it.

phigrospp.write(phigrospp.root .. "/my-mod.json", phigrospp.json.encode({ plays = 3 }))
ParameterType
pathstring
datastring

phigrospp.root

string

The phigros++ folder, where mods keep their files.

phigrospp.private()

The app's own folder, which no other app can read.

print(phigrospp.private()) --> /data/user/0/sh.molly.phigrosplusplus/files
phigrospp.write(phigrospp.private() .. "/token", token) -- for a secret

Returns string

phigrospp.find(transform, path)

A child by path, the error naming what's missing after a game update.

local canvas = phigrospp.find(go.transform, "ContentCanvas") -- an error naming what's missing if the game moved it
ParameterType
transformUnity
pathstring"A/B"

Returns Transform