From 3a84d5b85df914f154ca6be93192cec590553acb Mon Sep 17 00:00:00 2001 From: interpreterK Date: Tue, 19 Dec 2023 18:00:36 -0500 Subject: [PATCH] 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 --- default.project.json | 7 +++- .../Character/Client/HumanoidRootPart.lua | 21 +++++++++++ src/client/Character/Client/init.client.lua | 8 +++++ src/client/Character/Server/Humanoid.lua | 16 +++++++++ src/client/Character/Server/Shadows.lua | 36 +++++++++++++++++++ src/client/Character/Server/init.server.lua | 17 +++++++++ src/client/Player/Camera/init.lua | 19 ++++++++++ src/client/Player/CoreGuis.lua | 30 ++++++++++++++++ src/client/Player/Crosshair.lua | 33 +++++++++++++++++ src/client/Player/Mouse.lua | 13 +++++++ src/client/Player/init.client.lua | 15 ++++++++ src/server/Elevators/Otis1960/main.server.lua | 0 src/server/StudioEntities.server.lua | 33 +++++++++++++++++ src/shared/Client/KeyBinds.lua | 34 ++++++++++++++++++ 14 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 src/client/Character/Client/HumanoidRootPart.lua create mode 100644 src/client/Character/Client/init.client.lua create mode 100644 src/client/Character/Server/Humanoid.lua create mode 100644 src/client/Character/Server/Shadows.lua create mode 100644 src/client/Character/Server/init.server.lua create mode 100644 src/client/Player/Camera/init.lua create mode 100644 src/client/Player/CoreGuis.lua create mode 100644 src/client/Player/Crosshair.lua create mode 100644 src/client/Player/Mouse.lua create mode 100644 src/client/Player/init.client.lua create mode 100644 src/server/Elevators/Otis1960/main.server.lua create mode 100644 src/server/StudioEntities.server.lua create mode 100644 src/shared/Client/KeyBinds.lua diff --git a/default.project.json b/default.project.json index aa9d1a6..9aa6ab3 100644 --- a/default.project.json +++ b/default.project.json @@ -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" } diff --git a/src/client/Character/Client/HumanoidRootPart.lua b/src/client/Character/Client/HumanoidRootPart.lua new file mode 100644 index 0000000..3eee2e7 --- /dev/null +++ b/src/client/Character/Client/HumanoidRootPart.lua @@ -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 \ No newline at end of file diff --git a/src/client/Character/Client/init.client.lua b/src/client/Character/Client/init.client.lua new file mode 100644 index 0000000..aa7482f --- /dev/null +++ b/src/client/Character/Client/init.client.lua @@ -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() \ No newline at end of file diff --git a/src/client/Character/Server/Humanoid.lua b/src/client/Character/Server/Humanoid.lua new file mode 100644 index 0000000..f417ba8 --- /dev/null +++ b/src/client/Character/Server/Humanoid.lua @@ -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 \ No newline at end of file diff --git a/src/client/Character/Server/Shadows.lua b/src/client/Character/Server/Shadows.lua new file mode 100644 index 0000000..eebdf06 --- /dev/null +++ b/src/client/Character/Server/Shadows.lua @@ -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 \ No newline at end of file diff --git a/src/client/Character/Server/init.server.lua b/src/client/Character/Server/init.server.lua new file mode 100644 index 0000000..9914acd --- /dev/null +++ b/src/client/Character/Server/init.server.lua @@ -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) \ No newline at end of file diff --git a/src/client/Player/Camera/init.lua b/src/client/Player/Camera/init.lua new file mode 100644 index 0000000..d1229ef --- /dev/null +++ b/src/client/Player/Camera/init.lua @@ -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 \ No newline at end of file diff --git a/src/client/Player/CoreGuis.lua b/src/client/Player/CoreGuis.lua new file mode 100644 index 0000000..f252272 --- /dev/null +++ b/src/client/Player/CoreGuis.lua @@ -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 \ No newline at end of file diff --git a/src/client/Player/Crosshair.lua b/src/client/Player/Crosshair.lua new file mode 100644 index 0000000..36cf895 --- /dev/null +++ b/src/client/Player/Crosshair.lua @@ -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 \ No newline at end of file diff --git a/src/client/Player/Mouse.lua b/src/client/Player/Mouse.lua new file mode 100644 index 0000000..92e7963 --- /dev/null +++ b/src/client/Player/Mouse.lua @@ -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 \ No newline at end of file diff --git a/src/client/Player/init.client.lua b/src/client/Player/init.client.lua new file mode 100644 index 0000000..b7960bd --- /dev/null +++ b/src/client/Player/init.client.lua @@ -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() \ No newline at end of file diff --git a/src/server/Elevators/Otis1960/main.server.lua b/src/server/Elevators/Otis1960/main.server.lua new file mode 100644 index 0000000..e69de29 diff --git a/src/server/StudioEntities.server.lua b/src/server/StudioEntities.server.lua new file mode 100644 index 0000000..c0e1fd0 --- /dev/null +++ b/src/server/StudioEntities.server.lua @@ -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 \ No newline at end of file diff --git a/src/shared/Client/KeyBinds.lua b/src/shared/Client/KeyBinds.lua new file mode 100644 index 0000000..86f3a19 --- /dev/null +++ b/src/shared/Client/KeyBinds.lua @@ -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 \ No newline at end of file