Files
GameJamDungeon/Zennysoft.Game.Ma/src/data_viewer/DataViewer.cs
2025-10-06 02:13:05 -07:00

93 lines
3.2 KiB
C#

using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using System.Linq;
namespace Zennysoft.Game.Ma;
[Meta(typeof(IAutoNode))]
public partial class DataViewer : Control
{
public override void _Notification(int what) => this.Notify(what);
public IInstantiator Instantiator { get; set; } = default!;
[Export]
public float _cameraSpeed = 0.01f;
[Node] public Node3D CameraPivot { get; set; } = default!;
[Node] public Camera3D Camera3D { get; set; } = default!;
[Node] public Node3D ModelPivot { get; set; } = default!;
[Node] public DataViewerRepository DataViewerRepository { get; set; } = default!;
#region UI
[Node] public RichTextLabel EnemyName { get; set; } = default!;
[Node] public RichTextLabel Description { get; set; } = default!;
#endregion
private EnemyModelView2D _currentModel;
private int _modelIndex = 0;
public void Initialize()
{
Instantiator = new Instantiator(GetTree());
LoadModel();
}
public override void _Process(double delta)
{
if (Input.IsActionPressed(GameInputs.MoveLeft))
CameraPivot.RotateY(_cameraSpeed);
if (Input.IsActionPressed(GameInputs.MoveRight))
CameraPivot.RotateY(-_cameraSpeed);
if (Input.IsActionPressed(GameInputs.StrafeLeft))
Camera3D.Position = Camera3D.Position.MoveToward(CameraPivot.Position, (float)delta * 2f);
if (Input.IsActionPressed(GameInputs.StrafeRight))
Camera3D.Position = Camera3D.Position.MoveToward(CameraPivot.Position, -(float)delta * 2f);
Camera3D.Position = Camera3D.Position.Clamp(new Vector3(0, 0, 1), new Vector3(0, 0, 4));
ModelPivot.Rotation = ModelPivot.Rotation.Clamp(Mathf.DegToRad(-60), Mathf.DegToRad(60));
_currentModel.SetCurrentDirection(_currentModel.GlobalBasis, -CameraPivot.Basis.Z);
if (Input.IsActionJustPressed(GameInputs.Attack))
_currentModel.PlayPrimaryAttackAnimation();
if (Input.IsActionJustPressed(GameInputs.AltAttack))
_currentModel.PlaySecondaryAttackAnimation();
if (Input.IsActionJustPressed(GameInputs.Inventory))
_currentModel.PlayActivateAnimation();
if (Input.IsActionPressed(GameInputs.StrafeRight))
_currentModel.PlayWalkAnimation();
if (Input.IsActionJustReleased(GameInputs.StrafeRight))
_currentModel.PlayIdleAnimation();
if (Input.IsActionJustPressed(GameInputs.Next))
{
// Load next model
_currentModel.CallDeferred(MethodName.QueueFree);
_modelIndex = (_modelIndex + 1) % DataViewerRepository.ModelRepository.Count;
GD.Print(_modelIndex);
CallDeferred(MethodName.LoadModel);
}
if (Input.IsActionJustPressed(GameInputs.Previous))
{
// Load previous model
_currentModel.CallDeferred(MethodName.QueueFree);
_modelIndex = (_modelIndex - 1 < 0 ? DataViewerRepository.ModelRepository.Count : _modelIndex) - 1;
CallDeferred(MethodName.LoadModel);
}
}
private void LoadModel()
{
var modelScene = DataViewerRepository.ModelRepository.ElementAt(_modelIndex);
_currentModel = modelScene.Instantiate<EnemyModelView2D>();
ModelPivot.AddChild(_currentModel);
EnemyName.Text = _currentModel.EnemyLoreInfo.Name;
Description.Text = _currentModel.EnemyLoreInfo.Description;
}
}