Files
Jiaqi Liu d1b2c05eb4 Optimize resource loading and fix PAL3A script execution (#92)
* 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
2026-11-13 09:28:31 +08:00

140 lines
6.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ------------------------------------------------------------------------
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.GameSystems.Dialogue
{
using System;
using System.Collections.Generic;
public static class DialogueTextProcessor
{
/// <summary>
/// Break long dialogue into pieces
/// Basically separate a dialogue into two pieces if there are more
/// than three new line chars found in the dialogue text.
/// </summary>
/// <param name="text">The input text.</param>
/// <returns>One or two sub dialogues</returns>
public static IEnumerable<string> GetSubDialoguesAsync(string text)
{
if (text.Contains('\n'))
{
int indexOfSecondNewLineChar = text.IndexOf('\n', text.IndexOf('\n') + 1);
if (indexOfSecondNewLineChar != -1)
{
int indexOfThirdNewLineChar = text.IndexOf('\n', indexOfSecondNewLineChar + 1);
if (indexOfThirdNewLineChar != -1 && indexOfThirdNewLineChar != text.Length)
{
string firstPart = text[..indexOfThirdNewLineChar];
string secondPart = text.Substring(indexOfThirdNewLineChar, text.Length - indexOfThirdNewLineChar);
yield return firstPart;
yield return text[..text.IndexOf('\n')] + secondPart;
yield break;
}
}
}
yield return text;
}
/// <summary>
/// Returns the display text with information text color used by TextMeshProUGUI.
/// </summary>
/// <param name="text">The input text.</param>
/// <param name="informationTextColorHex">The hex code for the information text color.</param>
/// <returns>The formatted text with information text color.</returns>
public static string GetDisplayText(string text, string informationTextColorHex)
{
string formattedText = text.Replace("\\n", "\n");
return ReplaceStringInTextWithPatternForEachChar(formattedText,
"\\i", "\\r",
$"<color={informationTextColorHex}>", "</color>");
}
/// <summary>
/// Returns the display text for a given selection text. Removes any numbering or
/// punctuation at the beginning or end of the selection text.
/// </summary>
/// <param name="selectionText">The selection text to process.</param>
/// <returns>The display text for the selection string.</returns>
public static string GetSelectionDisplayText(string selectionText)
{
if (selectionText.EndsWith(";") || selectionText.EndsWith("。")) selectionText = selectionText[..^1];
if (selectionText.Contains('.'))
{
string numberStr = selectionText[..selectionText.IndexOf('.')];
if (int.TryParse(numberStr, out _))
{
return selectionText[(selectionText.IndexOf('.') + 1)..];
}
}
if (selectionText.Contains('、'))
{
string numberStr = selectionText[..selectionText.IndexOf('、')];
if (int.TryParse(numberStr, out _))
{
return selectionText[(selectionText.IndexOf('、') + 1)..];
}
}
// I don't think there will be more than 20 options, so let's start with 20
for (int i = 20; i >= 0; i--)
{
string intStr = i.ToString();
if (selectionText.StartsWith(intStr) && !string.Equals(selectionText, intStr))
{
return selectionText[intStr.Length..];
}
}
return selectionText;
}
/// <summary>
/// Replaces each character in a substring of the input string that is enclosed by a start pattern and an end pattern with a new pattern.
/// </summary>
/// <param name="text">The input string to process.</param>
/// <param name="startPattern">The start pattern that marks the beginning of the substring to process.</param>
/// <param name="endPattern">The end pattern that marks the end of the substring to process.</param>
/// <param name="charStartPattern">The pattern to insert before each character in the substring.</param>
/// <param name="charEndPattern">The pattern to insert after each character in the substring.</param>
/// <returns>The processed string.</returns>
private static string ReplaceStringInTextWithPatternForEachChar(string text,
string startPattern,
string endPattern,
string charStartPattern,
string charEndPattern)
{
string newStr = string.Empty;
int currentIndex = 0;
int startOfInformation = text.IndexOf(startPattern, StringComparison.Ordinal);
while (startOfInformation != -1)
{
int endOfInformation = text.IndexOf(endPattern, startOfInformation, StringComparison.Ordinal);
newStr += text.Substring(currentIndex, startOfInformation - currentIndex);
foreach (char ch in text.Substring(
startOfInformation + startPattern.Length,
endOfInformation - startOfInformation - startPattern.Length))
{
newStr += $"{charStartPattern}{ch}{charEndPattern}";
}
currentIndex = endOfInformation + endPattern.Length;
startOfInformation = text.IndexOf(
startPattern, currentIndex, StringComparison.Ordinal);
}
newStr += text.Substring(currentIndex, text.Length - currentIndex);
return newStr;
}
}
}