mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
work on light switches
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -2,12 +2,9 @@
|
|||||||
--!native
|
--!native
|
||||||
--!strict
|
--!strict
|
||||||
|
|
||||||
local ParentDir = script.Parent
|
|
||||||
local Elevators = ParentDir:WaitForChild("Elevators")
|
|
||||||
local ElevatorEnums = require(Elevators:WaitForChild("Enums"))
|
|
||||||
|
|
||||||
local Storage = game:GetService("ReplicatedStorage")
|
local Storage = game:GetService("ReplicatedStorage")
|
||||||
local Tags = require(Storage:WaitForChild("Tags"))
|
local Tags = require(Storage:WaitForChild("Tags"))
|
||||||
|
local Enums = require(Storage:WaitForChild("Enums"))
|
||||||
|
|
||||||
type TagsConstructor = Tags.TagsConstructor
|
type TagsConstructor = Tags.TagsConstructor
|
||||||
type TagProduct = Tags.TagProduct
|
type TagProduct = Tags.TagProduct
|
||||||
@@ -17,17 +14,18 @@ type Impl_Constructor = {
|
|||||||
__index: Impl_Constructor,
|
__index: Impl_Constructor,
|
||||||
constructor: Constructor_Fun,
|
constructor: Constructor_Fun,
|
||||||
--Class functions
|
--Class functions
|
||||||
Lanterns: (self: ClassConstructor, ElevatorModel: ElevatorEnums.ElevatorValues) -> Lanterns,
|
Lanterns: (self: ClassConstructor, ElevatorModel: Enums.ElevatorValues) -> Lanterns,
|
||||||
Buttons: (self: ClassConstructor, ElevatorModel: ElevatorEnums.ElevatorValues) -> GetButtons,
|
Buttons: (self: ClassConstructor, ElevatorModel: Enums.ElevatorValues) -> GetButtons,
|
||||||
Interactables: (self: ClassConstructor) -> ()
|
Interactables: (self: ClassConstructor) -> InteractablesTree
|
||||||
} & Impl_Static_Props
|
} & Impl_Static_Props
|
||||||
|
|
||||||
type Decoders = {
|
|
||||||
CarTag: (FloorTag: string) -> ()
|
|
||||||
}
|
|
||||||
|
|
||||||
type Impl_Static_Props = {
|
type Impl_Static_Props = {
|
||||||
Decoders: Decoders
|
DefaultMaxLightSwitchActivationDistance: number,
|
||||||
|
DefaultMaxLightSwitchHoldDuration: number,
|
||||||
|
|
||||||
|
Decoder: {
|
||||||
|
CarTag: (FloorTag: string) -> ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Constructor_Fun = (TagsConstructor: TagsConstructor) -> ClassConstructor
|
type Constructor_Fun = (TagsConstructor: TagsConstructor) -> ClassConstructor
|
||||||
@@ -40,7 +38,19 @@ type Lantern = {
|
|||||||
Light: BasePart?,
|
Light: BasePart?,
|
||||||
Played: boolean
|
Played: boolean
|
||||||
}
|
}
|
||||||
type GetButtons = {[string]: Instance}
|
|
||||||
|
type GetButtons = {
|
||||||
|
[string]: Instance
|
||||||
|
}
|
||||||
|
type InteractablesTree = {
|
||||||
|
LightSwitches: {
|
||||||
|
[string]: {
|
||||||
|
Switch: Instance?,
|
||||||
|
Lights: {Instance}?,
|
||||||
|
Prompt: ProximityPrompt?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export type Lanterns = {
|
export type Lanterns = {
|
||||||
[number]: Lantern,
|
[number]: Lantern,
|
||||||
@@ -70,7 +80,10 @@ function TagService.constructor(TagsConstructor)
|
|||||||
}, TagService)
|
}, TagService)
|
||||||
end
|
end
|
||||||
|
|
||||||
TagService.Decoders = {
|
TagService.DefaultMaxLightSwitchActivationDistance = 3
|
||||||
|
TagService.DefaultMaxLightSwitchHoldDuration = .15
|
||||||
|
|
||||||
|
TagService.Decoder = {
|
||||||
CarTag = function(FloorTag)
|
CarTag = function(FloorTag)
|
||||||
local Match = FloorTag:match('%d+$')
|
local Match = FloorTag:match('%d+$')
|
||||||
return Match and tonumber(Match)
|
return Match and tonumber(Match)
|
||||||
@@ -82,9 +95,12 @@ function TagService:Lanterns(ElevatorModel)
|
|||||||
|
|
||||||
for TagName: string, Inst: TagProduct in self.ExportedTags do
|
for TagName: string, Inst: TagProduct in self.ExportedTags do
|
||||||
local Split = TagName:split('_')
|
local Split = TagName:split('_')
|
||||||
|
local LanternModel = Split[1]
|
||||||
|
local IndicatorType = Split[2]
|
||||||
|
local FloorHint = Split[3]
|
||||||
|
|
||||||
if Split[1] == ElevatorModel and Split[2] == "DirectionIndicator" then
|
if LanternModel == ElevatorModel and IndicatorType == "DirectionIndicator" then
|
||||||
local Floor = tonumber(Split[3])
|
local Floor = tonumber(FloorHint)
|
||||||
|
|
||||||
if Floor then
|
if Floor then
|
||||||
if not Lanterns[Floor] then
|
if not Lanterns[Floor] then
|
||||||
@@ -97,20 +113,20 @@ function TagService:Lanterns(ElevatorModel)
|
|||||||
warn(`Lanterns: Floor "{tostring(Floor)}" was already wrote while parsing`)
|
warn(`Lanterns: Floor "{tostring(Floor)}" was already wrote while parsing`)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if Split[3] == "Up" then
|
if FloorHint == "Up" then
|
||||||
Lanterns.Up = {
|
Lanterns.Up = {
|
||||||
Inst = Inst :: BasePart,
|
Inst = Inst :: BasePart,
|
||||||
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
|
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
|
||||||
Played = false
|
Played = false
|
||||||
}
|
}
|
||||||
elseif Split[3] == "Down" then
|
elseif FloorHint == "Down" then
|
||||||
Lanterns.Down = {
|
Lanterns.Down = {
|
||||||
Inst = Inst :: BasePart,
|
Inst = Inst :: BasePart,
|
||||||
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
|
Light = (Inst :: BasePart).Parent:FindFirstChild("Light") :: BasePart?,
|
||||||
Played = false
|
Played = false
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {Split[3]}`)
|
warn(`Lanterns: Unknown type paired with "DirectionIndicator", {FloorHint}`)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -124,8 +140,10 @@ function TagService:Buttons(ElevatorModel)
|
|||||||
|
|
||||||
for TagName: string, Inst: TagProduct in self.ExportedTags do
|
for TagName: string, Inst: TagProduct in self.ExportedTags do
|
||||||
local Split = TagName:split('_')
|
local Split = TagName:split('_')
|
||||||
|
local ModelHint = Split[1]
|
||||||
|
local ButtonHint = Split[2]
|
||||||
|
|
||||||
if Split[1] == ElevatorModel and (Split[2] == "ElevatorButton" or Split[2] == "RelayButton") then
|
if ModelHint == ElevatorModel and (ButtonHint == "ElevatorButton" or ButtonHint == "RelayButton") then
|
||||||
if typeof(Inst) == "Instance" then
|
if typeof(Inst) == "Instance" then
|
||||||
Buttons[TagName] = Inst
|
Buttons[TagName] = Inst
|
||||||
else
|
else
|
||||||
@@ -138,7 +156,49 @@ function TagService:Buttons(ElevatorModel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function TagService:Interactables()
|
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 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.Parent = Switch
|
||||||
|
local Prompt = Instance.new("ProximityPrompt")
|
||||||
|
Prompt.MaxActivationDistance = TagService.DefaultMaxLightSwitchActivationDistance
|
||||||
|
Prompt.HoldDuration = TagService.DefaultMaxLightSwitchHoldDuration
|
||||||
|
Prompt.Parent = Attachment
|
||||||
|
|
||||||
|
Interactables.LightSwitches[InteractObjectLocation].Switch = Switch
|
||||||
|
Interactables.LightSwitches[InteractObjectLocation].Prompt = Prompt
|
||||||
|
elseif InteractType == Enums.Interactables.Light then
|
||||||
|
local p = Interactables.LightSwitches[InteractObjectLocation]
|
||||||
|
|
||||||
|
if type(Inst) == "table" then
|
||||||
|
p.Lights = table.clone(Inst)
|
||||||
|
else
|
||||||
|
p.Lights = {}
|
||||||
|
table.insert(p.Lights :: {Instance}, Inst)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Interactables
|
||||||
end
|
end
|
||||||
|
|
||||||
return TagService
|
return TagService
|
||||||
@@ -2,13 +2,18 @@
|
|||||||
--!native
|
--!native
|
||||||
--!strict
|
--!strict
|
||||||
|
|
||||||
|
|
||||||
local Enums = {}
|
local Enums = {}
|
||||||
|
|
||||||
export type EnumValue = EnumButton | EnumButtonTree | EnumElevator
|
export type EnumValue = EnumButton | EnumButtonTree | EnumElevator | EnumInteractables
|
||||||
export type EnumButton = typeof(Enums.Button)
|
export type EnumButton = typeof(Enums.Button)
|
||||||
export type EnumButtonTree = typeof(Enums.ButtonTree)
|
export type EnumButtonTree = typeof(Enums.ButtonTree)
|
||||||
export type EnumElevator = typeof(Enums.Elevator)
|
export type EnumElevator = typeof(Enums.Elevator)
|
||||||
|
export type EnumInteractables = typeof(Enums.Interactables)
|
||||||
|
|
||||||
|
export type ButtonValues = typeof(Enums.Button.Car) |
|
||||||
|
typeof(Enums.Button.Landing) |
|
||||||
|
typeof(Enums.Button.Special) |
|
||||||
|
typeof(Enums.Button.Relay)
|
||||||
|
|
||||||
export type ButtonTreeValues = typeof(Enums.ButtonTree.Car) |
|
export type ButtonTreeValues = typeof(Enums.ButtonTree.Car) |
|
||||||
typeof(Enums.ButtonTree.Landing) |
|
typeof(Enums.ButtonTree.Landing) |
|
||||||
@@ -16,6 +21,9 @@ export type ButtonTreeValues = typeof(Enums.ButtonTree.Car) |
|
|||||||
typeof(Enums.ButtonTree.Relays) |
|
typeof(Enums.ButtonTree.Relays) |
|
||||||
typeof(Enums.ButtonTree.Unknown)
|
typeof(Enums.ButtonTree.Unknown)
|
||||||
|
|
||||||
|
export type InteractablesValues = typeof(Enums.Interactables.LightSwitch) |
|
||||||
|
typeof(Enums.Interactables.Light)
|
||||||
|
|
||||||
export type ElevatorValues = typeof(Enums.Elevator.Otis1960)
|
export type ElevatorValues = typeof(Enums.Elevator.Otis1960)
|
||||||
|
|
||||||
Enums.Button = {
|
Enums.Button = {
|
||||||
@@ -37,4 +45,9 @@ Enums.Elevator = {
|
|||||||
Otis1960 = "Otis1960" :: "Otis1960"
|
Otis1960 = "Otis1960" :: "Otis1960"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Enums.Interactables = {
|
||||||
|
LightSwitch = "LightSwitch" :: "LightSwitch",
|
||||||
|
Light = "Light" :: "Light"
|
||||||
|
}
|
||||||
|
|
||||||
return Enums
|
return Enums
|
||||||
Reference in New Issue
Block a user