New game file structure

Scratch making the framework/engine open source for now until i figure out a better file structure that will work with Rojo
This commit is contained in:
2023-12-19 18:00:36 -05:00
parent e95b377c4e
commit 3a84d5b85d
14 changed files with 281 additions and 1 deletions

View File

@@ -2,16 +2,21 @@
"name": "ElevatorGame",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$path": "src/shared"
},
"ServerScriptService": {
"$path": "src/server"
},
"StarterPlayer": {
"StarterPlayerScripts": {
"$path": "src/client/Player"
"Player": {
"$path": "src/client/Player"
}
},
"StarterCharacterScripts": {
"$path": "src/client/Character"
}

View File

@@ -0,0 +1,21 @@
local HumanoidRPSettings = {}
HumanoidRPSettings.__index = HumanoidRPSettings
function HumanoidRPSettings.constructor(HumanoidRootPart: BasePart)
return setmetatable({
HumanoidRootPart = HumanoidRootPart
}, HumanoidRPSettings)
end
function HumanoidRPSettings:DisableRobloxSounds()
local HRP_objects = self.HumanoidRootPart:GetChildren()
for i = 1, #HRP_objects do
local Object = HRP_objects[i]
if Object:IsA("Sound") then
Object.SoundId = "rbxassetid://0"
end
end
end
return HumanoidRPSettings

View File

@@ -0,0 +1,8 @@
local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart"))
local Character = script.Parent
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart)
HRPSettings:DisableRobloxSounds()

View File

@@ -0,0 +1,16 @@
local HumanoidModule = {}
HumanoidModule.__index = HumanoidModule
type WalkSpeed = number | nil
function HumanoidModule.constructor(Humanoid: Humanoid)
return setmetatable({
Humanoid = Humanoid
}, HumanoidModule)
end
function HumanoidModule:SetWalkSpeed(Speed: WalkSpeed)
self.Humanoid.WalkSpeed = Speed or 16
end
return HumanoidModule

View File

@@ -0,0 +1,36 @@
--This really should be only client
local Shadows = {}
Shadows.__index = Shadows
type Character = Model
function Shadows.constructor(Character: Character)
return setmetatable({
Character = Character
}, Shadows)
end
function Shadows:PartToggle(Instance: BasePart, CastingShadow: boolean)
if Instance:IsA("BasePart") then --not 100%, but im sure types are only in effect on the editor side
Instance.CastShadow = CastingShadow
end
end
local function CharacterShadows(self, enabled: boolean)
local CharacterDescendants = self.Character:GetDescendants()
for i = 1, #CharacterDescendants do
self:PartToggle(CharacterDescendants[i], enabled)
end
end
function Shadows:on()
CharacterShadows(self, true)
end
function Shadows:off()
CharacterShadows(self, false)
end
return Shadows

View File

@@ -0,0 +1,17 @@
local Character = script.Parent
local Shadows = require(script:WaitForChild("Shadows"))
local HumanoidModule = require(script:WaitForChild("Humanoid"))
local Humanoid = Character:WaitForChild("Humanoid")
local CharacterShadows = Shadows.constructor(Character)
local HumanoidSettings = HumanoidModule.constructor(Humanoid)
CharacterShadows:off() --I plan to have 2 player support and characters block a ton of light
HumanoidSettings:SetWalkSpeed(12)
Character.DescendantAdded:Connect(function(Instance)
task.wait() --Wait for the instance to properly replicate?
CharacterShadows:PartToggle(Instance, false)
end)

View File

@@ -0,0 +1,19 @@
local Camera = {
FOV = {
Default = 70,
Zoomed = 50
}
}
Camera.__index = Camera
function Camera.constructor(Player: Player)
return setmetatable({
Player = Player
}, Camera)
end
function Camera:LockFirstPerson()
self.Player.CameraMode = Enum.CameraMode.LockFirstPerson
end
return Camera

View File

@@ -0,0 +1,30 @@
local CoreGuis = {
IncludeReset = true --disable the reset button?
}
CoreGuis.__index = CoreGuis
local SG = game:GetService("StarterGui")
local function DisableReset(enabled: boolean)
--Roblox actually doesn't register this fast enough so we gotta resort to cringe tactics
repeat
local PossibleMemoryLeak = pcall(SG.SetCore, SG, "ResetButtonCallback", enabled)
task.wait()
until PossibleMemoryLeak
end
function CoreGuis:on()
SG:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
if CoreGuis.IncludeReset then
DisableReset(true)
end
end
function CoreGuis:off()
SG:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
if CoreGuis.IncludeReset then
DisableReset(false)
end
end
return CoreGuis

View File

@@ -0,0 +1,33 @@
local Crosshair = {
Icon = "rbxassetid://12643750723"
}
Crosshair.__index = Crosshair
--Use a custom crosshair so we can do effects to it
function Crosshair.constructor(Player: Player)
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.ResetOnSpawn = false
ScreenGui.Name = "Crosshair"
local CrosshairIcon = Instance.new("ImageLabel")
CrosshairIcon.AnchorPoint = Vector2.new(.5,.5)
CrosshairIcon.Position = UDim2.fromScale(.5,.5)
CrosshairIcon.Size = UDim2.fromScale(.4,.4)
CrosshairIcon.Image = Crosshair.Icon
CrosshairIcon.BackgroundTransparency = 1
CrosshairIcon.ScaleType = Enum.ScaleType.Fit
CrosshairIcon.Parent = ScreenGui
return setmetatable({
Player = Player,
ScreenGui = ScreenGui,
CrosshairIcon = CrosshairIcon
}, Crosshair)
end
function Crosshair:Spawn()
self.ScreenGui.Parent = self.Player:WaitForChild("PlayerGui")
end
return Crosshair

View File

@@ -0,0 +1,13 @@
local Mouse = {}
local UIS = game:GetService("UserInputService")
function Mouse:DisablePointer()
UIS.MouseIconEnabled = false
end
function Mouse:EnablePointer()
UIS.MouseIconEnabled = true
end
return Mouse

View File

@@ -0,0 +1,15 @@
local CoreGuis = require(script:WaitForChild("CoreGuis"))
local Mouse = require(script:WaitForChild("Mouse"))
local CameraSettings = require(script:WaitForChild("Camera"))
local Crosshair = require(script:WaitForChild("Crosshair"))
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Camera = CameraSettings.constructor(Player)
local CrosshairObject = Crosshair.constructor(Player)
CoreGuis:off()
Mouse:DisablePointer()
Camera:LockFirstPerson()
CrosshairObject:Spawn()

View File

@@ -0,0 +1,33 @@
--All debugging objects such as light source indicating objects will be turned invisible
local EntityDebug = game:GetService("RunService"):IsStudio()
-- local EntityDebug = false
local WorkspaceEnt = workspace:GetDescendants()
local function DisablePart(Part: BasePart)
Part.Transparency = 1
Part.CanCollide = false
Part.CastShadow = false
end
local SwitchEntities = {
["LightSource"] = function(Part: BasePart)
DisablePart(Part)
end,
["PulleyRopeContact"] = function(Part: BasePart)
DisablePart(Part)
end
}
if not EntityDebug then
for i = 1, #WorkspaceEnt do
local Item = WorkspaceEnt[i]
local Case = SwitchEntities[Item.Name]
if Case then
Case(Item)
else
-- SwitchEntities.default()
end
end
end

View File

@@ -0,0 +1,34 @@
local Binds = {}
Binds.__index = Binds
local BindsMap = {
Keys = {}
}
BindsMap.__index = BindsMap
local UIS = game:GetService("UserInputService")
function Binds.constructor() --Allow multiple bindings of the same keys, no overwrites
return setmetatable({}, BindsMap)
end
function BindsMap.new()
local InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
end
end)
local InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
end
end)
return setmetatable({
InputBegan = InputBegan,
InputEnded = InputEnded
}, BindsMap)
end
return Binds