using System.Numerics; using AcDream.App.Rendering; using AcDream.Core.Physics; using AcDream.Core.World; using DatReaderWriter.DBObjs; namespace AcDream.App.Tests.Rendering; public sealed class LiveAppearanceAnimationTests { [Fact] public void RebindAppearance_PreservesEntitySequencerAndPlaybackState() { var setup = new Setup(); var animation = new Animation(); var sequencer = new AnimationSequencer(setup, new MotionTable(), new NullLoader()); var oldEntity = Entity(0x70000001u, 0x01000001u); var state = new GameWindow.AnimatedEntity { Entity = oldEntity, Setup = setup, Animation = animation, LowFrame = 2, HighFrame = 9, Framerate = 30f, Scale = 1f, PartTemplate = [new GameWindow.AnimatedPartTemplate(0x01000001u, null, true)], PartAvailability = [true], CurrFrame = 6.5f, Sequencer = sequencer, }; IReadOnlyList dressedParts = [ new MeshRef(0x01000002u, Matrix4x4.Identity), new MeshRef(0x01000003u, Matrix4x4.CreateTranslation(1f, 2f, 3f)), ]; oldEntity.ApplyAppearance(dressedParts, paletteOverride: null, partOverrides: []); GameWindow.RebindAnimatedEntityForAppearance( state, oldEntity, setup, 1.25f, [ new GameWindow.AnimatedPartTemplate(0x01000002u, null, true), new GameWindow.AnimatedPartTemplate(0x01000003u, null, true), ], [true, true]); Assert.Same(oldEntity, state.Entity); Assert.Same(dressedParts, state.Entity.MeshRefs); Assert.Same(sequencer, state.Sequencer); Assert.Equal(6.5f, state.CurrFrame); Assert.Equal((2, 9, 30f), (state.LowFrame, state.HighFrame, state.Framerate)); Assert.Equal(1.25f, state.Scale); Assert.Equal(new[] { 0x01000002u, 0x01000003u }, state.PartTemplate.Select(part => part.GfxObjId)); } private static WorldEntity Entity(uint id, uint gfxObjId) => new() { Id = id, ServerGuid = 0x50000001u, SourceGfxObjOrSetupId = 0x02000001u, Position = Vector3.Zero, Rotation = Quaternion.Identity, MeshRefs = [new MeshRef(gfxObjId, Matrix4x4.Identity)], }; private sealed class NullLoader : IAnimationLoader { public Animation? LoadAnimation(uint id) => null; } }