Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Finish hooking up settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Nov 28, 2023
1 parent 861b949 commit d6df327
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/client/Areas/Barriers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ playerStatePromise:andThen(function()
end)

CollectionService:GetInstanceAddedSignal("TP"):Connect(handleTeleporter)
for _, teleporter in pairs(CollectionService:GetTagged "TP") do
for _, teleporter in CollectionService:GetTagged "TP" do
handleTeleporter(teleporter)
end

Expand Down
27 changes: 27 additions & 0 deletions src/client/GameAtmosphere/Lighting.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local Players = game:GetService "Players"
local Lighting = game:GetService "Lighting"
local StarterPlayer = game:GetService "StarterPlayer"
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local selectors = require(ReplicatedStorage.Common.State.selectors)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.State.PlayerStatePromise)

local playerName = Players.LocalPlayer.Name

local function updateLighting(setting)
if Lighting.BrightMode.Enabled == setting then
return
end
Lighting.BrightMode.Enabled = setting
end

playerStatePromise:andThen(function()
updateLighting(selectors.getSetting(store:getState(), playerName, "BrightMode"))

store.changed:connect(function(newState)
updateLighting(selectors.getSetting(newState, playerName, "BrightMode"))
end)
end)

return 0
19 changes: 17 additions & 2 deletions src/client/GameAtmosphere/Soundscape/SoundInstanceHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ local volumeKnobs = {
off = {},
}

local switches = {
play = {},
pause = {},
}

local function createKnob(soundInstance, on)
return TweenService:Create(
soundInstance,
Expand Down Expand Up @@ -46,6 +51,17 @@ for _, playlistFolder in playlists:GetChildren() do
volumeKnobs.on[playlistFolder.Name] = createKnob(nextAudioInstance, true)
volumeKnobs.off[playlistFolder.Name] = createKnob(nextAudioInstance, false)

switches.play[playlistFolder.Name] = function()
nextAudioInstance:Play()
end
switches.pause[playlistFolder.Name] = function()
nextAudioInstance:Pause()
end

volumeKnobs.off[playlistFolder.Name].Completed:Connect(function()
switches.pause[playlistFolder.Name]()
end)

if
not selectors.isPlayerLoaded(store:getState(), player.Name)
or selectors.getAudioData(store:getState(), player.Name).PrimarySoundRegion
Expand All @@ -56,11 +72,10 @@ for _, playlistFolder in playlists:GetChildren() do

nextAudioInstance.Name = playlistFolder.Name
nextAudioInstance.Parent = soundFolder
nextAudioInstance:Play()
nextAudioInstance.Ended:Wait()
end
end
end)
end

return volumeKnobs
return { volumeKnobs, switches }
8 changes: 7 additions & 1 deletion src/client/GameAtmosphere/Soundscape/SoundSystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ local ReplicatedStorage = game:GetService "ReplicatedStorage"

local selectors = require(ReplicatedStorage.Common.State.selectors)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local volumeKnobs = require(StarterPlayer.StarterPlayerScripts.Client.GameAtmosphere.Soundscape.SoundInstanceHandler)
local volumeKnobs, switches =
table.unpack(require(StarterPlayer.StarterPlayerScripts.Client.GameAtmosphere.Soundscape.SoundInstanceHandler))

local player = Players.LocalPlayer

store.changed:connect(function(newState, oldState)
local oldPrimarySoundRegion = selectors.getAudioData(oldState, player.Name).PrimarySoundRegion
local newPrimarySoundRegion = selectors.getAudioData(newState, player.Name).PrimarySoundRegion

if not selectors.getSetting(newState, player.Name, "BackgroundMusic") then
newPrimarySoundRegion = nil
end

if oldPrimarySoundRegion ~= newPrimarySoundRegion then
if newPrimarySoundRegion then
if oldPrimarySoundRegion then
volumeKnobs.off[oldPrimarySoundRegion]:Play()
end
switches.play[newPrimarySoundRegion]()
volumeKnobs.on[newPrimarySoundRegion]:Play()
else
volumeKnobs.on[oldPrimarySoundRegion]:Cancel()
Expand Down
11 changes: 10 additions & 1 deletion src/client/Jumpscare.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ playerStatePromise:andThen(function()
if selectors.getCurrentTarget(newState, player.Name) then
lastEnemyFought = selectors.getCurrentTarget(newState, player.Name)
end
if isScared(newState) and not isScared(oldState) and (os.time() - lastJumpscared) > jumpscareGap then
if
isScared(newState)
and not isScared(oldState)
and ((os.time() - lastJumpscared) > jumpscareGap or not selectors.getSetting(
newState,
player.Name,
"JumpscareCooldown"
))
and selectors.getSetting(newState, player.Name, "Jumpscares")
then
jumpscarePlayer(if lastEnemyFought then lastEnemyFought.Name else "Evil Clown")
end
end)
Expand Down
85 changes: 85 additions & 0 deletions src/client/Pets.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
-- script to make pets invisible based on setting

local Players = game:GetService "Players"
local StarterPlayer = game:GetService "StarterPlayer"
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local selectors = require(ReplicatedStorage.Common.State.selectors)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.State.PlayerStatePromise)

local petsFolder = workspace.PetModels
local playerName = Players.LocalPlayer.Name

local function setPetEnabled(pet, enabled)
pet.PetUI.Enabled = enabled
for _, part in pet:GetChildren() do
if part:IsA "BasePart" then
part.Transparency = if enabled then 0 else 1
end
end
end

local function updateMyPets(show)
for _, playerPetFolder in petsFolder:GetChildren() do
if playerPetFolder.Name ~= playerName then
continue
end

for _, pet in playerPetFolder:GetChildren() do
setPetEnabled(pet, show)
end
end
end

local function updateOtherPets(show)
for _, playerPetFolder in petsFolder:GetChildren() do
if playerPetFolder.Name == playerName then
continue
end

for _, pet in playerPetFolder:GetChildren() do
setPetEnabled(pet, show)
end
end
end

petsFolder.DescendantAdded:Connect(function(descendant)
if not descendant:FindFirstChild "PetUI" then
return
end

if descendant.Parent.Name == playerName then
if not selectors.getSetting(store:getState(), playerName, "ShowMyPets") then
setPetEnabled(descendant, false)
end
return
end

if not selectors.getSetting(store:getState(), descendant.Parent.Name, "ShowOtherPets") then
setPetEnabled(descendant, false)
end
end)

playerStatePromise:andThen(function()
updateMyPets(selectors.getSetting(store:getState(), playerName, "ShowMyPets"))
updateOtherPets(selectors.getSetting(store:getState(), playerName, "ShowOtherPets"))

store.changed:connect(function(newState, oldState)
if
selectors.getSetting(newState, playerName, "ShowMyPets")
~= selectors.getSetting(oldState, playerName, "ShowMyPets")
then
updateMyPets(selectors.getSetting(newState, playerName, "ShowMyPets"))
end

if
selectors.getSetting(newState, playerName, "ShowOtherPets")
~= selectors.getSetting(oldState, playerName, "ShowOtherPets")
then
updateOtherPets(selectors.getSetting(newState, playerName, "ShowOtherPets"))
end
end)
end)

return 0
2 changes: 1 addition & 1 deletion src/client/UI/Combat/PetAnimator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end):andThen(function(petsModel)
end

local numPets = #petsModel:GetChildren()
for i, petModel in ipairs(petsModel:GetChildren()) do
for i, petModel in petsModel:GetChildren() do
local position, look = petUtils.calculatePosition(rootPart, numPets, i)

petModel.PrimaryPart.BodyPosition.Position = position
Expand Down
2 changes: 1 addition & 1 deletion src/client/UI/Inventories/PetInventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function PetInventory:Refresh()
end

-- clear the inventory
for _, rarityTemplate in pairs(self._ui.Background.ScrollingFrame:GetChildren()) do
for _, rarityTemplate in self._ui.Background.ScrollingFrame:GetChildren() do
if rarityTemplate:IsA "ImageButton" then
rarityTemplate:Destroy()
end
Expand Down
14 changes: 12 additions & 2 deletions src/client/UI/SettingsUI.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
local Players = game:GetService "Players"
local StarterPlayer = game:GetService "StarterPlayer"
local ReplicatedStorage = game:GetService "ReplicatedStorage"
--local MarketplaceService = game:GetService "MarketplaceService"
local MarketplaceService = game:GetService "MarketplaceService"

local player = Players.LocalPlayer

local Remotes = require(ReplicatedStorage.Common.Remotes)
--local Table = require(ReplicatedStorage.Common.Utils.Table)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local CentralUI = require(StarterPlayer.StarterPlayerScripts.Client.UI.CentralUI)
local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.State.PlayerStatePromise)

local gamepassIDs = ReplicatedStorage.Config.GamepassData.IDs
local SettingsUI = CentralUI.new(player.PlayerGui:WaitForChild "Settings")

local function shouldRefresh(newState, oldState)
Expand All @@ -28,6 +28,16 @@ function SettingsUI:_initialize(): ()
Remotes.Client:Get("SwitchSetting"):SendToServer(settingSwitch.Name)
end)
settingSwitch.Off.Activated:Connect(function()
if settingSwitch.Name:match "Vip" and not selectors.hasGamepass(store:getState(), player.Name, "VIP") then
MarketplaceService:PromptGamePassPurchase(player, gamepassIDs.VIP.Value)
return
end
if
settingSwitch.Name:match "Speed" and not selectors.hasGamepass(store:getState(), player.Name, "Speed")
then
MarketplaceService:PromptGamePassPurchase(player, gamepassIDs["2xSpeed"].Value)
return
end
Remotes.Client:Get("SwitchSetting"):SendToServer(settingSwitch.Name)
end)
end
Expand Down
2 changes: 2 additions & 0 deletions src/client/init.client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ require(client.Controls)
require(client.Areas)
require(client.Jumpscare)
require(client.GameAtmosphere.Soundscape)
require(client.GameAtmosphere.Lighting)
require(client.ChatModifiersHandler)
require(client.Pets)
3 changes: 2 additions & 1 deletion src/server/Combat/FearEffects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ local walkSpeedFearDebuff = -4
store.changed:connect(function(newState, oldState)
for _, player in Players:GetPlayers() do
local hasPass = selectors.hasGamepass(newState, player.Name, "2xSpeed")
local doubleSpeedEnabled = selectors.getSetting(newState, player.Name, "2xSpeed")
local modifiedDebuff = walkSpeedFearDebuff * (hasPass and 2 or 1)
local newWalkSpeed = defaultWalkSpeed * (hasPass and 2 or 1)
local newWalkSpeed = defaultWalkSpeed * (hasPass and doubleSpeedEnabled and 2 or 1)
if isScared(player.Name, newState) then
task.spawn(trackPlayerScaredStatus, player)
newWalkSpeed += modifiedDebuff
Expand Down
7 changes: 6 additions & 1 deletion src/server/PlayerManager/PlayerStatusUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ function PlayerStatusUI:_updateUIFields(state)
playerUIFrame.Scared.Visible = selectors.getStat(state, self._player.Name, "CurrentFearMeter")
== selectors.getStat(state, self._player.Name, "MaxFearMeter")

if selectors.hasGamepass(state, self._player.Name, "VIP") then
if
selectors.hasGamepass(state, self._player.Name, "VIP")
and selectors.getSetting(state, self._player.Name, "VIPNameTag")
then
self._player:SetAttribute("isVIP", true)
playerUIFrame.PlayerName.TextColor3 = Color3.fromRGB(255, 193, 7)
else
self._player:SetAttribute("isVIP", false)
playerUIFrame.PlayerName.TextColor3 = Color3.fromRGB(255, 255, 255)
end
end
Expand Down
14 changes: 14 additions & 0 deletions src/server/PlayerManager/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ local ServerScriptService = game:GetService "ServerScriptService"
local Remotes = require(ReplicatedStorage.Common.Remotes)
local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local selectors = require(ReplicatedStorage.Common.State.selectors)

Remotes.Server:Get("SwitchSetting"):Connect(function(player, setting)
if type(selectors.getSetting(store:getState(), player.Name, setting)) ~= "boolean" then
return
end
-- check vip pass
if setting == "2xSpeed" then
if not selectors.hasGamepass(store:getState(), player.Name, "2xSpeed") then
return
end
elseif setting:match "Vip" then
if not selectors.hasGamepass(store:getState(), player.Name, "VIP") then
return
end
end
store:dispatch(actions.switchSetting(player.Name, setting))
end)

Expand Down
7 changes: 0 additions & 7 deletions src/server/PlayerManager/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local store = require(ServerScriptService.Server.State.Store)
local actions = require(ServerScriptService.Server.State.Actions)
local formatter = require(ReplicatedStorage.Common.Utils.Formatter)
local PlayerStatusUI = require(ServerScriptService.Server.PlayerManager.PlayerStatusUI)
local VIPGamepassID = ReplicatedStorage.Config.GamepassData.IDs.VIP.Value

local profileStore = ProfileService.GetProfileStore("PlayerData", profileTemplate)

Expand Down Expand Up @@ -66,12 +65,6 @@ local function onPlayerAdded(player: Player)
profiles[player.Name] = profile
store:dispatch(actions.addPlayer(player.Name, profile.Data))
store:dispatch(actions.incrementPlayerStat(player.Name, "LogInCount"))

if profile.Data.PurchaseData.AwardedGamepasses[VIPGamepassID] then
player:SetAttribute("isVIP", true)
else
player:SetAttribute("isVIP", false)
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ return {
store:dispatch(actions.equipWeapon(player.Name, "Hero Blade"))
store:dispatch(actions.incrementPlayerMultiplier(player.Name, "Training DummyFearMultiplier", 0.5))
store:dispatch(actions.incrementPlayerMultiplier(player.Name, "PunchingBagStrengthMultiplier", 0.2))
store:dispatch(actions.switchSetting(player.Name, "VIPNameTag"))
store:dispatch(actions.switchSetting(player.Name, "VIPChatTag"))
player:SetAttribute("isVIP", true)
end,
[IDs["50PetStorage"].Value] = function(player: Player)
Expand Down Expand Up @@ -62,6 +64,7 @@ return {
if humanoid then
humanoid.WalkSpeed *= 2
end
store:dispatch(actions.switchSetting(player.Name, "2xSpeed"))
end,
[IDs["3xHatch"].Value] = true,
[IDs["AutoHatch"].Value] = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return function(nextDispatch, store)
local leaderstats = player:FindFirstChild "leaderstats"

if leaderstats then
for _, stat in pairs(leaderstats:GetChildren()) do
for _, stat in leaderstats:GetChildren() do
stat.Value =
formatter.formatNumberWithSuffix(selectors.getStat(store:getState(), player.Name, stat.Name))
end
Expand Down
4 changes: 3 additions & 1 deletion src/shared/State/selectors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ return {
return state.SavedSettings[playerName]
end,
getSetting = function(state, playerName, setting)
return state.SavedSettings[playerName][setting] or state.TempSettings[playerName][setting]
return if type(state.SavedSettings[playerName][setting]) == "boolean"
then state.SavedSettings[playerName][setting]
else state.TempSettings[playerName][setting]
end,
getPurchasedBoosts = function(state, playerName)
return state.PurchaseData[playerName].PurchasedBoosts
Expand Down

0 comments on commit d6df327

Please sign in to comment.