mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
TagService -> Tags and more refactoring, close to working again
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,10 +4,10 @@
|
||||
|
||||
local ElevatorsDir = script.Parent
|
||||
local MainDir = ElevatorsDir.Parent
|
||||
local TagService = require(MainDir:WaitForChild("TagService"))
|
||||
|
||||
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TagsModule = require(Storage:WaitForChild("Tags"))
|
||||
local TagsModule = require(MainDir:WaitForChild("Tags"))
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
|
||||
type TagsConstructor = TagsModule.TagsConstructor
|
||||
@@ -21,7 +21,7 @@ type Impl_Constructor = {
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
DecodeCarTag: (self: ClassConstructor, FloorTag: string) -> number?,
|
||||
CreatePromptButtons: (self: ClassConstructor) -> TagService.ButtonsTree,
|
||||
CreatePromptButtons: (self: ClassConstructor) -> TagsModule.ButtonsTree,
|
||||
AestheticActivateButton: (self: ClassConstructor, Button: BasePart, ActivatedState: boolean, ActivatedColor: Color3) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
@@ -33,7 +33,7 @@ type Constructor_Fun = (TagsConstructor: TagsConstructor, Model: Enums.ElevatorV
|
||||
type Constructor_Return_Props = {
|
||||
Tags: TagsConstructor,
|
||||
Model: Enums.ElevatorValues,
|
||||
Buttons: TagService.ButtonsTree
|
||||
Buttons: TagsModule.ButtonsTree
|
||||
}
|
||||
|
||||
export type ButtonsConstructor = ClassConstructor
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local ElevatorDir = script.Parent
|
||||
local MainDir = ElevatorDir.Parent
|
||||
|
||||
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Tween = require(Storage:WaitForChild("Tween"))
|
||||
local Tags = require(Storage:WaitForChild("Tags"))
|
||||
local Tags = require(MainDir:WaitForChild("Tags"))
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
|
||||
type rbxassetid = string
|
||||
@@ -14,7 +17,7 @@ type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
Get: (Tags: Tags.TagsConstructor, Model: Enums.ElevatorValues) -> Lanterns,
|
||||
Get: (Tags: Tags.TagsConstructor, Model: Enums.ElevatorValues) -> Tags.Lanterns,
|
||||
--Class functions
|
||||
Activate: (self: ClassConstructor, EnabledState: boolean, IsDirectionLantern: boolean, Lantern: Lantern) -> (),
|
||||
DirectionUp: (self: ClassConstructor, Enabled: boolean) -> (),
|
||||
@@ -24,12 +27,13 @@ type Impl_Constructor = {
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
Volume: number
|
||||
Volume: number,
|
||||
LightTweenTime: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (MainDisplay: UnionOperation, ChimeDirectionID: rbxassetid, ChimeLandingID: rbxassetid, Lanterns: Lanterns, Colors: Colors) -> ClassConstructor
|
||||
type Constructor_Fun = (MainDisplay: UnionOperation, ChimeDirectionID: rbxassetid, ChimeLandingID: rbxassetid, Lanterns: Tags.Lanterns, Colors: Colors) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
LanternsMap: Lanterns,
|
||||
LanternsMap: Tags.Lanterns,
|
||||
AudioChimeDirection: Sound,
|
||||
AudioChimeLanding: Sound,
|
||||
Colors: Colors
|
||||
@@ -41,12 +45,6 @@ type Lantern = {
|
||||
Played: boolean
|
||||
}
|
||||
|
||||
type Lanterns = {
|
||||
[number]: Lantern,
|
||||
Up: Lantern,
|
||||
Down: Lantern
|
||||
}
|
||||
|
||||
export type Colors = {
|
||||
Active: Color3,
|
||||
Off: Color3
|
||||
@@ -57,7 +55,8 @@ export type LanternsConstructor = ClassConstructor
|
||||
local Lanterns = {} :: Impl_Constructor
|
||||
Lanterns.__index = Lanterns
|
||||
|
||||
Lanterns.Volume = .8
|
||||
Lanterns.Volume = .5
|
||||
Lanterns.LightTweenTime = 1
|
||||
|
||||
function Lanterns.constructor(MainDisplay, ChimeDirectionID, ChimeLandingID, LanternsMap, Colors)
|
||||
local AudioChimeDirection = Instance.new("Sound") :: Sound
|
||||
@@ -78,7 +77,7 @@ function Lanterns.constructor(MainDisplay, ChimeDirectionID, ChimeLandingID, Lan
|
||||
}, Lanterns)
|
||||
end
|
||||
|
||||
local LanternLight = Tween.constructor(TweenInfo.new(1))
|
||||
local LanternLight = Tween.constructor(TweenInfo.new(Lanterns.LightTweenTime))
|
||||
|
||||
function Lanterns:Activate(EnabledState, IsDirectionLantern, Lantern)
|
||||
local Tween = LanternLight:Start(Lantern.Light, {
|
||||
@@ -97,10 +96,14 @@ function Lanterns:Activate(EnabledState, IsDirectionLantern, Lantern)
|
||||
end
|
||||
|
||||
function Lanterns:Reset()
|
||||
if self.LanternsMap.Up then
|
||||
self.LanternsMap.Up.Played = false
|
||||
self.LanternsMap.Down.Played = false
|
||||
self:Activate(false, true, self.LanternsMap.Up)
|
||||
end
|
||||
if self.LanternsMap.Down then
|
||||
self.LanternsMap.Down.Played = false
|
||||
self:Activate(false, true, self.LanternsMap.Down)
|
||||
end
|
||||
|
||||
for n: number = 1, #self.LanternsMap do
|
||||
self:Activate(false, false, self.LanternsMap[n])
|
||||
@@ -109,14 +112,14 @@ function Lanterns:Reset()
|
||||
end
|
||||
|
||||
function Lanterns:DirectionUp(Enabled)
|
||||
if not self.LanternsMap.Up.Played then
|
||||
if self.LanternsMap.Up and not self.LanternsMap.Up.Played then
|
||||
self.LanternsMap.Up.Played = true
|
||||
self:Activate(Enabled, true, self.LanternsMap.Up)
|
||||
end
|
||||
end
|
||||
|
||||
function Lanterns:DirectionDown(Enabled)
|
||||
if not self.LanternsMap.Down.Played then
|
||||
if self.LanternsMap.Down and not self.LanternsMap.Down.Played then
|
||||
self.LanternsMap.Down.Played = true
|
||||
self:Activate(Enabled, true, self.LanternsMap.Down)
|
||||
end
|
||||
|
||||
@@ -8,7 +8,6 @@ local MainDir = Elevators.Parent
|
||||
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RS: RunService = game:GetService("RunService")
|
||||
|
||||
local TagsModule = require(Storage:WaitForChild("Tags"))
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
|
||||
local Leveling = require(script:WaitForChild("Leveling"))
|
||||
@@ -21,12 +20,12 @@ local TractionRopes = require(Elevators:WaitForChild("TractionRopes"))
|
||||
local Lanterns = require(Elevators:WaitForChild("Lanterns"))
|
||||
|
||||
local PromptModule = require(MainDir:WaitForChild("Map"):WaitForChild("Prompts"))
|
||||
local TagService = require(MainDir:WaitForChild("TagService"))
|
||||
local Tags = require(MainDir:WaitForChild("Tags"))
|
||||
|
||||
type rbxassetid = string
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
type TagsConstructor = TagsModule.TagsConstructor
|
||||
type Tags = Tags.ExportedTags
|
||||
type TagsConstructor = Tags.TagsConstructor
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
@@ -49,7 +48,7 @@ type Impl_Static_Props = {
|
||||
__CurrentFloor: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, TagServiceConstructor: TagService.TagsServiceConstructor) -> ClassConstructor
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ButtonsTags: Tags.ButtonsTree, LanternsTags: Tags.Lanterns) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
MOConstructor: MovingObjects.MovingObjectsConstructor,
|
||||
@@ -73,7 +72,10 @@ type Constructor_Return_Props = {
|
||||
__MovingConnection: RBXScriptConnection?,
|
||||
}
|
||||
|
||||
type ButtonFunction = (self: ClassConstructor, ButtonName: string, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonTree: ButtonTags.ButtonProperties) -> ()
|
||||
type ButtonFunction = (self: ClassConstructor, ButtonName: string, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonTree: Tags.ButtonProperties) -> ()
|
||||
type ButtonFunctions = {
|
||||
[Enums.ButtonTreeValues]: ButtonFunction
|
||||
}
|
||||
|
||||
local Otis1960 = {} :: Impl_Constructor
|
||||
Otis1960.__index = Otis1960
|
||||
@@ -89,13 +91,13 @@ Otis1960.LanternChimeLanding = "rbxassetid://16990290265"
|
||||
Otis1960.__Moving = false
|
||||
Otis1960.__CurrentFloor = 1
|
||||
|
||||
local ButtonFunctions: {[Enums.ButtonTreeValues]: ButtonFunction} = {
|
||||
local ButtonFunctions: ButtonFunctions = {
|
||||
[Enums.ButtonTree.Landing] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
|
||||
|
||||
end,
|
||||
|
||||
[Enums.ButtonTree.Car] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
|
||||
local DecodedFloor = TagService.Decoder.CarTag(ButtonName)
|
||||
local DecodedFloor = Tags.Decoders.CarTag(ButtonName)
|
||||
if not DecodedFloor then
|
||||
|
||||
end
|
||||
@@ -134,7 +136,7 @@ local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTag
|
||||
end
|
||||
end
|
||||
|
||||
function Otis1960.constructor(TagsConstructor, TagServiceConstructor)
|
||||
function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags)
|
||||
local self = {} :: Constructor_Return_Props
|
||||
self.ElevatorBox_1960 = TagsConstructor:Request("ElevatorMover_1960") :: UnionOperation
|
||||
self.ElevatorDoor1 = TagsConstructor:Request("ElevatorDoor_1960_1") :: BasePart
|
||||
@@ -156,9 +158,9 @@ function Otis1960.constructor(TagsConstructor, TagServiceConstructor)
|
||||
|
||||
--Audio
|
||||
local LanternDisplay = TagsConstructor:Request("Otis1960_LanternDisplayMain") :: UnionOperation
|
||||
local LaternTags = TagServiceConstructor:Lanterns(Enums.Elevator.Otis1960) :: TagService.Lanterns
|
||||
local LanternTags = TagsConstructor:ElevatorLanterns()[Enums.Elevator.Otis1960]
|
||||
|
||||
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, Otis1960.LanternChimeDirection, Otis1960.LanternChimeLanding, LaternTags, {
|
||||
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, Otis1960.LanternChimeDirection, Otis1960.LanternChimeLanding, LanternTags, {
|
||||
Active = Otis1960.LanternDisplayColorOn,
|
||||
Off = Otis1960.LanternDisplayColorOff
|
||||
} :: Lanterns.Colors)
|
||||
@@ -177,7 +179,7 @@ function Otis1960.constructor(TagsConstructor, TagServiceConstructor)
|
||||
local ClassConstructor = setmetatable(self, Otis1960)
|
||||
HookButtons(ClassConstructor, ButtonsConstructor, Enums.ButtonTree.Car)
|
||||
|
||||
print("[DEBUG] Otis1960 Lanterns=", LaternTags)
|
||||
print("[DEBUG] Otis1960 Lanterns=", LanternTags)
|
||||
print("[DEBUG] Otis1960 Buttons=", Otis1960_Buttons)
|
||||
print("🔝 Otis1960 initialized and ready")
|
||||
return ClassConstructor
|
||||
|
||||
@@ -20,6 +20,7 @@ type Constructor_Fun = (Prompt: ProximityPrompt, Instance: Instance, Enabled: bo
|
||||
type Constructor_Return_Props = {
|
||||
Prompt: ProximityPrompt,
|
||||
Instance: Instance,
|
||||
|
||||
__TriggeredCallback: PromptCallback?,
|
||||
__TriggerEndedCallback: PromptCallback?,
|
||||
__PromptConnections: {
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local Tags = require(Storage:WaitForChild("Tags"))
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
|
||||
type rbxassetid = string
|
||||
type TagsConstructor = Tags.TagsConstructor
|
||||
type TagProduct = Tags.TagProduct
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Lanterns: (self: ClassConstructor, ElevatorModel: Enums.ElevatorValues) -> Lanterns,
|
||||
Buttons: (self: ClassConstructor, ElevatorModel: Enums.ElevatorValues) -> GetButtons,
|
||||
Interactables: (self: ClassConstructor) -> InteractablesTree
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
MaxLightSwitchActivationDistance: number,
|
||||
MaxLightSwitchHoldDuration: number,
|
||||
LightSwitchActivateSoundId: rbxassetid,
|
||||
|
||||
Decoder: {
|
||||
CarTag: (FloorTag: string) -> number?
|
||||
}
|
||||
}
|
||||
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
ExportedTags: Tags.ExportedTags,
|
||||
}
|
||||
|
||||
type Lantern = {
|
||||
Inst: BasePart,
|
||||
Light: BasePart?,
|
||||
Played: boolean
|
||||
}
|
||||
|
||||
export type GetButtons = {
|
||||
[string]: Instance
|
||||
}
|
||||
|
||||
export type LightSwitchTree = {
|
||||
[string]: {
|
||||
Switch: Instance?,
|
||||
Lights: {Instance}?,
|
||||
Prompt: ProximityPrompt?,
|
||||
ClickSound: Sound?
|
||||
}
|
||||
}
|
||||
|
||||
export type InteractablesTree = {
|
||||
LightSwitches: LightSwitchTree
|
||||
}
|
||||
|
||||
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?
|
||||
}
|
||||
|
||||
export type TagsServiceConstructor = ClassConstructor
|
||||
|
||||
local TagService = {} :: Impl_Constructor
|
||||
TagService.__index = TagService
|
||||
|
||||
TagService.MaxLightSwitchActivationDistance = 3
|
||||
TagService.MaxLightSwitchHoldDuration = .15
|
||||
TagService.LightSwitchActivateSoundId = "rbxassetid://156286438"
|
||||
|
||||
function TagService.constructor(TagsConstructor)
|
||||
return setmetatable({
|
||||
ExportedTags = TagsConstructor.__export
|
||||
}, TagService)
|
||||
end
|
||||
|
||||
TagService.Decoder = {
|
||||
CarTag = function(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.ExportedTags do
|
||||
local Split = TagName:split('_')
|
||||
local LanternModel = Split[1]
|
||||
local IndicatorType = Split[2]
|
||||
local FloorHint = Split[3]
|
||||
|
||||
if LanternModel == ElevatorModel and IndicatorType == "DirectionIndicator" then
|
||||
local Floor = tonumber(FloorHint)
|
||||
|
||||
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 FloorHint == "Up" then
|
||||
Lanterns.Up = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
}
|
||||
elseif FloorHint == "Down" then
|
||||
Lanterns.Down = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
}
|
||||
else
|
||||
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {FloorHint}`)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Lanterns
|
||||
end
|
||||
|
||||
function TagService:Buttons(ElevatorModel)
|
||||
local Buttons: GetButtons = {}
|
||||
|
||||
for TagName: string, Inst: TagProduct in self.ExportedTags do
|
||||
local Split = TagName:split('_')
|
||||
local ModelHint = Split[1]
|
||||
local ButtonHint = Split[2]
|
||||
|
||||
if ModelHint == ElevatorModel and (ButtonHint == "ElevatorButton" or ButtonHint == "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()
|
||||
local Interactables: InteractablesTree = {
|
||||
LightSwitches = {}
|
||||
}
|
||||
|
||||
for TagName: string, Inst: TagProduct in self.ExportedTags do
|
||||
local Split = TagName:split('_')
|
||||
local InteractHint = Split[1]
|
||||
local InteractType = Split[2]
|
||||
local InteractObjectLocation = Split[3]
|
||||
|
||||
if InteractHint == "Interact" then
|
||||
Interactables.LightSwitches[InteractObjectLocation] = {}
|
||||
|
||||
if InteractType == Enums.Interactables.LightSwitch then
|
||||
local ptr = Interactables.LightSwitches[InteractObjectLocation]
|
||||
local itype = type(Inst) == "table"
|
||||
local Switch = itype and (Inst :: {Instance})[1] or Inst :: Instance
|
||||
if itype then
|
||||
warn(`2 or more light switch tags were present under the same name, using the first index. "{TagName}". This feature is not implemented yet`)
|
||||
end
|
||||
|
||||
local Attachment = Instance.new("Attachment") :: Attachment
|
||||
Attachment.Parent = Switch
|
||||
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
|
||||
Prompt.MaxActivationDistance = TagService.MaxLightSwitchActivationDistance
|
||||
Prompt.HoldDuration = TagService.MaxLightSwitchHoldDuration
|
||||
Prompt.Parent = Attachment
|
||||
local ClickSound = Instance.new("Sound") :: Sound
|
||||
ClickSound.SoundId = TagService.LightSwitchActivateSoundId
|
||||
ClickSound.Parent = Switch
|
||||
|
||||
ptr.Switch = Switch
|
||||
ptr.Prompt = Prompt
|
||||
ptr.ClickSound = ClickSound
|
||||
elseif InteractType == Enums.Interactables.Light then
|
||||
local ptr = Interactables.LightSwitches[InteractObjectLocation]
|
||||
|
||||
if type(Inst) == "table" then
|
||||
ptr.Lights = table.clone(Inst)
|
||||
else
|
||||
ptr.Lights = {}
|
||||
table.insert(ptr.Lights :: {Instance}, Inst)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Interactables
|
||||
end
|
||||
|
||||
return TagService
|
||||
264
src/server/main/Tags.lua
Normal file
264
src/server/main/Tags.lua
Normal file
@@ -0,0 +1,264 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local CS = game:GetService("CollectionService")
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
|
||||
type Error = never
|
||||
type rbxassetid = string
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Nuke: (self: ClassConstructor) -> (),
|
||||
Request: (self: ClassConstructor, Name: string) -> TagProduct | Error,
|
||||
__ElevatorLanterns: (self: ClassConstructor) -> LanternsTree,
|
||||
__ElevatorButtons: (self: ClassConstructor) -> ElevatorButtons,
|
||||
__Interactables: (self: ClassConstructor) -> InteractablesTree
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
MaxLightSwitchActivationDistance: number,
|
||||
MaxLightSwitchHoldDuration: number,
|
||||
LightSwitchActivateSoundId: rbxassetid,
|
||||
|
||||
Decoders: {
|
||||
CarTag: (FloorTag: string) -> number?
|
||||
}
|
||||
}
|
||||
|
||||
type Constructor_Fun = () -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
__export: ExportedTags
|
||||
}
|
||||
|
||||
type Lantern = {
|
||||
Inst: BasePart,
|
||||
Light: BasePart?,
|
||||
Played: boolean
|
||||
}
|
||||
|
||||
export type ElevatorButtons = {
|
||||
[Enums.ElevatorValues]: {
|
||||
[string]: Instance
|
||||
}
|
||||
}
|
||||
|
||||
export type Lanterns = {
|
||||
[number]: Lantern,
|
||||
Up: Lantern?,
|
||||
Down: Lantern?
|
||||
}
|
||||
|
||||
export type LanternsTree = {
|
||||
[Enums.ElevatorValues]: Lanterns
|
||||
}
|
||||
|
||||
export type LightSwitchTree = {
|
||||
[string]: {
|
||||
Switch: Instance?,
|
||||
Lights: {Instance}?,
|
||||
Prompt: ProximityPrompt?,
|
||||
ClickSound: Sound?
|
||||
}
|
||||
}
|
||||
|
||||
export type InteractablesTree = {
|
||||
LightSwitches: LightSwitchTree
|
||||
}
|
||||
|
||||
|
||||
export type ButtonsTree = {
|
||||
Landing: ButtonProperties,
|
||||
Car: ButtonProperties,
|
||||
Special: ButtonProperties,
|
||||
Relays: ButtonProperties
|
||||
}
|
||||
|
||||
export type ButtonProperties = {
|
||||
Inst: Instance?,
|
||||
Prompt: ProximityPrompt?,
|
||||
Attachment: Attachment?
|
||||
}
|
||||
|
||||
export type TagProduct = Instance | {Instance}
|
||||
export type ExportedTags = {[string]: TagProduct}
|
||||
export type TagsConstructor = ClassConstructor
|
||||
|
||||
local Tags = {} :: Impl_Constructor
|
||||
Tags.__index = Tags
|
||||
|
||||
Tags.MaxLightSwitchActivationDistance = 3
|
||||
Tags.MaxLightSwitchHoldDuration = .15
|
||||
Tags.LightSwitchActivateSoundId = "rbxassetid://156286438"
|
||||
|
||||
Tags.Decoders = {
|
||||
CarTag = function(FloorTag)
|
||||
local Match = FloorTag:match('%d+$')
|
||||
return Match and tonumber(Match)
|
||||
end
|
||||
}
|
||||
|
||||
function Tags.constructor()
|
||||
local Exports: ExportedTags = {}
|
||||
local AllTags = CS:GetAllTags()
|
||||
|
||||
for n: number = 1, #AllTags do
|
||||
local TagName = AllTags[n]
|
||||
local Tagged = CS:GetTagged(TagName)
|
||||
Exports[TagName] = #Tagged>1 and Tagged or Tagged[1]
|
||||
end
|
||||
|
||||
return setmetatable({
|
||||
__export = Exports
|
||||
}, Tags)
|
||||
end
|
||||
|
||||
function Tags:Request(Name)
|
||||
return self.__export[Name] or error(`Error requesting tag name, tag name "{Name}" does not exist.`, 2)
|
||||
end
|
||||
|
||||
function Tags:Nuke()
|
||||
local Exports = self.__export
|
||||
|
||||
for i: string, v: TagProduct in Exports do
|
||||
if type(v) == "table" then
|
||||
for n: number = 1, #v do
|
||||
CS:RemoveTag(v[n], i)
|
||||
end
|
||||
else
|
||||
CS:RemoveTag(v, i)
|
||||
end
|
||||
end
|
||||
warn("☢️ nuked all in-game tags. Left-over tags="..table.concat(CS:GetAllTags(), ", "))
|
||||
end
|
||||
|
||||
function Tags:__ElevatorLanterns()
|
||||
local Lanterns: LanternsTree = {}
|
||||
|
||||
for _, EnumValue in Enums.Elevator do
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues] = {}
|
||||
|
||||
for TagName: string, Inst: TagProduct in self.__export do
|
||||
local Split = TagName:split('_')
|
||||
local LanternModel = Split[1]
|
||||
local IndicatorType = Split[2]
|
||||
local FloorHint = Split[3]
|
||||
|
||||
if LanternModel == (EnumValue :: string) and IndicatorType == "DirectionIndicator" then
|
||||
local Floor = tonumber(FloorHint)
|
||||
|
||||
if Floor then
|
||||
if not Lanterns[EnumValue :: Enums.ElevatorValues][Floor] then
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues][Floor] = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
}
|
||||
else
|
||||
warn(`Lanterns: Floor "{tostring(Floor)}" was already wrote while parsing`)
|
||||
end
|
||||
else
|
||||
if FloorHint == "Up" then
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues].Up = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
}
|
||||
elseif FloorHint == "Down" then
|
||||
Lanterns[EnumValue :: Enums.ElevatorValues].Down = {
|
||||
Inst = Inst :: BasePart,
|
||||
Light = ((Inst :: BasePart).Parent :: Instance):FindFirstChild("Light") :: BasePart?,
|
||||
Played = false
|
||||
}
|
||||
else
|
||||
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {FloorHint}`)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Lanterns
|
||||
end
|
||||
|
||||
function Tags:__ElevatorButtons()
|
||||
local Buttons: ElevatorButtons = {}
|
||||
|
||||
for _, EnumValue in Enums.Elevator do
|
||||
Buttons[EnumValue :: Enums.ElevatorValues] = {}
|
||||
|
||||
for TagName: string, Inst: TagProduct in self.__export do
|
||||
local Split = TagName:split('_')
|
||||
local ModelHint = Split[1]
|
||||
local ButtonHint = Split[2]
|
||||
|
||||
if ModelHint == (EnumValue :: Enums.ElevatorValues) and (ButtonHint == "ElevatorButton" or ButtonHint == "RelayButton") then
|
||||
if typeof(Inst) == "Instance" then
|
||||
Buttons[EnumValue :: Enums.ElevatorValues][TagName] = Inst
|
||||
else
|
||||
warn("TODO block hit,", debug.traceback())
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Buttons
|
||||
end
|
||||
|
||||
function Tags:__Interactables()
|
||||
local Interactables: InteractablesTree = {
|
||||
LightSwitches = {}
|
||||
}
|
||||
|
||||
for TagName: string, Inst: TagProduct in self.__export do
|
||||
local Split = TagName:split('_')
|
||||
local InteractHint = Split[1]
|
||||
local InteractType = Split[2]
|
||||
local InteractObjectLocation = Split[3]
|
||||
|
||||
if InteractHint == "Interact" then
|
||||
Interactables.LightSwitches[InteractObjectLocation] = {}
|
||||
|
||||
if InteractType == Enums.Interactables.LightSwitch then
|
||||
local ptr = Interactables.LightSwitches[InteractObjectLocation]
|
||||
local itype = type(Inst) == "table"
|
||||
local Switch = itype and (Inst :: {Instance})[1] or Inst :: Instance
|
||||
if itype then
|
||||
warn(`2 or more light switch tags were present under the same name, using the first index. "{TagName}". This feature is not implemented yet`)
|
||||
end
|
||||
|
||||
local Attachment = Instance.new("Attachment") :: Attachment
|
||||
Attachment.Parent = Switch
|
||||
local Prompt = Instance.new("ProximityPrompt") :: ProximityPrompt
|
||||
Prompt.MaxActivationDistance = Tags.MaxLightSwitchActivationDistance
|
||||
Prompt.HoldDuration = Tags.MaxLightSwitchHoldDuration
|
||||
Prompt.Parent = Attachment
|
||||
local ClickSound = Instance.new("Sound") :: Sound
|
||||
ClickSound.SoundId = Tags.LightSwitchActivateSoundId
|
||||
ClickSound.Parent = Switch
|
||||
|
||||
ptr.Switch = Switch
|
||||
ptr.Prompt = Prompt
|
||||
ptr.ClickSound = ClickSound
|
||||
elseif InteractType == Enums.Interactables.Light then
|
||||
local ptr = Interactables.LightSwitches[InteractObjectLocation]
|
||||
|
||||
if type(Inst) == "table" then
|
||||
ptr.Lights = table.clone(Inst)
|
||||
else
|
||||
ptr.Lights = {}
|
||||
table.insert(ptr.Lights :: {Instance}, Inst)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Interactables
|
||||
end
|
||||
|
||||
return Tags
|
||||
@@ -5,7 +5,7 @@
|
||||
local ShowEditorEntities = game:GetService("RunService"):IsServer()
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local TagsModule = require(Storage:WaitForChild("Tags"))
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
|
||||
local Elevators = script:WaitForChild("Elevators")
|
||||
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
|
||||
@@ -13,14 +13,13 @@ local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
|
||||
local Map = script:WaitForChild("Map")
|
||||
local LightSwitchesConstructor = require(Map:WaitForChild("LightSwitches"))
|
||||
|
||||
local TagService = require(script:WaitForChild("TagService"))
|
||||
local TagsModule = require(script:WaitForChild("Tags"))
|
||||
local HideEditorEntities = require(script:WaitForChild("EditorEntities"))
|
||||
local Lighting_Stuff = require(script:WaitForChild("Lighting"))
|
||||
local Workspace_Stuff = require(script:WaitForChild("Workspace"))
|
||||
local StarterPlayer_Stuff = require(script:WaitForChild("StarterPlayer"))
|
||||
|
||||
local TagsConstructor = TagsModule.constructor()
|
||||
local TagServiceConstructor = TagService.constructor(TagsConstructor)
|
||||
print("[DEBUG] Tags=", TagsConstructor.__export)
|
||||
|
||||
HideEditorEntities.indexAll(ShowEditorEntities)
|
||||
@@ -31,10 +30,15 @@ Lighting_Stuff()
|
||||
Workspace_Stuff()
|
||||
|
||||
--Map
|
||||
local Interactables = TagServiceConstructor:Interactables()
|
||||
local Interactables = TagsConstructor:__Interactables()
|
||||
print("[DEBUG] Interactables=", Interactables)
|
||||
|
||||
local LightSwitches = LightSwitchesConstructor.constructor(Interactables.LightSwitches)
|
||||
--local LightSwitches = LightSwitchesConstructor.constructor(Interactables.LightSwitches)
|
||||
|
||||
--Start the elevators
|
||||
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, TagServiceConstructor)
|
||||
local Buttons = TagsConstructor:__ElevatorButtons()
|
||||
local Lanterns = TagsConstructor:__ElevatorLanterns()
|
||||
|
||||
local Otis1960Lanterns = Lanterns[Enums.Elevator.Otis1960]
|
||||
local Otis1960Buttons = Buttons[Enums.Elevator.Otis1960]
|
||||
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, Otis1960Buttons, Otis1960Lanterns)
|
||||
@@ -1,64 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type Error = never
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Nuke: (self: ClassConstructor) -> (),
|
||||
Request: (self: ClassConstructor, Name: string) -> TagProduct | Error
|
||||
}
|
||||
|
||||
type Constructor_Fun = () -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
__export: ExportedTags
|
||||
}
|
||||
|
||||
export type TagProduct = Instance | {Instance}
|
||||
export type ExportedTags = {[string]: TagProduct}
|
||||
export type TagsConstructor = ClassConstructor
|
||||
|
||||
local Tags = {} :: Impl_Constructor
|
||||
Tags.__index = Tags
|
||||
|
||||
local CS: CollectionService = game:GetService("CollectionService")
|
||||
|
||||
function Tags.constructor()
|
||||
local Exports: ExportedTags = {}
|
||||
local AllTags = CS:GetAllTags()
|
||||
|
||||
for n: number = 1, #AllTags do
|
||||
local TagName = AllTags[n]
|
||||
local Tagged = CS:GetTagged(TagName)
|
||||
Exports[TagName] = #Tagged>1 and Tagged or Tagged[1]
|
||||
end
|
||||
|
||||
return setmetatable({
|
||||
__export = Exports
|
||||
}, Tags)
|
||||
end
|
||||
|
||||
function Tags:Request(Name)
|
||||
return self.__export[Name] or error(`Error requesting tag name, tag name "{Name}" does not exist.`, 2)
|
||||
end
|
||||
|
||||
function Tags:Nuke()
|
||||
local Exports = self.__export
|
||||
|
||||
for i: string, v: TagProduct in Exports do
|
||||
if type(v) == "table" then
|
||||
for n: number = 1, #v do
|
||||
CS:RemoveTag(v[n], i)
|
||||
end
|
||||
else
|
||||
CS:RemoveTag(v, i)
|
||||
end
|
||||
end
|
||||
warn("☢️ nuked all in-game tags. Left-over tags="..table.concat(CS:GetAllTags(), ", "))
|
||||
end
|
||||
|
||||
return Tags
|
||||
Reference in New Issue
Block a user