Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- This is a simple example of streaming live score data to a file.
-- It is meant to be loaded as an actor in the out transition layer of
-- ScreenGameplay.
-- Save it to Graphics/live_score_report.lua in a theme and edit
-- BGAnimations/ScreenGameplay decorations.lua to load it.
-- If BGAnimations/ScreenGameplay decorations.lua doesn't exist, here is an
-- example:
-- return Def.ActorFrame{
-- LoadActor(THEME:GetPathG("", "live_score_report.lua")),
-- }
-- This writes score data for each player to a different file for
-- convenience. This way, the scoring data doesn't have to be tagged with
-- the player.
-- Since the file is opened each time ScreenGameplay starts and closed when
-- exiting it, an outside app that is watching the file might need to reopen
-- it every time. If that's a problem, it would be better to put this in an
-- overlay screen and add a bit of code for outputting when a song begins or
-- ends.
-- file_path will have p1 or p2 appended, so that data for different players
-- is sent to different files.
local file_path= "Save/live_score_data_"
local file_handles= {}
-- tns_reverse is used to change the TapNoteScore strings into numbers.
-- Check Docs/Luadoc/Lua.xml to see what each number corresponds to.
local tns_reverse= TapNoteScore:Reverse()
return Def.Actor{
InitCommand= function(self)
for i, pn in ipairs(GAMESTATE:GetHumanPlayers()) do
local real_path= file_path .. ToEnumShortString(pn):lower()
file_handles[pn]= RageFileUtil.CreateRageFile()
if not file_handles[pn]:Open(real_path, 6) then
Warn("Opening '" .. real_path .. "' failed: " ..
file_handles[pn]:GetError())
file_handles[pn]= nil
end
end
end,
JudgmentMessageCommand= function(self, param)
local pn= param.Player
if not file_handles[pn] then return end
if not param.TapNoteScore then return end
file_handles[pn]:Write(tns_reverse[param.TapNoteScore] .. " ")
-- Flush isn't exposed yet, but it will be soon....
-- file_handles[pn]:Flush()
end,
OffCommand= function(self)
for pn, handle in pairs(file_handles) do
handle:Close()
handle:destroy()
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.