diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau index 2b0fffe..ad16316 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau @@ -11,6 +11,7 @@ local IJW = require(root.roblox_packages.ijw); local expect = IJW.expect; local describe = IJW.describe; local it = IJW.it; +local VirtualSelection = require(root.DialogueEditor.mocks.Selection); local screenGui: ScreenGui?; local reactRoot: ReactRoblox.RootType?; @@ -44,7 +45,7 @@ return { }, { React.createElement(DialogueGroupContainer, { name = dialogueType; - plugin = VirtualService.mocks.globals.plugin; + plugin = VirtualService.globals.plugin; layoutOrder = 1; }) }); @@ -158,7 +159,7 @@ return { assert(dialogueGroupContainer); local dialogueFolder, selectedScript = initializeDialogueFolder(4); - VirtualService.mocks.services.Selection:Set({selectedScript}); + VirtualService.globals.game:GetService("Selection"):Set({selectedScript}); dialogueGroupContainer.ChildAdded:Wait(); verifyReactStatus(); expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren()); @@ -194,7 +195,7 @@ return { assert(dialogueGroupContainer); local dialogueFolder, selectedScript = initializeDialogueFolder(4); - VirtualService.mocks.services.Selection:Set({selectedScript}); + VirtualService.globals.game:GetService("Selection"):Set({selectedScript}); dialogueGroupContainer.ChildAdded:Wait(); verifyReactStatus(); expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren()); @@ -217,7 +218,7 @@ return { -- Render the component and wait for it to finish rendering. assert(screenGui, "ScreenGui should be initialized before running tests."); local dialogueFolder, selectedScript = initializeDialogueFolder(4); - VirtualService.mocks.services.Selection:Set({selectedScript}); + VirtualService.globals.game:GetService("Selection"):Set({selectedScript}); render(); verifyReactStatus(); @@ -257,7 +258,7 @@ return { conversationsFolder.Name = "Conversations"; conversationsFolder.Parent = conversationsFolderParent; - VirtualService.mocks.services.Selection:Set({conversationsFolderParent}); + VirtualService.globals.game:GetService("Selection"):Set({conversationsFolderParent}); verifyReactStatus(); expect(#getDialogueItems(screenGui)).toBe(#conversationsFolder:GetChildren()); @@ -291,7 +292,7 @@ return { local conversationScript = Instance.new("ModuleScript"); conversationScript:AddTag("DialogueMakerConversationScript"); conversationScript.Parent = conversationsFolder; - VirtualService.mocks.services.Selection:Set({conversationsFolderParent}); + VirtualService.globals.game:GetService("Selection"):Set({conversationsFolderParent}); -- Render the component and wait for it to finish rendering. assert(screenGui, "ScreenGui should be initialized before running tests."); @@ -313,18 +314,29 @@ return { end, { beforeEach = function() - - VirtualService.mocks.isEnabled = true; local newScreenGui = Instance.new("ScreenGui"); screenGui = newScreenGui; reactRoot = ReactRoblox.createRoot(newScreenGui); + local virtualSelection = VirtualSelection.new(); + VirtualService.globals.game = { + GetService = function(self, serviceName: string) + + if serviceName == "Selection" then + + return virtualSelection; + + end; + + return game:GetService(serviceName); + + end; + } + end; afterEach = function() - VirtualService.mocks.isEnabled = false; - if reactRoot then reactRoot:unmount(); @@ -337,12 +349,13 @@ return { end; - VirtualService.mocks.services.Selection:Set({}); + VirtualService.globals.game = game; propagatedErrorMessage = nil; dialogueGroupContainer = nil; dialogueGroup = nil; end; - }) + }); + }; \ No newline at end of file diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/DialogueGroup.test.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/DialogueGroup.test.luau index 806e6af..ce09829 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/DialogueGroup.test.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/DialogueGroup.test.luau @@ -35,7 +35,7 @@ return { return React.createElement(DialogueGroup, { name = dialogueType; - plugin = VirtualService.mocks.globals.plugin; + plugin = VirtualService.globals.plugin; dialogueScripts = dialogueScripts; layoutOrder = layoutOrder; }); @@ -113,8 +113,6 @@ return { end, { beforeEach = function() - - VirtualService.mocks.isEnabled = true; local newScreenGui = Instance.new("ScreenGui"); screenGui = newScreenGui; @@ -123,8 +121,6 @@ return { end; afterEach = function() - VirtualService.mocks.isEnabled = false; - if reactRoot then reactRoot:unmount(); diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/DialogueItem.test.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/DialogueItem.test.luau index 83d5e43..4856640 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/DialogueItem.test.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/DialogueItem.test.luau @@ -3,6 +3,8 @@ local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent; local DialogueItem = require(script.Parent); local VirtualService = require(root.VirtualService); +local VirtualSelection = require(root.DialogueEditor.mocks.Selection); +local VirtualChangeHistoryService = require(root.DialogueEditor.mocks.ChangeHistoryService); local React = require(root.roblox_packages.react); local ReactErrorBoundary = require(root.roblox_packages.ReactErrorBoundary); local ErrorBoundary = ReactErrorBoundary.ErrorBoundary; @@ -110,7 +112,7 @@ return { assert(viewButton and viewButton:IsA("GuiButton"), "ViewButton should be present in the DialogueItem."); local didSelectionChange = false; - VirtualService.mocks.services.Selection.SelectionChanged:Once(function() + VirtualService.globals.game:GetService("Selection").SelectionChanged:Once(function() didSelectionChange = true; @@ -305,17 +307,35 @@ return { end, { beforeEach = function() - - VirtualService.mocks.isEnabled = true; local newScreenGui = Instance.new("ScreenGui"); screenGui = newScreenGui; reactRoot = ReactRoblox.createRoot(newScreenGui); + local virtualSelection = VirtualSelection.new(); + local virtualChangeHistoryService = VirtualChangeHistoryService.new(); + VirtualService.globals.game = { + GetService = function(self, serviceName: string): unknown + + if serviceName == "Selection" then + + return virtualSelection; + + elseif serviceName == "ChangeHistoryService" then + + return virtualChangeHistoryService; + + end; + + return VirtualService.globals.game:GetService(serviceName); + + end; + } + end; afterEach = function() - VirtualService.mocks.isEnabled = false; + VirtualService.globals.game = game; if reactRoot then diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau index 97d5b0e..0bb20dd 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau @@ -1,7 +1,5 @@ --!strict -local Selection = game:GetService("Selection"); - local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent; local VirtualService = require(root.VirtualService); local React = require(root.roblox_packages.react); @@ -22,7 +20,8 @@ local function DialogueItem(props: DialogueItemProperties) -- Replace services with VirtualService services for testing. -- VirtualService services are used to mock specific Roblox services in tests. - Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection; + local game = VirtualService.globals.game; + local Selection = game:GetService("Selection"); local dialogueType = props.type; local dialogueScript = props.dialogueScript; diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/init.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/init.luau index 202eb5c..b80fea0 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/init.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/init.luau @@ -3,7 +3,6 @@ local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent; local React = require(root.roblox_packages.react); local DialogueItem = require(script.components.DialogueItem); -local VirtualService = require(root.VirtualService); export type DialogueItemType = DialogueItem.DialogueItemType; @@ -19,7 +18,7 @@ local function DialogueGroup(properties: DialogueGroupProperties) local groupName = properties.name; local dialogueScripts = properties.dialogueScripts; local layoutOrder = properties.layoutOrder; - local plugin = if VirtualService.mocks.isEnabled then VirtualService.mocks.globals.plugin else properties.plugin; + local plugin = properties.plugin; local scriptComponents = {}; for index, dialogueScript in dialogueScripts do diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau index 479335f..df8546a 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau @@ -1,7 +1,5 @@ --!strict -local Selection = game:GetService("Selection"); - local root = script.Parent.Parent.Parent.Parent.Parent; local VirtualService = require(root.VirtualService); local React = require(root.roblox_packages.react); @@ -22,7 +20,8 @@ export type DialogueTableBodyProperties = { local function DialogueGroupContainer(props: DialogueTableBodyProperties) - Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection; + local game = VirtualService.globals.game; + local Selection = game:GetService("Selection"); local layoutOrder = props.layoutOrder; local selectedScript = useDialogueMakerScriptSelection(); diff --git a/src/DialogueEditor/components/Explorer/components/Preview/components/AutoTriggerCheckbox/AutoTriggerCheckbox.test.luau b/src/DialogueEditor/components/Explorer/components/Preview/components/AutoTriggerCheckbox/AutoTriggerCheckbox.test.luau index 400558c..2ab73ed 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/components/AutoTriggerCheckbox/AutoTriggerCheckbox.test.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/components/AutoTriggerCheckbox/AutoTriggerCheckbox.test.luau @@ -5,6 +5,7 @@ local StarterPlayer = game:GetService("StarterPlayer"); local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent; local AutoTriggerCheckbox = require(script.Parent); local VirtualService = require(root.VirtualService); +local VirtualChangeHistoryService = require(root.DialogueEditor.mocks.ChangeHistoryService); local React = require(root.roblox_packages.react); local ReactErrorBoundary = require(root.roblox_packages.ReactErrorBoundary); local ErrorBoundary = ReactErrorBoundary.ErrorBoundary; @@ -197,6 +198,21 @@ return { screenGui = newScreenGui; reactRoot = ReactRoblox.createRoot(newScreenGui); + local virtualChangeHistoryService = VirtualChangeHistoryService.new(); + VirtualService.globals.game = { + GetService = function(self, serviceName: string): unknown + + if serviceName == "ChangeHistoryService" then + + return virtualChangeHistoryService; + + end; + + return game:GetService(serviceName); + + end; + }; + end; afterEach = function() diff --git a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau index 3dcf458..581b98f 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau @@ -11,11 +11,14 @@ local IJW = require(root.roblox_packages.ijw); local expect = IJW.expect; local describe = IJW.describe; local it = IJW.it; +local VirtualSelection = require(root.DialogueEditor.mocks.Selection); +local VirtualChangeHistoryService = require(root.DialogueEditor.mocks.ChangeHistoryService); local screenGui: ScreenGui?; local reactRoot: ReactRoblox.RootType?; local propagatedErrorMessage; local eventConnection: RBXScriptConnection?; +local didOpenScript = false; return { @@ -39,7 +42,7 @@ return { }, { React.createElement(DialogueOptions, { selectedScript = selectedScript; - plugin = VirtualService.mocks.globals.plugin; + plugin = VirtualService.globals.plugin; selectedDialogueType = selectedScript:GetAttribute("DialogueType") or "Conversation"; layoutOrder = 1; }) @@ -250,6 +253,25 @@ return { end).toFinishBeforeSeconds(1); end); + + it("can request to open condition script in Roblox script editor", function() + + expect(function() + + render("Message"); + + assert(screenGui, "ScreenGui should be initialized before running tests."); + local dialogueOptions = screenGui:FindFirstChildOfClass("Frame"); + assert(dialogueOptions, "DialogueOptions should be rendered."); + + local conditionButton = dialogueOptions:FindFirstChild("ConditionButton"); + assert(conditionButton and conditionButton:IsA("TextButton"), "Condition button should be present in the DialogueOptions."); + VirtualService.events.GuiButton.Activated:fireEvent(conditionButton); + repeat task.wait() until didOpenScript or propagatedErrorMessage; + + end).toFinishBeforeSeconds(1); + + end); } @@ -259,7 +281,34 @@ return { local newScreenGui = Instance.new("ScreenGui"); screenGui = newScreenGui; reactRoot = ReactRoblox.createRoot(newScreenGui); - VirtualService.mocks.isEnabled = true; + + local virtualSelection = VirtualSelection.new(); + local virtualChangeHistoryService = VirtualChangeHistoryService.new(); + VirtualService.globals.game = { + GetService = function(self, serviceName: string): unknown + + if serviceName == "Selection" then + + return virtualSelection; + + elseif serviceName == "ChangeHistoryService" then + + return virtualChangeHistoryService; + + end; + + return game:GetService(serviceName); + + end; + }; + + VirtualService.globals.plugin = { + OpenScript = function(script) + + didOpenScript = true; + + end + } :: any; end; afterEach = function() @@ -286,7 +335,9 @@ return { end; propagatedErrorMessage = nil; - VirtualService.mocks.isEnabled = false; + VirtualService.globals.game = game; + VirtualService.globals.plugin = plugin; + didOpenScript = false; end; }) diff --git a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/init.luau b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/init.luau index 2157a3c..0ea4278 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/init.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/init.luau @@ -1,7 +1,5 @@ --!strict -local Selection = game:GetService("Selection"); - local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent; local React = require(root.roblox_packages.react); local Button = require(root.DialogueEditor.components.Button); @@ -23,7 +21,7 @@ export type DialogueOptionsProperties = { local function DialogueOptions(properties: DialogueOptionsProperties) - Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection; + local Selection = VirtualService.globals.game:GetService("Selection"); local selectedScript = properties.selectedScript; local selectedDialogueType = properties.selectedDialogueType; diff --git a/src/DialogueEditor/hooks/useChangeHistory.luau b/src/DialogueEditor/hooks/useChangeHistory.luau index 35d6208..402c22d 100644 --- a/src/DialogueEditor/hooks/useChangeHistory.luau +++ b/src/DialogueEditor/hooks/useChangeHistory.luau @@ -1,14 +1,13 @@ --!strict -local ChangeHistoryService = game:GetService("ChangeHistoryService"); - local root = script.Parent.Parent.Parent; local React = require(root.roblox_packages.react); local VirtualService = require(root.VirtualService); local function useChangeHistory() - ChangeHistoryService = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.ChangeHistoryService else ChangeHistoryService; + local game = VirtualService.globals.game; + local ChangeHistoryService = game:GetService("ChangeHistoryService"); local startRecording = React.useCallback(function(label: string) diff --git a/src/DialogueEditor/hooks/useDialogueMakerScriptSelection.luau b/src/DialogueEditor/hooks/useDialogueMakerScriptSelection.luau index 7685ad7..ef92b44 100644 --- a/src/DialogueEditor/hooks/useDialogueMakerScriptSelection.luau +++ b/src/DialogueEditor/hooks/useDialogueMakerScriptSelection.luau @@ -1,14 +1,13 @@ --!strict -local Selection = game:GetService("Selection"); - local root = script.Parent.Parent.Parent; local React = require(root.roblox_packages.react); local VirtualService = require(root.VirtualService); local function useDialogueMakerScriptSelection() - Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection; + local game = VirtualService.globals.game; + local Selection = game:GetService("Selection"); local getScripts = React.useCallback(function() diff --git a/src/DialogueEditor/mocks/ChangeHistoryService.luau b/src/DialogueEditor/mocks/ChangeHistoryService.luau new file mode 100644 index 0000000..f6d5d54 --- /dev/null +++ b/src/DialogueEditor/mocks/ChangeHistoryService.luau @@ -0,0 +1,54 @@ +--!strict + +local HttpService = game:GetService("HttpService"); + +local VirtualChangeHistoryService = {}; + +function VirtualChangeHistoryService.new() + + local virtualChangeHistoryService = { + currentHistory = {}; + currentIdentifier = nil; + }; + + function virtualChangeHistoryService:TryBeginRecording() + + if self.currentIdentifier then + + return; + + end + + self.currentIdentifier = HttpService:GenerateGUID(false); + self.currentHistory[self.currentIdentifier] = true; -- Simulate a successful start + return self.currentIdentifier; + + end; + + function virtualChangeHistoryService:IsRecordingInProgress() + + return self.currentIdentifier ~= nil; + + end; + + function virtualChangeHistoryService:FinishRecording(identifier, operation) + + if not self.currentHistory[identifier] then + + return; + + end + + if operation == Enum.FinishRecordingOperation.Cancel then + self.currentHistory[identifier] = nil; + end + + self.currentIdentifier = nil; + + end; + + return virtualChangeHistoryService; + +end; + +return VirtualChangeHistoryService; \ No newline at end of file diff --git a/src/DialogueEditor/mocks/Selection.luau b/src/DialogueEditor/mocks/Selection.luau new file mode 100644 index 0000000..d69967d --- /dev/null +++ b/src/DialogueEditor/mocks/Selection.luau @@ -0,0 +1,110 @@ +--!strict + +local VirtualSelection = {}; + +function VirtualSelection.new() + + local selectionChangedEvent = Instance.new("BindableEvent"); + local virtualSelection = { + currentSelection = {}; + SelectionChanged = selectionChangedEvent.Event; + }; + + function virtualSelection:Set(selection: {Instance}): () + + local oldSelection = self.currentSelection; + self.currentSelection = selection; + + if not oldSelection[1] and #selection > 0 then + + selectionChangedEvent:Fire(); + return; + + end; + + local checkedInstances = {}; + for _, instance in oldSelection do + + if not table.find(selection, instance) then + + selectionChangedEvent:Fire(); + return; + + end; + + table.insert(checkedInstances, instance); + + end; + + for _, instance in selection do + + if not table.find(checkedInstances, instance) then + + selectionChangedEvent:Fire(); + return; + + end; + + end; + + end; + + function virtualSelection:Get(): {Instance} + + return self.currentSelection; + + end; + + function virtualSelection:Add(instances: {Instance}): () + + local shouldFire = false; + + for _, instance in instances do + + if not table.find(self.currentSelection, instance) then + + table.insert(self.currentSelection, instance); + shouldFire = true; + + end; + + end; + + if shouldFire then + + selectionChangedEvent:Fire(); + + end; + + end; + + function virtualSelection:Remove(instances: {Instance}): () + + local shouldFire = false; + + for _, instance in instances do + + local index = table.find(self.currentSelection, instance); + + if index then + + table.remove(self.currentSelection, index); + shouldFire = true; + + end; + + end; + + if shouldFire then + + selectionChangedEvent:Fire(); + + end; + + end; + + return virtualSelection; + +end; + +return VirtualSelection; \ No newline at end of file diff --git a/src/VirtualService/init.luau b/src/VirtualService/init.luau index 8fdb5cf..4d82acc 100644 --- a/src/VirtualService/init.luau +++ b/src/VirtualService/init.luau @@ -3,15 +3,10 @@ local EventProvider = require(script.EventProvider); local VirtualService = { - mocks = { - isEnabled = false; - services = { - ChangeHistoryService = require(script.mocks.services.ChangeHistoryService); - Selection = require(script.mocks.services.Selection); - }; - globals = { - plugin = require(script.mocks.globals.plugin); - }; + globals = { + plugin = plugin; + game = game; + script = script; }; events = { GuiButton = { diff --git a/src/VirtualService/mocks/globals/plugin.luau b/src/VirtualService/mocks/globals/plugin.luau deleted file mode 100644 index d74a3c3..0000000 --- a/src/VirtualService/mocks/globals/plugin.luau +++ /dev/null @@ -1,5 +0,0 @@ ---!strict - -local VirtualPlugin = {}; - -return (VirtualPlugin :: unknown) :: Plugin; \ No newline at end of file diff --git a/src/VirtualService/mocks/services/ChangeHistoryService.luau b/src/VirtualService/mocks/services/ChangeHistoryService.luau deleted file mode 100644 index 188190b..0000000 --- a/src/VirtualService/mocks/services/ChangeHistoryService.luau +++ /dev/null @@ -1,46 +0,0 @@ ---!strict - -local HttpService = game:GetService("HttpService"); - -local VirtualChangeHistoryService = { - currentHistory = {}; - currentIdentifier = nil; -}; - -function VirtualChangeHistoryService:TryBeginRecording() - - if self.currentIdentifier then - - return; - - end - - self.currentIdentifier = HttpService:GenerateGUID(false); - self.currentHistory[self.currentIdentifier] = true; -- Simulate a successful start - return self.currentIdentifier; - -end; - -function VirtualChangeHistoryService:IsRecordingInProgress() - - return self.currentIdentifier ~= nil; - -end; - -function VirtualChangeHistoryService:FinishRecording(identifier, operation) - - if not self.currentHistory[identifier] then - - return; - - end - - if operation == Enum.FinishRecordingOperation.Cancel then - self.currentHistory[identifier] = nil; - end - - self.currentIdentifier = nil; - -end; - -return (VirtualChangeHistoryService :: unknown) :: ChangeHistoryService; \ No newline at end of file diff --git a/src/VirtualService/mocks/services/Selection.luau b/src/VirtualService/mocks/services/Selection.luau deleted file mode 100644 index 95aa70f..0000000 --- a/src/VirtualService/mocks/services/Selection.luau +++ /dev/null @@ -1,102 +0,0 @@ ---!strict - -local selectionChangedEvent = Instance.new("BindableEvent"); -local VirtualSelection = { - currentSelection = {}; - SelectionChanged = selectionChangedEvent.Event; -}; - -function VirtualSelection:Set(selection: {Instance}): () - - local oldSelection = self.currentSelection; - self.currentSelection = selection; - - if not oldSelection[1] and #selection > 0 then - - selectionChangedEvent:Fire(); - return; - - end; - - local checkedInstances = {}; - for _, instance in oldSelection do - - if not table.find(selection, instance) then - - selectionChangedEvent:Fire(); - return; - - end; - - table.insert(checkedInstances, instance); - - end; - - for _, instance in selection do - - if not table.find(checkedInstances, instance) then - - selectionChangedEvent:Fire(); - return; - - end; - - end; - -end; - -function VirtualSelection:Get(): {Instance} - - return self.currentSelection; - -end; - -function VirtualSelection:Add(instances: {Instance}): () - - local shouldFire = false; - - for _, instance in instances do - - if not table.find(self.currentSelection, instance) then - - table.insert(self.currentSelection, instance); - shouldFire = true; - - end; - - end; - - if shouldFire then - - selectionChangedEvent:Fire(); - - end; - -end; - -function VirtualSelection:Remove(instances: {Instance}): () - - local shouldFire = false; - - for _, instance in instances do - - local index = table.find(self.currentSelection, instance); - - if index then - - table.remove(self.currentSelection, index); - shouldFire = true; - - end; - - end; - - if shouldFire then - - selectionChangedEvent:Fire(); - - end; - -end; - -return (VirtualSelection :: unknown) :: Selection; \ No newline at end of file