From 0f98fe4af5ce6729429a23c9d6df6df40c236e49 Mon Sep 17 00:00:00 2001 From: Billy Snikkers Date: Wed, 1 Nov 2023 10:36:09 +0100 Subject: [PATCH] Added SurfaceCFrame/Soze interfaces to Boards --- lib/Client/BoardClient/init.lua | 18 +++++++++++++----- lib/Server/BoardServer.lua | 11 +++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/Client/BoardClient/init.lua b/lib/Client/BoardClient/init.lua index 84ba9a3..ee42055 100644 --- a/lib/Client/BoardClient/init.lua +++ b/lib/Client/BoardClient/init.lua @@ -7,7 +7,9 @@ local RunService = game:GetService("RunService") local root = script.Parent.Parent -local Rx = require(script.Parent.Parent.Util.Rx) +local BoardUtils = require(root.BoardUtils) +local Rx = require(root.Util.Rx) +local ValueObject = require(root.Util.ValueObject) local BoardState = require(root.BoardState) local BaseObject = require(root.Util.BaseObject) -- local ValueObject = require(root.Util.ValueObject) @@ -27,8 +29,6 @@ export type BoardClient = { Remotes: BoardRemotes.BoardRemotes, State: BoardState.BoardState, StateChanged: { Connect:(() -> ()) -> { Disconnect: () -> ()} }, - -- SurfaceSize: { Value: Vector2 }, - -- SurfaceCFrame: { Value: CFrame }, ClientState: { DrawingTasks: BoardState.DrawingTaskDict }, } & typeof(BoardClient) @@ -46,8 +46,8 @@ function BoardClient.new(part: Part) : BoardClient -- Fires at most once per-frame self.StateChanged = self._maid:Add(GoodSignal.new()) - -- self.SurfaceSize = self._maid:Add(ValueObject.new(BoardState.getSurfaceSizeFromPart(self._obj), "Vector2")) - -- self.SurfaceCFrame = self._maid:Add(ValueObject.new(BoardState.getSurfaceCFrameFromPart(self._obj), "CFrame")) + self.SurfaceCFrame = self._maid:Add(ValueObject.fromObservable(BoardUtils.getSurfaceCFrameFromPart(part))) + self.SurfaceSize = self._maid:Add(ValueObject.fromObservable(BoardUtils.getSurfaceSizeFromPart(part))) -- self._maid:GiveTask(self._obj:GetPropertyChangedSignal("Size"):Connect(function() -- self.SurfaceSize.Value = BoardState.getSurfaceSizeFromPart(self._obj) @@ -64,6 +64,14 @@ function BoardClient:GetPart() return self._obj end +function BoardClient:GetSurfaceCFrame() + return self.SurfaceCFrame.Value +end + +function BoardClient:GetSurfaceSize() + return self.SurfaceSize.Value +end + --[[ Connect remote event callbacks to respond to init/update/finish's of a drawing task, as well as undo, redo, clear events. diff --git a/lib/Server/BoardServer.lua b/lib/Server/BoardServer.lua index 99d5d9d..f280067 100644 --- a/lib/Server/BoardServer.lua +++ b/lib/Server/BoardServer.lua @@ -56,6 +56,9 @@ function BoardServer.new(part: Part): BoardServer -- When set to true, self.State should be set to a valid state self.Loaded = self._maid:Add(ValueObject.new(false, "boolean")) + self.SurfaceCFrame = self._maid:Add(ValueObject.fromObservable(BoardUtils.getSurfaceCFrameFromPart(part))) + self.SurfaceSize = self._maid:Add(ValueObject.fromObservable(BoardUtils.getSurfaceSizeFromPart(part))) + self._persistId = part:FindFirstChild("PersistId") if self._persistId then assert(typeof(self._persistId) == "Instance", `Bad persistId: {self._persistId}`) @@ -89,6 +92,14 @@ function BoardServer:_checkStateUpdate() end end +function BoardServer:GetSurfaceCFrame() + return self.SurfaceCFrame.Value +end + +function BoardServer:GetSurfaceSize() + return self.SurfaceSize.Value +end + function BoardServer:GetPersistId(): number? if self._persistId then return self._persistId.Value