Skip to content

Instantly share code, notes, and snippets.

@Quenty
Created November 30, 2017 05:38
Show Gist options
  • Save Quenty/35594287bd23fa127966ead7ff291182 to your computer and use it in GitHub Desktop.
Save Quenty/35594287bd23fa127966ead7ff291182 to your computer and use it in GitHub Desktop.
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