Sync weapon equip to hitbox damage
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
@@ -52,16 +54,17 @@ namespace GameJamDungeon
|
||||
|
||||
public PlayerLogic.IBinding PlayerBinding { get; set; } = default!;
|
||||
|
||||
[Node]
|
||||
public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
[Node] public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
|
||||
[Node]
|
||||
public IAnimatedSprite2D SwordSlashAnimation { get; set; } = default!;
|
||||
[Node] public AnimatedSprite2D SwordSlashAnimation { get; set; } = default!;
|
||||
|
||||
[Node] public IHitbox Hitbox { get; set; } = default!;
|
||||
|
||||
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
@@ -77,20 +80,15 @@ namespace GameJamDungeon
|
||||
PlayerLogic.Set(GameRepo);
|
||||
PlayerLogic.Set(PlayerData);
|
||||
|
||||
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
|
||||
EquippedWeapon = new AutoProp<WeaponInfo>(WeaponInfo.Default);
|
||||
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
||||
}
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition)
|
||||
{
|
||||
GlobalPosition = globalPosition;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
PlayerBinding = PlayerLogic.Bind();
|
||||
|
||||
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
|
||||
|
||||
PlayerBinding
|
||||
.Handle((in PlayerLogic.Output.MovementComputed output) =>
|
||||
{
|
||||
@@ -104,9 +102,15 @@ namespace GameJamDungeon
|
||||
|
||||
this.Provide();
|
||||
PlayerLogic.Start();
|
||||
|
||||
EquippedWeapon.Sync += OnEquippedWeaponChanged;
|
||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||
}
|
||||
|
||||
public void OnReady() => SetPhysicsProcess(true);
|
||||
public void OnReady()
|
||||
{
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
@@ -145,5 +149,9 @@ namespace GameJamDungeon
|
||||
PlayerBinding.Dispose();
|
||||
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
||||
}
|
||||
|
||||
private void OnEquippedWeaponChanged(WeaponInfo info) => Hitbox.Damage = info.Damage;
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user