Files
Pal3.Unity/Assets/Tests/Editor/FlexCameraReaderTests.cs
Jiaqi Liu 5d0f564a00 Add a standalone battle editor and battle system for PAL3 and PAL3A (#99)
* build: migrate C# formatting and add offscreen editor test support

Host IMGUI tests on a detached panel without creating a native editor window.

* feat(core): decode native battle records, geometry and animation metadata

Read the two game variants’ battle tables and model data, with binary-reader and original-resource coverage.

* feat(battle): implement deterministic combat rules and action settlement

Implement actors, inventory, formation, action timing, status interruption, AI, stage ownership and deterministic replay. Keep the domain and its regression suite independent of Unity.

* feat(battle): project native HUD state and input commands

Add the presentation assembly and tests for command routing, lineup selection, floating numbers and stage messages.

* feat(rendering): add battle lighting, actor appearance and native shadows

Support baked and toon lighting, actor and weapon rendering, display refresh rate and resource ownership.

* feat(effects): drive battle effects through shared resource previews

Bind battle control nodes to action owners. Share preview lighting, geometry and effect resources with the existing Unity editors.

* refactor(game): isolate story battle targeting and actor lifetimes

Preserve scene ownership, bound story battle targeting and stop debug attacks when their actor leaves the scene.

* feat(editor): compile original game data into battle scenarios

Build per-variant animation and ability catalogs, encounter music, scene lighting profiles, random parties, equipment and test inventory from the original resources.

* feat(editor): play battle sessions with animated previews and synced media

Drive the preview scene, camera, effects, hit feedback, result choreography, music and movies from simulation snapshots and events.

* feat(editor): add the battle workbench, native HUD and input controls

Expose scenario authoring, replay, diagnostics, responsive command menus and mouse, touch and gamepad targeting. Include the editor workflow and HUD integration tests.
2026-11-21 22:28:47 +08:00

103 lines
4.7 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Core.Tests
{
using System.IO;
using Core.DataReader;
using Core.DataReader.Dat;
using NUnit.Framework;
public sealed class FlexCameraReaderTests
{
[Test]
public void BothGamesUseTheSixteenByteDispatchAreaAnd204ByteRecordStride()
{
byte[] bytes = Empty();
using (var writer = new BinaryWriter(new MemoryStream(bytes)))
{
for (int record = 0; record < 2; record++)
{
writer.BaseStream.Position = record * 204;
for (uint word = 0; word < 4; word++)
writer.Write(0x10000000u + word);
writer.Write((uint)(700 + record));
writer.Write(true);
writer.Write(false);
writer.Write(true);
writer.Write(true);
for (int value = 0; value < 14; value++)
writer.Write(1.25f + value);
writer.Write(21);
writer.Write(22);
for (int bit = 0; bit < 15; bit++)
writer.Write(bit % 2 == 0);
writer.Write((byte)0xfe); // Alignment must never become part of nTraceRole.
writer.Write(-1);
for (int value = 0; value < 22; value++)
writer.Write(30.5f + value);
writer.Write(0x11223344u);
writer.Write(0x55667788u);
}
writer.BaseStream.Position = 408000;
writer.Write(true);
writer.BaseStream.Position = 410000;
writer.Write(1);
}
FlexCameraFile file = ((IFileReader<FlexCameraFile>)new FlexCameraFileReader()).Read(bytes, 936);
Assert.That(file.Pool.Count, Is.EqualTo(2000));
Assert.That(file.Lists.Count, Is.EqualTo(100));
Assert.That(file.Lists[0][0], Is.EqualTo(1));
Assert.That(file.InUse[0], Is.True);
Assert.That(file.InUse[1], Is.False);
for (int record = 0; record < 2; record++)
{
FlexCameraTask task = file.Pool[record];
Assert.That(task.SerializedDispatchWords, Is.EqualTo(new uint[] { 0x10000000, 0x10000001, 0x10000002, 0x10000003 }));
Assert.That(task.Id, Is.EqualTo(700 + record));
Assert.That(task.SavedStartTime, Is.EqualTo(1.25f));
Assert.That(task.ExpectedSeconds, Is.EqualTo(2.25f));
Assert.That(task.Start.Position.X, Is.EqualTo(3.25f));
Assert.That(task.Start.Yaw, Is.EqualTo(6.25f));
Assert.That(task.End.Roll, Is.EqualTo(14.25f));
Assert.That(task.StartCameraIndex, Is.EqualTo(21));
Assert.That(task.EndCameraIndex, Is.EqualTo(22));
Assert.That((int)task.Flags, Is.EqualTo(0x5555));
Assert.That(task.TraceActor, Is.EqualTo(-1));
Assert.That(task.StartSpeed, Is.EqualTo(30.5f));
Assert.That(task.CircleAngle, Is.EqualTo(36.5f));
Assert.That(task.CircleCenter.X, Is.EqualTo(38.5f));
Assert.That(task.TimeCompensation, Is.EqualTo(46.5f));
Assert.That(task.StartFieldOfView, Is.EqualTo(47.5f));
Assert.That(task.SavedTraceStart.Z, Is.EqualTo(51.5f));
Assert.That(task.ExtensionWords, Is.EqualTo(new uint[] { 0x11223344, 0x55667788 }));
}
}
[Test]
public void TruncatedExtendedAndOutOfPoolFilesAreRejected()
{
var reader = (IFileReader<FlexCameraFile>)new FlexCameraFileReader();
Assert.Throws<InvalidDataException>(() => reader.Read(new byte[FlexCameraFileReader.FileBytes - 1], 936));
Assert.Throws<InvalidDataException>(() => reader.Read(new byte[FlexCameraFileReader.FileBytes + 1], 936));
byte[] bytes = Empty();
using (var writer = new BinaryWriter(new MemoryStream(bytes)))
{
writer.BaseStream.Position = 410000;
writer.Write(2000);
}
Assert.Throws<InvalidDataException>(() => reader.Read(bytes, 936));
}
private static byte[] Empty()
{
var bytes = new byte[FlexCameraFileReader.FileBytes];
for (int i = 410000; i < bytes.Length; i++)
bytes[i] = 0xff;
return bytes;
}
}
}