Skip to content

Commit

Permalink
turned replay into replayutils
Browse files Browse the repository at this point in the history
  • Loading branch information
blinkybool committed Nov 12, 2022
1 parent 7ebd753 commit b17983d
Show file tree
Hide file tree
Showing 37 changed files with 814 additions and 2,331 deletions.
4 changes: 1 addition & 3 deletions aftman.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
[tools]
rojo = "rojo-rbx/[email protected]"
selene = "Kampfkarren/[email protected]"
wally = "UpliftGames/[email protected]"
# wally = "UpliftGames/[email protected]"
# rojo = "rojo-rbx/[email protected]"
wally = "UpliftGames/[email protected]"
18 changes: 9 additions & 9 deletions default.project.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "replay",
"name": "replayutils",
"tree": {
"$className": "DataModel",
"$path": "Packages",
"$className": "ModuleScript",

"ReplicatedStorage": {
"replay": {
"$path": "src",
"$properties": {
"Source": "return require(script.lib)"
},

"lib": {
"$path": "src"

"Packages": {
"$path": "Packages"
}
}
}

}
Expand Down
19 changes: 13 additions & 6 deletions release.project.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
"name": "replay",
"name": "replayutils",
"tree": {
"$path": "src",

"Packages": {
"$path": "Packages"
},
"Replay": {
"$path": "Packages",
"$className": "ModuleScript",

"version": {
"$path": "version.txt"

"$properties": {
"Source": "return require(script.lib)"
},

"lib": {
"$path": "lib"

}

}
}
Expand Down
5 changes: 1 addition & 4 deletions selene.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
std = "roblox"

[config]
undefined_variable = { ignore_pattern = "(^_|rbx|Array|Set|Dictionary)" }
std = "roblox"
113 changes: 74 additions & 39 deletions src/BoardRecorder/BoardReplay.lua
Original file line number Diff line number Diff line change
@@ -1,59 +1,108 @@
-- Services
local replay = script.Parent.Parent
local metaboard = game:GetService("ServerScriptService").metaboard
local Replay = script.Parent.Parent

-- Imports
local t = require(replay.Packages.t)

-- Helper functions
local persist = require(script.Parent.persist)
local t = require(Replay.Parent.t)

local BoardReplay = {}
BoardReplay.__index = BoardReplay

local check = t.strictInterface({
export type ReplayArgs = {

Board: any,
Origin: CFrame,
}

local checkReplayArgs = t.strictInterface({

Board = t.any,
InitFigures = t.table,
InitNextFigureZIndex = t.number,
Timeline = t.table,
Origin = t.CFrame,
})

function BoardReplay.new(args)
function BoardReplay.new(record: {Timeline: {any}}, replayArgs: ReplayArgs)

assert(check(args))
assert(checkReplayArgs(replayArgs))

return setmetatable(args, BoardReplay)
end
local tokenToAuthorId = {}

function BoardReplay:Init()
for authorId, token in record.AuthorIdTokens do

for watcher in pairs(self.Board.Watchers) do
self.Board.Remotes.SetData:FireClient(watcher, self.InitFigures, {}, {}, self.InitNextFigureZIndex, nil, nil)
if tokenToAuthorId[token] then

error("[BoardReplay] Non-distinct authorId tokens")
end

tokenToAuthorId[token] = authorId
end

self.Board:LoadData(self.InitFigures, {}, {}, self.InitNextFigureZIndex, nil, nil)
self.Board:DataChanged()
local tokenToRemoteName = {}

for remoteName, token in record.RemoteNameTokens do

if tokenToRemoteName[token] then

error("[BoardReplay] Non-distinct remote name tokens")
end

tokenToRemoteName[token] = remoteName
end

return setmetatable({
Record = record,
__tokenToAuthorId = tokenToAuthorId,
__tokenToRemoteName = tokenToRemoteName,
Board = replayArgs.Board,
Origin = replayArgs.Origin,
}, BoardReplay)
end

function BoardReplay:Init()

self.TimelineIndex = 1
self.Finished = false
end

function BoardReplay:PlayUpTo(playhead: number)

while self.TimelineIndex <= #self.Timeline do
while self.TimelineIndex <= #self.Record.Timeline do

local event = self.Timeline[self.TimelineIndex]
local event = self.Record.Timeline[self.TimelineIndex]

if event[1] <= playhead then

local timeStamp, remoteName, args = unpack(event)
local remoteName = self.__tokenToRemoteName[event[2]]
local authorId = self.__tokenToAuthorId[event[3]]
local args = {}

if remoteName == "InitDrawingTask" then

local taskId, taskType, width, r, g, b, x, y = unpack(event, 4)

local drawingTask = {
Id = taskId,
Type = taskType,
Curve = {
Type = "Curve",
Points = nil,
Width = width,
Color = Color3.new(r,g,b)
},
Verified = true,
}

args = {drawingTask, Vector2.new(x, y)}
elseif remoteName == "UpdateDrawingTask" then

local x, y = unpack(event, 4)

args = {Vector2.new(x, y)}
end

for watcher in pairs(self.Board.Watchers) do
self.Board.Remotes[remoteName]:FireClient(watcher, unpack(args))
self.Board.Remotes[remoteName]:FireClient(watcher, "replay-"..authorId, unpack(args))
end

self.Board["Process"..remoteName](self.Board, unpack(args))
self.Board["Process"..remoteName](self.Board, "replay-"..authorId, unpack(args))

self.TimelineIndex += 1
continue
Expand All @@ -62,24 +111,10 @@ function BoardReplay:PlayUpTo(playhead: number)
break
end

if self.TimelineIndex > #self.Timeline then
if self.TimelineIndex > #self.Record.Timeline then

self.Finished = true
end
end

function BoardReplay.Restore(dataStore: DataStore, key: string, replayArgs)

local restoredArgs = persist.Restore(dataStore, key, replayArgs.Board)

return BoardReplay.new({

InitFigures = restoredArgs.InitFigures,
InitNextFigureZIndex = restoredArgs.InitNextFigureZIndex,
Timeline = restoredArgs.Timeline,

Board = replayArgs.Board,
})
end

return BoardReplay
Loading

0 comments on commit b17983d

Please sign in to comment.