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

Commit

Permalink
Closes #96
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Dec 2, 2023
1 parent 0017979 commit 5dc6a10
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 114 deletions.
15 changes: 5 additions & 10 deletions src/client/Areas/Barriers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ local ReplicatedStorage = game:GetService "ReplicatedStorage"
local CollectionService = game:GetService "CollectionService"

local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.State.PlayerStatePromise)
local teleportPlayer = require(StarterPlayer.StarterPlayerScripts.Client.Areas.TeleportPlayer)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local selectors = require(ReplicatedStorage.Common.State.selectors)
local petUtils = require(ReplicatedStorage.Common.Utils.Player.PetUtils)
local selectors = require(ReplicatedStorage.Common.State.selectors)

local debounce = false
local player = Players.LocalPlayer
Expand Down Expand Up @@ -48,10 +49,10 @@ local function handleTeleporter(teleporter)
local strengthRequirement = areaRequirements[teleporter.Name:sub(1, -4)].Value

teleporter.Touched:Connect(function(hit)
local goal = teleporters[teleporter.Name:gsub("%d", opposite)]
local target = teleporters[teleporter.Name:gsub("%d", opposite)]
local hitPlayer = Players:GetPlayerFromCharacter(hit.Parent)

if not hitPlayer or hitPlayer ~= player or not goal then
if not hitPlayer or hitPlayer ~= player or not target then
return
end

Expand All @@ -64,13 +65,7 @@ local function handleTeleporter(teleporter)
end
debounce = true

player.Character:PivotTo(
CFrame.fromMatrix(
goal.Position + goal.CFrame.LookVector * 5 + goal.CFrame.UpVector * 5,
goal.CFrame.RightVector,
goal.CFrame.UpVector
)
)
teleportPlayer(player, { target = target })

petUtils.instantiatePets(player.Name, selectors.getEquippedPets(store:getState(), player.Name))

Expand Down
38 changes: 0 additions & 38 deletions src/client/Areas/ConfirmationUI.lua

This file was deleted.

21 changes: 21 additions & 0 deletions src/client/Areas/TeleportPlayer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local Dict = require(ReplicatedStorage.Common.lib.Sift).Dictionary

local defaultTeleportData = {
verticalOffset = 5,
horizontalOffset = 5,
}

return function(player, teleportData)
teleportData = Dict.merge(defaultTeleportData, teleportData)
player.Character:PivotTo(
CFrame.fromMatrix(
teleportData.target.Position
+ teleportData.target.CFrame.LookVector * teleportData.horizontalOffset
+ teleportData.target.CFrame.UpVector * teleportData.verticalOffset,
teleportData.target.CFrame.RightVector,
teleportData.target.CFrame.UpVector
)
)
end
51 changes: 25 additions & 26 deletions src/client/Areas/TeleportUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ local ReplicatedStorage = game:GetService "ReplicatedStorage"
local MarketplaceService = game:GetService "MarketplaceService"

local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.State.PlayerStatePromise)
local confirmationUI = require(StarterPlayer.StarterPlayerScripts.Client.Areas.ConfirmationUI)
local teleportPlayer = require(StarterPlayer.StarterPlayerScripts.Client.Areas.TeleportPlayer)
local interfaces = require(StarterPlayer.StarterPlayerScripts.Client.UI.CollidableInterfaces)
local confirmationUI = require(StarterPlayer.StarterPlayerScripts.Client.UI.ConfirmationUI)
local CentralUI = require(StarterPlayer.StarterPlayerScripts.Client.UI.CentralUI)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local selectors = require(ReplicatedStorage.Common.State.selectors)
Expand All @@ -20,6 +21,8 @@ local player = Players.LocalPlayer

local mainUI = player.PlayerGui:WaitForChild "MainUI"
local TeleportUI = CentralUI.new(player.PlayerGui:WaitForChild "Teleport")
local confirmationUIInstance = player.PlayerGui:WaitForChild("Teleport").Confirmation
local afkConfirmationUIInstance = mainUI.AFK.Confirmation

local function getAreaTeleporter(areaName: string): Instance?
for _, teleporter in CollectionService:GetTagged "AreaTeleport" do
Expand Down Expand Up @@ -74,25 +77,21 @@ function TeleportUI:_initialize()
mainUI.AFK.Activated:Connect(function()
local primarySoundArea = selectors.getAudioData(store:getState(), player.Name).PrimarySoundRegion
local purchasedTeleporters = selectors.getPurchasedTeleporters(store:getState(), player.Name)
local goal, targetAreaName = nil, nil
local target, targetAreaName = nil, nil

if areaRequirements["Howling Woods"].Value <= selectors.getStat(store:getState(), player.Name, "Strength") then
targetAreaName = "Howling Woods"
goal = workspace.Teleports.AFK2TP
target = workspace.Teleports.AFK2TP
else
targetAreaName = "Clown Town"
goal = workspace.Teleports.AFK1TP
target = workspace.Teleports.AFK1TP
end

if purchasedTeleporters[targetAreaName] or primarySoundArea == targetAreaName then
player.Character:PivotTo(
CFrame.fromMatrix(
goal.Position + goal.CFrame.LookVector * 5 + goal.CFrame.UpVector * 5,
goal.CFrame.RightVector,
goal.CFrame.UpVector
)
)
petUtils.instantiatePets(player.Name, selectors.getEquippedPets(store:getState(), player.Name))
confirmationUI(afkConfirmationUIInstance, "", function()
teleportPlayer(player, { target = target })
petUtils.instantiatePets(player.Name, selectors.getEquippedPets(store:getState(), player.Name))
end)
else
self:setEnabled(true)
end
Expand Down Expand Up @@ -122,25 +121,25 @@ function TeleportUI:_initialize()
if confirmationJanitor and confirmationJanitor.Destroy then
confirmationJanitor:Destroy()
end
confirmationJanitor = confirmationUI({
AreaName = area.Name,
Cost = if hasFreeTeleporters then 0 else area.Cost.Value,
}, function()
Remotes.Client:Get("PurchaseTeleporter"):SendToServer(area.Name)
end)
confirmationJanitor = confirmationUI(
confirmationUIInstance,
string.format(
'Unlock the %s teleport for <font color="rgb(224, 18, 231)">%s Gems</font>?',
area.Name,
if hasFreeTeleporters then 0 else area.Cost.Value
),
function()
Remotes.Client:Get("PurchaseTeleporter"):SendToServer(area.Name)
end
)
return
end
if not player.Character or not player.Character:FindFirstChild "HumanoidRootPart" then
return
end
local goal = getAreaTeleporter(area.Name)
player.Character:PivotTo(
CFrame.fromMatrix(
goal.Position + goal.CFrame.LookVector * 5 + goal.CFrame.UpVector * 5,
goal.CFrame.RightVector,
goal.CFrame.UpVector
)
)
teleportPlayer(player, {
target = getAreaTeleporter(area.Name),
})
petUtils.instantiatePets(player.Name, selectors.getEquippedPets(store:getState(), player.Name))
end)
end
Expand Down
32 changes: 17 additions & 15 deletions src/client/UI/ConfirmationUI.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
local Players = game:GetService "Players"
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local PlayerGui = Players.LocalPlayer:WaitForChild "PlayerGui"
local confirmationUI = PlayerGui:WaitForChild("PetInventory").Confirmation
local Janitor = require(ReplicatedStorage.Common.lib.Janitor)

local contextMessages = {
UnequipAll = "Are you sure you want to Unequip All Pets?",
EquipBest = "Are you sure you want to Equip Your Best Pets?",
EvolveAll = "Are you sure you want to Evolve All Pets?",
DeleteAll = "Delete All Pets? Make sure all the pets you want to keep are Locked.",
}

--TODO: Set up to be a promise so don't have to yield for player gui
--TODO: components to be loaded in.
return function(context, callback)
return function(confirmationUI, message, callback)
local destructor = Janitor.new()
confirmationUI.Visible = true
confirmationUI.WarningText.Text = contextMessages[context]

if #message > 0 then
confirmationUI.WarningText.Text = message
end

destructor:Add(
confirmationUI.GreenButton.Activated:Connect(function()
confirmationUI.Confirm.Activated:Connect(function()
confirmationUI.Visible = false
destructor:Cleanup()
callback()
Expand All @@ -36,5 +27,16 @@ return function(context, callback)
"Disconnect"
)

local cancel = confirmationUI:FindFirstChild "Cancel"
if cancel then
destructor:Add(
confirmationUI.Cancel.Activated:Connect(function()
confirmationUI.Visible = false
destructor:Cleanup()
end),
"Disconnect"
)
end

return destructor
end
49 changes: 33 additions & 16 deletions src/client/UI/Inventories/PetInventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local playerStatePromise = require(StarterPlayer.StarterPlayerScripts.Client.Sta
local interfaces = require(StarterPlayer.StarterPlayerScripts.Client.UI.CollidableInterfaces)

local PetInventory = CentralUI.new(player.PlayerGui:WaitForChild "PetInventory")
local confirmationUIInstance = player.PlayerGui:WaitForChild("PetInventory").Confirmation
local rarityTemplates = ReplicatedStorage.RarityTemplates
local gamepassIDs = ReplicatedStorage.Config.GamepassData.IDs

Expand Down Expand Up @@ -76,40 +77,56 @@ function PetInventory:_initialize(): ()
if self._confirmationDestructor then
self._confirmationDestructor:Cleanup()
end
self._confirmationDestructor = confirmationUI("UnequipAll", function()
Remotes.Client:Get("UnequipAllPets"):SendToServer()
self:_clearFocusedDisplay()
end)
self._confirmationDestructor = confirmationUI(
confirmationUIInstance,
"Are you sure you want to Unequip All Pets?",
function()
Remotes.Client:Get("UnequipAllPets"):SendToServer()
self:_clearFocusedDisplay()
end
)
end)

self._ui.Background.EquipBest.Activated:Connect(function()
if self._confirmationDestructor then
self._confirmationDestructor:Cleanup()
end
self._confirmationDestructor = confirmationUI("EquipBest", function()
Remotes.Client:Get("EquipBestPets"):SendToServer()
self:_clearFocusedDisplay()
end)
self._confirmationDestructor = confirmationUI(
confirmationUIInstance,
"Are you sure you want to Equip Your Best Pets?",
function()
Remotes.Client:Get("EquipBestPets"):SendToServer()
self:_clearFocusedDisplay()
end
)
end)

self._ui.Background.EvolveAll.Activated:Connect(function()
if self._confirmationDestructor then
self._confirmationDestructor:Cleanup()
end
self._confirmationDestructor = confirmationUI("EvolveAll", function()
Remotes.Client:Get("EvolveAllPets"):SendToServer()
self:_clearFocusedDisplay()
end)
self._confirmationDestructor = confirmationUI(
confirmationUIInstance,
"Are you sure you want to Evolve All Pets?",
function()
Remotes.Client:Get("EvolveAllPets"):SendToServer()
self:_clearFocusedDisplay()
end
)
end)

self._ui.Background.DeleteAll.Activated:Connect(function()
if self._confirmationDestructor then
self._confirmationDestructor:Cleanup()
end
self._confirmationDestructor = confirmationUI("DeleteAll", function()
Remotes.Client:Get("DeleteAllPets"):SendToServer()
self:_clearFocusedDisplay()
end)
self._confirmationDestructor = confirmationUI(
confirmationUIInstance,
"Delete All Pets? Make sure all the pets you want to keep are Locked.",
function()
Remotes.Client:Get("DeleteAllPets"):SendToServer()
self:_clearFocusedDisplay()
end
)
end)

playerStatePromise:andThen(function()
Expand Down
16 changes: 7 additions & 9 deletions src/client/UI/Shops/WeaponShop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ local petUtils = require(ReplicatedStorage.Common.Utils.Player.PetUtils)
local store = require(StarterPlayer.StarterPlayerScripts.Client.State.Store)
local CentralUI = require(StarterPlayer.StarterPlayerScripts.Client.UI.CentralUI)
local teleportUI = require(StarterPlayer.StarterPlayerScripts.Client.Areas.TeleportUI)
local confirmationUI = require(StarterPlayer.StarterPlayerScripts.Client.UI.ConfirmationUI)
local teleportPlayer = require(StarterPlayer.StarterPlayerScripts.Client.Areas.TeleportPlayer)

local weapons = ReplicatedStorage.Weapons
local gamepassIDs = ReplicatedStorage.Config.GamepassData.IDs
local gamepassPrices = ReplicatedStorage.Config.GamepassData.Prices
local WeaponShop = CentralUI.new(player.PlayerGui:WaitForChild "WeaponShop")
local mainUI = player.PlayerGui:WaitForChild "MainUI"
local confirmationUIInstance = mainUI.WeaponShop.Confirmation

WeaponShop.Trigger = "WeaponShop"
WeaponShop._itemButtons = WeaponShop._ui.LeftBackground.ScrollingFrame:GetChildren()
Expand All @@ -44,15 +47,10 @@ function WeaponShop:_initialize(): ()
local purchasedTeleporters = selectors.getPurchasedTeleporters(store:getState(), player.Name)

if purchasedTeleporters["Clown Town"] or primarySoundArea == "Clown Town" then
local goal = workspace.Teleports.WeaponShopTP
player.Character:PivotTo(
CFrame.fromMatrix(
goal.Position + goal.CFrame.LookVector * 5 + goal.CFrame.UpVector * 5,
goal.CFrame.RightVector,
goal.CFrame.UpVector
)
)
petUtils.instantiatePets(player.Name, selectors.getEquippedPets(store:getState(), player.Name))
confirmationUI(confirmationUIInstance, "", function()
teleportPlayer(player, { target = workspace.Teleports.WeaponShopTP })
petUtils.instantiatePets(player.Name, selectors.getEquippedPets(store:getState(), player.Name))
end)
else
teleportUI:setEnabled(true)
end
Expand Down

0 comments on commit 5dc6a10

Please sign in to comment.