Move files and folders to new repo format to enable multi-project format
This commit is contained in:
85
Zennysoft.Game.Ma/src/data_viewer/DataViewer.cs
Normal file
85
Zennysoft.Game.Ma/src/data_viewer/DataViewer.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
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.RotateModel(_currentModel.Basis, CameraPivot.Basis.Z, 0.75f, 0.5f, false);
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.Attack))
|
||||
{
|
||||
_currentModel.PlayPrimaryAttackAnimation();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user