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

Commit

Permalink
Fixes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluviolithic committed Nov 24, 2023
1 parent 1608574 commit d036096
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/client/Jumpscare.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local jumpscareAnimations = {}
for _, jumpscare in jumpscares:GetChildren() do
table.insert(jumpscareAnimations, jumpscare.Enemy.Configuration.Anim)
end
ContentProvider:PreloadAsync(jumpscareAnimations)

task.spawn(ContentProvider.PreloadAsync, ContentProvider, jumpscareAnimations)

return 0
51 changes: 0 additions & 51 deletions src/client/State/Middleware.lua
Original file line number Diff line number Diff line change
@@ -1,60 +1,9 @@
local Players = game:GetService "Players"
local CollectionService = game:GetService "CollectionService"
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local player = Players.LocalPlayer
local Rodux = require(ReplicatedStorage.Common.lib.Rodux)
local selectors = require(ReplicatedStorage.Common.State.selectors)

local displayClientLogs = ReplicatedStorage.Config.Output.DisplayClientLogs.Value
local originalAnimationId

local function updateIdleAnimationMiddleware(nextDispatch, store)
return function(action)
if
action.playerName ~= player.Name
or (action.type ~= "switchPlayerEnemy" and action.type ~= "setCurrentPunchingBag")
then
nextDispatch(action)
return
end

if player.Character then
if action.enemy or action.currentPunchingBag then
if not originalAnimationId then
originalAnimationId = player.Character.Animate.idle.Animation1.AnimationId
end
local equippedWeapon = selectors.getEquippedWeapon(store:getState(), player.Name)
if
equippedWeapon
and not action.currentPunchingBag
and not CollectionService:HasTag(action.enemy, "Dummy")
then
player.Character.Animate.idle.Animation1.AnimationId =
ReplicatedStorage.CombatAnimations[equippedWeapon].Idle.AnimationId
player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
else
player.Character.Animate.idle.Animation1.AnimationId =
ReplicatedStorage.CombatAnimations.Fists.Idle.AnimationId
end
elseif originalAnimationId then
local humanoid = player.Character and player.Character:FindFirstChild "Humanoid"
if humanoid then
for _, animationTrack in player.Character.Humanoid.Animator:GetPlayingAnimationTracks() do
if animationTrack.Priority == Enum.AnimationPriority.Idle then
animationTrack:Stop()
end
end
end
player.Character.Animate.idle.Animation1.AnimationId = originalAnimationId
player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Landed)
end
end
nextDispatch(action)
end
end

return {
updateIdleAnimationMiddleware,
if displayClientLogs then Rodux.loggerMiddleware else nil,
}
13 changes: 13 additions & 0 deletions src/client/UI/Combat/CombatAnimationPreloader.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local ContentProvider = game:GetService "ContentProvider"
local ReplicatedStorage = game:GetService "ReplicatedStorage"

local animationsToPreload = {}
for _, animation in ReplicatedStorage.CombatAnimations:GetDescendants() do
if animation:IsA "Animation" then
table.insert(animationsToPreload, animation)
end
end

task.spawn(ContentProvider.PreloadAsync, ContentProvider, animationsToPreload)

return 0
14 changes: 14 additions & 0 deletions src/server/Combat/Enemies/ApplyPlayerAnimations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ return function(player, janitor)
local runAnimations = true

local currentIndex, animationTrack, animation = 0, nil, nil
local idleAnimation = combatAnimations[selectors.getEquippedWeapon(store:getState(), player.Name)].Idle
local animationInstances = animationUtilities.filterAndSortAnimationInstances(
combatAnimations[selectors.getEquippedWeapon(store:getState(), player.Name)]:GetChildren()
)

local loadedIdleAnimation = player.Character.Humanoid:LoadAnimation(idleAnimation)
loadedIdleAnimation.Priority = Enum.AnimationPriority.Idle

task.spawn(function()
while runAnimations do
currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex)
Expand All @@ -24,7 +28,12 @@ return function(player, janitor)
animationTrack:Play()
animationTrack.Stopped:Wait()
animationTrack:Destroy()

loadedIdleAnimation:Play()

task.wait(animationUtilities.getPlayerAttackSpeed(player))

loadedIdleAnimation:Stop()
end
end)

Expand All @@ -33,5 +42,10 @@ return function(player, janitor)
if animationTrack.IsPlaying then
animationTrack:Stop()
end
if loadedIdleAnimation.IsPlaying then
loadedIdleAnimation:Stop()
end
animationTrack:Destroy()
loadedIdleAnimation:Destroy()
end, true)
end

0 comments on commit d036096

Please sign in to comment.