mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2026-02-03 19:46:49 +00:00
relay work and source map
This commit is contained in:
@@ -5,24 +5,23 @@
|
||||
local Elevators = script.Parent
|
||||
|
||||
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
|
||||
type GetButtons = {[string]: Instance}
|
||||
type ButtonTree = {
|
||||
Inst: Instance,
|
||||
Prompt: ProximityPrompt
|
||||
type ButtonProperties = {
|
||||
Inst: Instance?,
|
||||
Prompt: ProximityPrompt?
|
||||
}
|
||||
type ButtonsTree = {
|
||||
Landing: ButtonTree,
|
||||
Car: ButtonTree,
|
||||
Special: ButtonTree,
|
||||
Unknown: {
|
||||
Inst: Instance,
|
||||
Prompt: ProximityPrompt?
|
||||
}
|
||||
Landing: ButtonProperties,
|
||||
Car: ButtonProperties,
|
||||
Special: ButtonProperties,
|
||||
Relays: ButtonProperties,
|
||||
Unknown: ButtonProperties
|
||||
}
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
@@ -42,25 +41,24 @@ type Impl_Static_Props = {
|
||||
type Constructor_Fun = (Tags: Tags, Model: string) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
Model: string
|
||||
}
|
||||
|
||||
export type ButtonsEnum = {
|
||||
Car: string,
|
||||
Landing: string,
|
||||
Special: string,
|
||||
Unknown: string
|
||||
Model: string,
|
||||
Buttons: ButtonsTree
|
||||
}
|
||||
|
||||
local ButtonsModule = {} :: Impl_Constructor
|
||||
ButtonsModule.__index = ButtonsModule
|
||||
|
||||
local ButtonsEnum = Enums.ButtonsEnum
|
||||
|
||||
function ButtonsModule.constructor(Tags, Model)
|
||||
return setmetatable({
|
||||
Tags = Tags,
|
||||
Model = Model
|
||||
Model = Model,
|
||||
Buttons = {
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Relays = {},
|
||||
Unknown = {}
|
||||
}
|
||||
}, ButtonsModule)
|
||||
end
|
||||
|
||||
@@ -71,7 +69,7 @@ function ButtonsModule:Get()
|
||||
|
||||
for TagName: string, Inst: Instance | {Instance} in self.Tags do
|
||||
local Split = TagName:split('_')
|
||||
if Split[1] == self.Model and Split[2] == "ElevatorButton" then
|
||||
if Split[1] == self.Model and (Split[2] == "ElevatorButton" or Split[2] == "RelayButton") then
|
||||
if typeof(Inst) == "Instance" then
|
||||
Buttons[TagName] = Inst
|
||||
else
|
||||
@@ -82,15 +80,15 @@ function ButtonsModule:Get()
|
||||
return Buttons
|
||||
end
|
||||
|
||||
--[[
|
||||
CarButton = Model_ElevatorButton_1
|
||||
LandingButton = Model_ElevatorButton_Floor_1_Up
|
||||
SpecialButton = Model_ElevatorButton_Open
|
||||
RelayButton = Model_RelayButton_F1
|
||||
]]
|
||||
function ButtonsModule:CreatePromptButtons()
|
||||
local ModelButtons = self:Get()
|
||||
local Buttons = {
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Unknown = {}
|
||||
} :: ButtonsTree
|
||||
|
||||
|
||||
for TagName: string, Inst: Instance in ModelButtons do
|
||||
local Attachment = Instance.new("Attachment") :: Attachment
|
||||
Attachment.Parent = Inst
|
||||
@@ -98,56 +96,64 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Prompt.MaxActivationDistance = 3
|
||||
Prompt.Parent = Attachment
|
||||
|
||||
--CarButton = Model_ElevatorButton_1
|
||||
--LandingButton = Model_ElevatorButton_Floor_1_Up
|
||||
--SpecialButton = Model_ElevatorButton_Open
|
||||
local Split = TagName:split('_')
|
||||
local ButtonType = tonumber(Split[3]) and
|
||||
ButtonsEnum.Car
|
||||
or Split[3] == "Floor" and Split[4]:match('%d') and
|
||||
ButtonsEnum.Landing
|
||||
or Split[2] == "ElevatorButton" and
|
||||
ButtonsEnum.Special
|
||||
local ButtonType = if tonumber(Split[3]) then
|
||||
Enums.Buttons.Car
|
||||
elseif Split[3] == "Floor" and Split[4]:match('%d') then
|
||||
Enums.Buttons.Landing
|
||||
elseif Split[2] == "ElevatorButton" then
|
||||
Enums.Buttons.Special
|
||||
elseif Split[2] == "RelayButton" then
|
||||
Enums.Buttons.Relay
|
||||
else
|
||||
nil
|
||||
|
||||
ButtonsEnum:Match(ButtonType, {
|
||||
[ButtonsEnum.Car] = function()
|
||||
--ElevatorButton_1
|
||||
Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
end,
|
||||
if ButtonType == Enums.Buttons.Car then
|
||||
--ElevatorButton_1
|
||||
|
||||
[ButtonsEnum.Landing] = function()
|
||||
--ElevatorButton_Floor_1_Up
|
||||
Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
end,
|
||||
self.Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == Enums.Buttons.Landing then
|
||||
--ElevatorButton_Floor_1_Up
|
||||
|
||||
[ButtonsEnum.Special] = function()
|
||||
--ElevatorButton_Open
|
||||
Buttons.Special[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
end,
|
||||
self.Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[5])
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
elseif ButtonType == Enums.Buttons.Special then
|
||||
--ElevatorButton_Open
|
||||
|
||||
["_"] = function()
|
||||
warn(`{self.Model}: Door tag was present but couldnt specify its type for use "{TagName}"`)
|
||||
end
|
||||
})
|
||||
print(`{self.Model}: created a ProximityPrompt @ "{Inst:GetFullName()}"`)
|
||||
self.Buttons.Special[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
elseif ButtonType == Enums.Buttons.Relay then
|
||||
--RelayButton_F1
|
||||
|
||||
Attachment.Position-=Vector3.new(.1,.3,0)
|
||||
|
||||
self.Buttons.Relays[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt
|
||||
}
|
||||
Prompt.ActionText = `Relay {tostring(Split[3])}`
|
||||
Prompt.ObjectText = "Activate"
|
||||
else
|
||||
warn(`{self.Model}: Door tag was present but couldnt specify its type for use "{TagName}"`)
|
||||
end
|
||||
|
||||
print(`[{tostring(ButtonType)}] {self.Model}: created a ProximityPrompt @ "{Inst:GetFullName()}"`)
|
||||
end
|
||||
|
||||
return Buttons
|
||||
return self.Buttons
|
||||
end
|
||||
|
||||
function ButtonsModule:HookPromptButtonsGroup()
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Enum = require(RS:WaitForChild("Enum"))
|
||||
|
||||
local Enums = {}
|
||||
|
||||
Enums.ButtonsEnum = Enum.Create("Buttons", {
|
||||
Car = "CarButton",
|
||||
Enums.Buttons = {
|
||||
Car = "CarButton",
|
||||
Landing = "LandingButton",
|
||||
Special = "SpecialButton",
|
||||
})
|
||||
Relay = "RelayButton"
|
||||
}
|
||||
|
||||
Enums.Elevators = {
|
||||
Otis1960 = "Otis1960"
|
||||
}
|
||||
|
||||
return Enums
|
||||
@@ -41,6 +41,8 @@ type Constructor_Return_Props = {
|
||||
DoorClosingClick: Sound
|
||||
}
|
||||
|
||||
export type DoorConstructor = ClassConstructor
|
||||
|
||||
local Doors = {} :: Impl_Constructor
|
||||
Doors.__index = Doors
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ local TagsModule = require(RS:WaitForChild("Tags"))
|
||||
local Leveling = require(script:WaitForChild("Leveling"))
|
||||
local Doors = require(script:WaitForChild("Doors"))
|
||||
|
||||
local Enums = require(Elevators:WaitForChild("Enums"))
|
||||
local ElevatorMover = require(Elevators:WaitForChild("Mover"))
|
||||
local ButtonTags = require(Elevators:WaitForChild("Buttons"))
|
||||
|
||||
@@ -35,7 +36,7 @@ type Constructor_Return_Props = {
|
||||
BoxAttachment: Attachment,
|
||||
BoxAlignPosition: AlignPosition,
|
||||
BoxAlignOrientation: AlignOrientation,
|
||||
ElevatorDoors: BasePart,
|
||||
ElevatorDoors: Doors.DoorConstructor,
|
||||
}
|
||||
|
||||
local Otis1960 = {} :: Impl_Constructor
|
||||
@@ -54,7 +55,7 @@ function Otis1960.constructor(Tags)
|
||||
self.ElevatorDoors = Doors.constructor(self.ElevatorBox, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
|
||||
|
||||
--Buttons
|
||||
local Buttons = ButtonTags.constructor(Tags, "Otis1960")
|
||||
local Buttons = ButtonTags.constructor(Tags, Enums.Elevators.Otis1960)
|
||||
local Otis1960_Buttons = Buttons:CreatePromptButtons()
|
||||
|
||||
print("[DEBUG] Otis1960 Buttons=", Otis1960_Buttons)
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
type EnumValue = any
|
||||
type EnumName = string
|
||||
type MatchResult = any?
|
||||
|
||||
type MatchList_f = {[string]: (...any?) -> MatchResult}
|
||||
type Enums = {[EnumName]: EnumValue}
|
||||
|
||||
type EnumsMetadata = {
|
||||
__index: (self: EnumsMetadata, i: EnumName) -> EnumValue?,
|
||||
__newindex: (self: EnumsMetadata, i: EnumName, v: EnumValue) -> ()
|
||||
}
|
||||
|
||||
export type CustomEnums = {
|
||||
Enums: typeof(setmetatable({} :: Enums, {} :: EnumsMetadata))
|
||||
} & CustonEnumsFunctions
|
||||
|
||||
type CustonEnumsFunctions = {
|
||||
Create: <T>(Name: EnumName, EnumValue: T) -> T,
|
||||
Remove: (Name: EnumName) -> ()
|
||||
}
|
||||
|
||||
local CustomEnum = {} :: CustomEnums
|
||||
local EnumMeta = {} :: EnumsMetadata
|
||||
|
||||
function EnumMeta.__index(self, i)
|
||||
local get = rawget(self, i)
|
||||
if type(i) == "string" then
|
||||
return get
|
||||
end
|
||||
warn(`Enum: attempt to retrieve an unknown Enum "{i}".`, debug.traceback())
|
||||
return nil
|
||||
end
|
||||
|
||||
function EnumMeta.__newindex(self, i, v)
|
||||
local PossibleEnum = rawget(self, i)
|
||||
if not PossibleEnum then
|
||||
if type(i) == "string" then
|
||||
rawset(self, i, v)
|
||||
else
|
||||
error(`Enum: attempt to set an Enum but the requested name was not a string "{i}", type="{type(i)}".`, 2)
|
||||
end
|
||||
else
|
||||
error(`Enum: attempt to set an Enum but the name "{i}" is already registered.`, 2)
|
||||
end
|
||||
end
|
||||
|
||||
CustomEnum.Enums = setmetatable({}, EnumMeta)
|
||||
|
||||
local function EnumMethods(Enum)
|
||||
--Branch these out later
|
||||
function Enum:Match(Result: string, MatchList: MatchList_f): MatchResult
|
||||
local LastIndexName, LastIndexValue = next(MatchList)
|
||||
|
||||
for MatchEnumName: string, EnumFunc in MatchList do
|
||||
if MatchEnumName == Result then
|
||||
return type(EnumFunc) == "function" and EnumFunc() or EnumFunc
|
||||
elseif MatchEnumName == LastIndexName and LastIndexValue ~= nil and MatchList['_'] then
|
||||
return type(MatchList['_']) == "function" and MatchList['_']() or MatchList['_']
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function Enum:MatchOnThread(Result: string, MatchList: MatchList_f): (boolean, MatchResult)
|
||||
return coroutine.resume(coroutine.create(function()
|
||||
return self:Match(Result, MatchList)
|
||||
end))
|
||||
end
|
||||
end
|
||||
|
||||
function CustomEnum.Create(Name, EnumValue)
|
||||
CustomEnum.Enums[Name] = EnumValue
|
||||
|
||||
local Enum = CustomEnum.Enums[Name]
|
||||
EnumMethods(Enum)
|
||||
|
||||
return Enum
|
||||
end
|
||||
|
||||
function CustomEnum.Remove(Name)
|
||||
if CustomEnum.Enums[Name] then
|
||||
CustomEnum.Enums[Name] = nil
|
||||
else
|
||||
warn(`Enum: attempt to remove an Enum that does not exist "{Name}".`, debug.traceback())
|
||||
end
|
||||
end
|
||||
|
||||
return CustomEnum
|
||||
Reference in New Issue
Block a user