Add controllable lab walking checkpoint with collision and chase camera
This commit is contained in:
1 parent
37fa18094f
commit
58424120bb
26 files changed
+1848
-110
No files matched your search
@@ -1,11 +1,13 @@
|
||||
using GamePort.Assets;
|
||||
using GamePort.Game;
|
||||
|
||||
namespace GamePort.Application;
|
||||
|
||||
/// <summary>Explicit animation inspection; does not simulate player actions.</summary>
|
||||
/// <summary>Shared original clips for explicit inspection and simulation pose selection.</summary>
|
||||
public sealed class PreviewAnimationLibrary
|
||||
{
|
||||
private readonly Dictionary<uint, (string Name, MorphAnimation Animation)> choices = [];
|
||||
private readonly Dictionary<PlayerPose, MorphAnimation> movement = [];
|
||||
public MorphAnimation Current { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string WindowTitle => $"Jimmy Neutron — scene preview | {Name}{(Current.HasVertexMotion ? "" : " (still pose)")} | 1 idle, 2 run, 3 jump, 4 scratch | C camera";
|
||||
@@ -15,6 +17,22 @@ public sealed class PreviewAnimationLibrary
|
||||
Current = new MorphAnimation(manifest);
|
||||
Name = Path.GetFileName(Path.GetDirectoryName(Path.GetFullPath(manifest)))!;
|
||||
var parent = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(manifest)!, ".."));
|
||||
var loaded = new Dictionary<string, MorphAnimation>(StringComparer.Ordinal)
|
||||
{ [Path.GetFullPath(manifest)] = Current };
|
||||
MorphAnimation Load(string path)
|
||||
{
|
||||
path = Path.GetFullPath(path);
|
||||
if (loaded.TryGetValue(path, out var cached)) return cached;
|
||||
var clip = new MorphAnimation(path);
|
||||
if (clip.Base.Vertices.Length != Current.Base.Vertices.Length
|
||||
|| !clip.Base.Indices.SequenceEqual(Current.Base.Indices)
|
||||
|| !clip.Base.Vertices.Select(v => v.Uv).SequenceEqual(Current.Base.Vertices.Select(v => v.Uv))
|
||||
|| clip.Texture.Width != Current.Texture.Width || clip.Texture.Height != Current.Texture.Height
|
||||
|| !clip.Texture.Rgba.SequenceEqual(Current.Texture.Rgba))
|
||||
throw new InvalidDataException($"Animation family mismatch: {path}");
|
||||
loaded[path] = clip;
|
||||
return clip;
|
||||
}
|
||||
foreach (var (scancode, folder, label) in new[]
|
||||
{
|
||||
(30u, "jimstop", "Idle"), (31u, "jimrun", "Run cycle"),
|
||||
@@ -23,16 +41,17 @@ public sealed class PreviewAnimationLibrary
|
||||
{
|
||||
var path = Path.Combine(parent, folder, "animation.json");
|
||||
if (!File.Exists(path)) continue;
|
||||
var clip = Path.GetFullPath(path) == Path.GetFullPath(manifest) ? Current : new MorphAnimation(path);
|
||||
if (clip.Base.Vertices.Length != Current.Base.Vertices.Length
|
||||
|| !clip.Base.Indices.SequenceEqual(Current.Base.Indices)
|
||||
|| !clip.Base.Vertices.Select(v => v.Uv).SequenceEqual(Current.Base.Vertices.Select(v => v.Uv))
|
||||
|| clip.Texture.Width != Current.Texture.Width || clip.Texture.Height != Current.Texture.Height
|
||||
|| !clip.Texture.Rgba.SequenceEqual(Current.Texture.Rgba))
|
||||
throw new InvalidDataException($"Animation family mismatch: {path}");
|
||||
var clip = Load(path);
|
||||
choices[scancode] = (label, clip);
|
||||
if (ReferenceEquals(clip, Current)) Name = label;
|
||||
}
|
||||
foreach (var (pose, folder) in new[] { (PlayerPose.Idle, "jimstop"), (PlayerPose.Run, "jimrun"),
|
||||
(PlayerPose.Backpedal, "jimbackpedal"), (PlayerPose.Jump, "jimjump"), (PlayerPose.Fall, "jimfall") })
|
||||
{
|
||||
var path = Path.Combine(parent, folder, "animation.json");
|
||||
if (!File.Exists(path)) continue;
|
||||
movement[pose] = Load(path);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Select(uint scancode)
|
||||
@@ -42,4 +61,13 @@ public sealed class PreviewAnimationLibrary
|
||||
Name = clip.Name;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SelectPose(PlayerPose pose)
|
||||
{
|
||||
if (!movement.TryGetValue(pose, out var clip)) throw new InvalidDataException($"Prepare original {pose} animation first");
|
||||
if (ReferenceEquals(Current, clip)) return false;
|
||||
Current = clip;
|
||||
Name = pose.ToString();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user