mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
* Optimize DDS texture creation and static POL meshes Separate file decoding from Unity upload through format-neutral texture data and explicit world, sprite and skybox policies. Validate DDS layouts, preserve alpha coverage and use native BC uploads with software RGBA fallback. Compact referenced POL vertices and batch nearby static opaque groups sharing materials. Keep water and dynamic geometry separate, with source ranges retained only in the Editor. Add DDS layout and POL index regression tests. Validation: PAL3 and PAL3A each passed 24 Editor tests, eight combined Game and ResourceViewer style regressions, 936 paired skybox comparisons, and both macOS Player builds on Metal. Editor provenance and Core tests are excluded from Players. * Add core protocol regression tests and copyright checks Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation. Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries. * Implement PAL3A command handlers and isolate script execution Correct PAL3A parameter signatures and add handlers for fortune selection, skybox sequences, actor facing and attacks, team and progression state, camera constraints, and battle preparation flags. Give script instances separate locals, advance grouped waits concurrently, and pause PAL3A parents only for their directly decoded child calls. Cancel stale interactions and save replay on reset, preserve finite action semantics, and restore camera orientation after releasing horizontal constraints. Persist supported state in v2 saves and add protocol, runtime, and progression regressions. Full combat gameplay remains outside this change. Validation: PAL3 274/274 and PAL3A 291/291 EditMode tests; 18 PAL3 and 22 PAL3A runtime checks. All 77,889 PAL3A instruction boundaries match EXE signatures. * Run CI only for pull requests and upgrade build actions
111 lines
6.2 KiB
C#
111 lines
6.2 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;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using NUnit.Framework;
|
|
|
|
public sealed class CopyrightHeaderTests
|
|
{
|
|
private const string Separator = "// ------------------------------------------------------------------------";
|
|
private const string LicenseLine = "// See LICENSE file in the project root for license information.";
|
|
private static readonly Regex CopyrightLine = new(
|
|
@"\A// Copyright \(c\) (?<first>\d{4})(?:-(?<last>\d{4}))?, Jiaqi \(0x7c13\) Liu\. All rights reserved\.\z");
|
|
|
|
private static readonly string[] SourceRoots =
|
|
{
|
|
"Assets/Scripts", "Assets/Tests", "Assets/Rendering", "Assets/Resources/Shaders"
|
|
};
|
|
private static readonly HashSet<string> Extensions = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
".cs", ".shader", ".hlsl", ".cginc", ".compute"
|
|
};
|
|
|
|
// Explicit upstream/generated files retain their own authorship or tool-owned header.
|
|
// Priority queue provenance: github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp.
|
|
private static readonly HashSet<string> UpstreamFiles = new(StringComparer.Ordinal)
|
|
{
|
|
"Assets/Scripts/Pal3.Core/DataReader/Cpk/Lzo/MiniLzo.cs",
|
|
"Assets/Scripts/Pal3.Core/DataReader/Bmp/BmpFileReader.cs",
|
|
"Assets/Scripts/Pal3.Core/Algorithm/PriorityQueue/GenericPriorityQueue.cs",
|
|
"Assets/Scripts/Pal3.Core/Algorithm/PriorityQueue/GenericPriorityQueueNode.cs",
|
|
"Assets/Scripts/Pal3.Core/Algorithm/PriorityQueue/IFixedSizePriorityQueue.cs",
|
|
"Assets/Scripts/Pal3.Core/Algorithm/PriorityQueue/IPriorityQueue.cs",
|
|
"Assets/Scripts/Pal3.Core/Algorithm/PriorityQueue/SimplePriorityQueue.cs"
|
|
};
|
|
private const string UnityGeneratedInput = "Assets/Scripts/Pal3.Game/Input/PlayerInputActions.cs";
|
|
|
|
[Test]
|
|
public void ProjectOwnedSourcesHaveStandardCopyrightHeaders()
|
|
{
|
|
string project = Path.GetFullPath(".").TrimEnd(Path.DirectorySeparatorChar);
|
|
var failures = new List<string>();
|
|
int checkedFiles = 0, upstreamFiles = 0, generatedFiles = 0;
|
|
foreach (string root in SourceRoots)
|
|
{
|
|
Assert.That(Directory.Exists(Path.Combine(project, root)), Is.True, root);
|
|
foreach (string file in Directory.EnumerateFiles(Path.Combine(project, root), "*", SearchOption.AllDirectories)
|
|
.Where(p => Extensions.Contains(Path.GetExtension(p))).OrderBy(p => p))
|
|
{
|
|
string relative = file[(project.Length + 1)..].Replace('\\', '/');
|
|
if (UpstreamFiles.Contains(relative)) { upstreamFiles++; continue; }
|
|
string text = File.ReadAllText(file);
|
|
if (relative == UnityGeneratedInput)
|
|
{
|
|
Assert.That(text, Does.Contain("auto-generated by com.unity.inputsystem:InputActionCodeGenerator"));
|
|
generatedFiles++;
|
|
continue;
|
|
}
|
|
checkedFiles++;
|
|
string error = ValidateHeader(text, DateTime.Now.Year);
|
|
if (error != null) failures.Add($"{relative}: {error}");
|
|
}
|
|
}
|
|
TestContext.WriteLine($"Checked {checkedFiles} owned source headers; preserved {upstreamFiles} upstream files and {generatedFiles} Unity-generated file.");
|
|
Assert.That(checkedFiles, Is.GreaterThan(0));
|
|
Assert.That(upstreamFiles, Is.EqualTo(UpstreamFiles.Count), "Keep the explicit upstream catalog in sync with the source tree");
|
|
Assert.That(generatedFiles, Is.EqualTo(1));
|
|
Assert.That(failures, Is.Empty, string.Join("\n", failures));
|
|
}
|
|
|
|
[TestCase("2026", 72, true)]
|
|
[TestCase("2021-2026", 72, true)]
|
|
[TestCase("2021-2025", 72, true)] // A valid historical header stays valid until that file changes.
|
|
[TestCase("2026", 93, false)]
|
|
[TestCase("2026-2026", 72, false)]
|
|
[TestCase("2026-2025", 72, false)]
|
|
[TestCase("2020-2026", 72, false)]
|
|
[TestCase("9999", 72, false)]
|
|
public void HeaderValidationAcceptsSingleYearsAndRangesButRejectsMalformedNotices(string years, int dashes, bool valid)
|
|
{
|
|
string separator = "// " + new string('-', dashes);
|
|
string text = $"{separator}\n// Copyright (c) {years}, Jiaqi (0x7c13) Liu. All rights reserved.\n{LicenseLine}\n{separator}\n\nnamespace Example {{ }}";
|
|
Assert.That(ValidateHeader(text, 2026) == null, Is.EqualTo(valid));
|
|
Assert.That(ValidateHeader("\uFEFF" + text.Replace("\n", "\r\n"), 2026) == null, Is.EqualTo(valid));
|
|
}
|
|
|
|
private static string ValidateHeader(string text, int currentYear)
|
|
{
|
|
string[] lines = text.TrimStart('\uFEFF').Replace("\r\n", "\n").Split('\n');
|
|
if (lines.Length < 5 || lines[0] != Separator || lines[3] != Separator)
|
|
return "Expected the four-line copyright header with 72 hyphens at the start of the file";
|
|
if (lines[2] != LicenseLine || lines[4] != string.Empty)
|
|
return "Expected the standard LICENSE sentence and a blank line after the header";
|
|
Match notice = CopyrightLine.Match(lines[1]);
|
|
if (!notice.Success) return "Copyright owner, spacing or year format does not match the project standard";
|
|
int first = int.Parse(notice.Groups["first"].Value);
|
|
int last = notice.Groups["last"].Success ? int.Parse(notice.Groups["last"].Value) : first;
|
|
if (first < 2021 || last > currentYear || last < first || (notice.Groups["last"].Success && last == first))
|
|
return "Use a single year or an increasing year range, without future dates";
|
|
return null;
|
|
}
|
|
}
|
|
}
|