Swap models
This commit is contained in:
@@ -3,6 +3,8 @@ using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class DataViewer : Control
|
||||
@@ -20,11 +22,16 @@ public partial class DataViewer : Control
|
||||
|
||||
[Node] public Node3D ModelPivot { get; set; } = default!;
|
||||
|
||||
[Node] public Label RotationLabel { get; set; } = default!;
|
||||
[Node] public DataViewerRepository DataViewerRepository { get; set; } = default!;
|
||||
|
||||
private EnemyModelView _currentModel;
|
||||
|
||||
private int _modelIndex = 0;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
LoadModel();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
@@ -44,18 +51,34 @@ public partial class DataViewer : Control
|
||||
|
||||
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);
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.Interact))
|
||||
if (Input.IsActionJustPressed(GameInputs.Attack))
|
||||
{
|
||||
// do nothing
|
||||
_currentModel.PlayAttackAnimation();
|
||||
}
|
||||
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;
|
||||
GD.Print(_modelIndex);
|
||||
CallDeferred(MethodName.LoadModel);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadModel()
|
||||
{
|
||||
var modelScene = DataViewerRepository.ModelRepository.ElementAt(_modelIndex);
|
||||
_currentModel = modelScene.Instantiate<EnemyModelView>();
|
||||
ModelPivot.AddChild(_currentModel);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -6,5 +6,5 @@ using Godot;
|
||||
public partial class DataViewerRepository : Node
|
||||
{
|
||||
[Export]
|
||||
private Godot.Collections.Array<PackedScene> _modelsToDisplay;
|
||||
public Godot.Collections.Array<PackedScene> ModelRepository;
|
||||
}
|
||||
Reference in New Issue
Block a user