Tag service module

This commit is contained in:
2024-04-12 01:27:06 -04:00
parent 53e383cbb1
commit 5556006c83
6 changed files with 144 additions and 95 deletions

File diff suppressed because one or more lines are too long

View File

@@ -95,7 +95,6 @@ function StudioEntities.indexAll(enabled: boolean)
end
elseif Item:IsA("LuaSourceContainer") then --Cant allow scripts outside of the framework
--mini algIsAorthim to see if the script is part of the rhpid-framework character or not
--[[
local Model = Item:FindFirstAncestorOfClass("Model")
if Model and not Players:GetPlayerFromCharacter(Model) then
@@ -105,7 +104,6 @@ function StudioEntities.indexAll(enabled: boolean)
Item:Destroy()
warn(`Script: "{Item.Name}" ({Item.ClassName}) was removed because it was outside of the rhpid-framework boundries,`, Item:GetFullName())
end
]]
end
if table.find(CS:GetTags(Item), "ServerGuard_Physics") then

View File

@@ -14,8 +14,6 @@ type TagProduct = TagsModule.TagProduct
type HumanoidRootPart = BasePart
type PromptCallback = (Player: Player) -> ()
type GetButtons = {[string]: Instance}
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
@@ -39,17 +37,6 @@ type Constructor_Return_Props = {
Buttons: ButtonsTree
}
export type ButtonsTree = {
Landing: ButtonProperties,
Car: ButtonProperties,
Special: ButtonProperties,
Relays: ButtonProperties
}
export type ButtonProperties = {
Inst: Instance?,
Prompt: ProximityPrompt?,
Attachment: Attachment?
}
export type ButtonsConstructor = ClassConstructor
local ButtonsModule = {} :: Impl_Constructor
@@ -68,30 +55,6 @@ function ButtonsModule.constructor(TagsConstructor, Model)
}, ButtonsModule)
end
--Button parsing
function ButtonsModule:DecodeCarTag(FloorTag)
local Match = FloorTag:match('%d+$')
return Match and tonumber(Match)
end
function ButtonsModule:Get()
local Buttons: GetButtons = {}
for TagName: string, Inst: TagProduct in self.Tags.__export do
local Split = TagName:split('_')
if Split[1] == self.Model and (Split[2] == "ElevatorButton" or Split[2] == "RelayButton") then
if typeof(Inst) == "Instance" then
Buttons[TagName] = Inst
else
warn("TODO block hit,", debug.traceback())
end
end
end
return Buttons
end
--[[
CarButton = Model_ElevatorButton_1
LandingButton = Model_ElevatorButton_Floor_1_Up

View File

@@ -17,7 +17,7 @@ type Impl_Constructor = {
constructor: Constructor_Fun,
Get: (Tags: Tags.TagsConstructor, Model: Enums.ElevatorValues) -> Lanterns,
--Class functions
__Activate: (self: ClassConstructor, EnabledState: boolean, IsDirectionLantern: boolean, Lantern: Lantern) -> (),
Activate: (self: ClassConstructor, EnabledState: boolean, IsDirectionLantern: boolean, Lantern: Lantern) -> (),
DirectionUp: (self: ClassConstructor, Enabled: boolean) -> (),
DirectionDown: (self: ClassConstructor, Enabled: boolean) -> (),
Toggle: (self: ClassConstructor, Enabled: boolean, Floor: number) -> (),
@@ -79,49 +79,9 @@ function Lanterns.constructor(MainDisplay, ChimeDirectionID, ChimeLandingID, Lan
}, Lanterns)
end
function Lanterns.Get(Tags, Model)
local Lanterns = {} :: Lanterns
for TagName: string, Inst: TagProduct in Tags.__export do
local Split = TagName:split('_')
if Split[1] == Model and Split[2] == "DirectionIndicator" then
local Floor = tonumber(Split[3])
if Floor then
if not Lanterns[Floor] then
Lanterns[Floor] = {
Inst = Inst :: BasePart,
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
Played = false
}
else
warn(`Lanterns: Floor "{tostring(Floor)}" was already wrote while parsing`)
end
else
if Split[3] == "Up" then
Lanterns.Up = {
Inst = Inst :: BasePart,
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
Played = false
}
elseif Split[3] == "Down" then
Lanterns.Down = {
Inst = Inst :: BasePart,
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
Played = false
}
else
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {Split[3]}`)
end
end
end
end
return Lanterns
end
local LanternLight = Tween.constructor(TweenInfo.new(1))
function Lanterns:__Activate(EnabledState, IsDirectionLantern, Lantern)
function Lanterns:Activate(EnabledState, IsDirectionLantern, Lantern)
local Tween = LanternLight:Start(Lantern.Light, {
Color = EnabledState and self.Colors.Active or self.Colors.Off
})
@@ -140,11 +100,11 @@ end
function Lanterns:Reset()
self.LanternsMap.Up.Played = false
self.LanternsMap.Down.Played = false
self:__Activate(false, true, self.LanternsMap.Up)
self:__Activate(false, true, self.LanternsMap.Down)
self:Activate(false, true, self.LanternsMap.Up)
self:Activate(false, true, self.LanternsMap.Down)
for n: number = 1, #self.LanternsMap do
self:__Activate(false, false, self.LanternsMap[n])
self:Activate(false, false, self.LanternsMap[n])
self.LanternsMap[n].Played = false
end
end
@@ -152,14 +112,14 @@ end
function Lanterns:DirectionUp(Enabled)
if not self.LanternsMap.Up.Played then
self.LanternsMap.Up.Played = true
self:__Activate(Enabled, true, self.LanternsMap.Up)
self:Activate(Enabled, true, self.LanternsMap.Up)
end
end
function Lanterns:DirectionDown(Enabled)
if not self.LanternsMap.Down.Played then
self.LanternsMap.Down.Played = true
self:__Activate(Enabled, true, self.LanternsMap.Down)
self:Activate(Enabled, true, self.LanternsMap.Down)
end
end
@@ -167,7 +127,7 @@ function Lanterns:Toggle(Enabled, Floor)
local f = self.LanternsMap[Floor]
if not f.Played then
f.Played = true
self:__Activate(Enabled, false, f)
self:Activate(Enabled, false, f)
end
end

View File

@@ -13,12 +13,6 @@ local Leveling = {
[8] = 188.007,
[9] = 213.058,
[10] = 239.245,
Between = {}
}
for n: number = 1, #Leveling, 2 do
Leveling.Between[n]=(Leveling[n+1]+Leveling[n])/2
end
return Leveling

View File

@@ -0,0 +1,134 @@
--!optimize 2
--!native
--!strict
local ParentDir = script.Parent
local Elevators = ParentDir:WaitForChild("Elevators")
local ElevatorEnums = Elevators:WaitForChild("Enums")
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tags = Storage:WaitForChild("Tags")
type TagsConstructor = Tags.TagsConstructor
type TagProdcut = Tags.TagProdcut
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Lanterns: (self: ClassConstructor, ElevatorModel: ) -> Lanterns
} & Impl_Static_Props
type Impl_Static_Props = {
Volume: number
}
type Constructor_Fun = (Tags: TagsConstructor) -> ClassConstructor
type Constructor_Return_Props = {
Tags: TagsConstructor,
}
type Lantern = {
Inst: BasePart,
Light: BasePart?,
Played: boolean
}
type GetButtons = {[string]: Instance}
export type Lanterns = {
[number]: Lantern,
Up: Lantern,
Down: Lantern
}
export type ButtonsTree = {
Landing: ButtonProperties,
Car: ButtonProperties,
Special: ButtonProperties,
Relays: ButtonProperties
}
export type ButtonProperties = {
Inst: Instance?,
Prompt: ProximityPrompt?,
Attachment: Attachment?
}
local TagService = {} :: Impl_Constructor
TagService.__index = TagService
function TagService.constructor(Tags)
return setmetatable({
Tags = Tags
}, TagService)
end
TagService.Decoders = {}
function TagService.Decoders:CarTag(FloorTag)
local Match = FloorTag:match('%d+$')
return Match and tonumber(Match)
end
function TagService:Lanterns(ElevatorModel)
local Lanterns = {} :: Lanterns
for TagName: string, Inst: TagProduct in self.Tags do
local Split = TagName:split('_')
if Split[1] == ElevatorModel and Split[2] == "DirectionIndicator" then
local Floor = tonumber(Split[3])
if Floor then
if not Lanterns[Floor] then
Lanterns[Floor] = {
Inst = Inst :: BasePart,
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
Played = false
}
else
warn(`Lanterns: Floor "{tostring(Floor)}" was already wrote while parsing`)
end
else
if Split[3] == "Up" then
Lanterns.Up = {
Inst = Inst :: BasePart,
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
Played = false
}
elseif Split[3] == "Down" then
Lanterns.Down = {
Inst = Inst :: BasePart,
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
Played = false
}
else
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {Split[3]}`)
end
end
end
end
return Lanterns
end
function TagService:Buttons(ElevatorModel)
local Buttons: GetButtons = {}
for TagName: string, Inst: TagProduct in self.Tags do
local Split = TagName:split('_')
if Split[1] == self.Model and (Split[2] == "ElevatorButton" or Split[2] == "RelayButton") then
if typeof(Inst) == "Instance" then
Buttons[TagName] = Inst
else
warn("TODO block hit,", debug.traceback())
end
end
end
return Buttons
end
function TagService:Interactables()
end
return TagService