Created
November 30, 2017 05:38
-
-
Save Quenty/35594287bd23fa127966ead7ff291182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
local NevermoreEngine = require(ReplicatedStorage:WaitForChild("NevermoreEngine")) | |
local LoadCustomLibrary = NevermoreEngine.LoadLibrary | |
local BaseClass = LoadCustomLibrary("BaseClass") | |
local MakeMaid = LoadCustomLibrary("Maid").MakeMaid | |
-- Intent: | |
-- @author Quenty | |
local InteractionSpace = setmetatable({}, BaseClass) | |
InteractionSpace.__index = InteractionSpace | |
InteractionSpace.ClassName = "InteractionSpace" | |
function InteractionSpace.new(MixinFactory, Object) | |
local self = setmetatable(BaseClass.new(MixinFactory, Object), InteractionSpace) | |
return self | |
end | |
function InteractionSpace:Deactivate() | |
assert(self.MixinFactory:IsClient()) | |
for _, Item in pairs(self:GetObject():GetChildren()) do | |
local Mixin = self.MixinFactory:GetNoCreate(Item) | |
if Mixin then | |
if Mixin.AcceptGCRequest then | |
Mixin:AcceptGCRequest() | |
else | |
Item:Remove() -- So we GC correctly | |
end | |
else | |
Item:Destroy() | |
end | |
end | |
end | |
function InteractionSpace:Activate(SourceRobloxObject) | |
assert(self.MixinFactory:IsClient()) | |
assert(SourceRobloxObject) | |
-- Chances are SourceRobloxObject is the Torso | |
self:Deactivate() | |
for _, Item in pairs(self:GetObject().Parent:GetChildren()) do | |
local Mixin = self.MixinFactory:Get(Item) | |
if Mixin and Mixin.ConstructNewInteraction then | |
local NewInteraction = Mixin:ConstructNewInteraction(self) | |
if NewInteraction then | |
assert(NewInteraction:IsA("Instance") and not NewInteraction.Parent) | |
local Source = Instance.new("ObjectValue") | |
Source.Name = self.MixinFactory:GetPrefix() .. "InteractionSource" | |
Source.Value = SourceRobloxObject | |
Source.Parent = NewInteraction | |
NewInteraction.Parent = self:GetObject() | |
else | |
warn(("[InteractionSpace] - Failed to construct new interaction from '%s'"):format(Item:GetFullName())) | |
end | |
end | |
end | |
end | |
return InteractionSpace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment