Reconstruct lab story, interactions, patrol and jet pack practice flow
This commit is contained in:
1 parent
58424120bb
commit
c929f942e1
84 files changed
+7957
-305
No files matched your search
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net10.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems></PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs"/>
|
||||
<Compile Include="../../src/GamePort/Assets/Mesh.cs"/>
|
||||
<Compile Include="../../src/GamePort/Assets/PngImage.cs"/>
|
||||
<Compile Include="../../src/GamePort/Application/SceneHud.cs"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Numerics;
|
||||
using System.Text.Json;
|
||||
using GamePort.Assets;
|
||||
using GamePort.Application;
|
||||
|
||||
var temp = Path.Combine(Path.GetTempPath(), "neutron-hud-" + Guid.NewGuid());
|
||||
Directory.CreateDirectory(temp);
|
||||
try
|
||||
{
|
||||
var entries = new[] { (120,256,29),(121,256,29),(122,256,29),(156,320,173),(169,207,100),(83,8,8),(84,8,8),(85,8,8) }
|
||||
.Select(t => new { id=t.Item1, width=t.Item2, height=t.Item3, path=$"{t.Item1}.rgba" }).ToArray();
|
||||
foreach (var entry in entries) File.WriteAllBytes(Path.Combine(temp, entry.path), new byte[entry.width * entry.height * 4]);
|
||||
string Manifest(object textures) => JsonSerializer.Serialize(new { version=1, referenceWidth=640, referenceHeight=480, textures });
|
||||
var path = Path.Combine(temp, "ui.json");
|
||||
File.WriteAllText(path, Manifest(entries));
|
||||
var source = new Mesh([new(new(5,6,7), Vector2.Zero, Vector3.One)], [0,0,0]);
|
||||
var hud = new SceneHud(source, path);
|
||||
Check(hud.Mesh.Vertices.Length == 33 && hud.Mesh.Indices.Length == 51, "Exact bounded HUD ranges");
|
||||
Check(hud.Mesh.Draws.Length == 9 && !hud.Mesh.Draws[0].ScreenSpace && hud.Mesh.Draws.Skip(1).All(d => d.ScreenSpace),
|
||||
"Preserve implicit world draw; explicit HUD overlays");
|
||||
Check(hud.Mesh.Textures.Count == 8, "Original canvas count");
|
||||
var final = hud.Mesh with { Vertices = hud.Mesh.Vertices.ToArray(), Draws = hud.Mesh.Draws.Select(d => d with {}).ToArray() };
|
||||
hud.Update(final, 2, true, true);
|
||||
Check(final.Vertices[0].Position == new Vector3(5,6,7), "HUD leaves world data unchanged");
|
||||
Check(hud.Mesh.Vertices[1].Position == Vector3.Zero && final.Vertices[1].Position != Vector3.Zero,
|
||||
"Update writes final merged buffer after copies");
|
||||
Near(final.Vertices[1].Position, new(.2f, 2*311f/480-1, 0), "Pad default source offset");
|
||||
Near(final.Vertices[9].Position, new(.2f, 2*379f/480-1, 0), "Selected objective row position");
|
||||
Near(final.Vertices[21].Position, new(2*393f/640-1, 2*381f/480-1, 0), "Selected original digit position");
|
||||
Near(final.Vertices[29].Position, new(2*210f/640-1, 2*210f/480-1, 0), "Practice source position");
|
||||
Check(final.Draws.Select(d => d.Visible).SequenceEqual(new[] { true,true,false,true,false,false,true,false,true }),
|
||||
"Only pad, active objective2 and practice visible");
|
||||
hud.Update(final, 3, true, false, 0);
|
||||
Check(final.Draws.Select(d => d.Visible).SequenceEqual(new[] { true,true,false,false,true,false,false,true,false }), "Objective3 and dismissed modal");
|
||||
Near(final.Vertices[1].Position, new(.2f, 2*380f/480-1, 0), "Expanded source HUD offset");
|
||||
hud.Update(final, 0, true, false);
|
||||
Check(final.Draws.Skip(1).All(d => !d.Visible), "No invented objective0 image");
|
||||
Reject(() => hud.Update(source, 1, true, false), "Missing final ranges");
|
||||
Reject(() => hud.Update(final, 1, true, false, float.NaN), "Nonfinite HUD offset");
|
||||
File.WriteAllText(path, Manifest(entries.Select(e => new { e.id, width=e.id==120 ? 0 : e.width, e.height, e.path })));
|
||||
Reject(() => new SceneHud(source,path), "Bad canvas dimensions");
|
||||
File.WriteAllText(path, Manifest(entries.Select(e => new { e.id, e.width, e.height, path=e.id==120 ? "../outside.rgba" : e.path })));
|
||||
Reject(() => new SceneHud(source,path), "Escaping texture path");
|
||||
File.WriteAllText(path, Manifest(entries.Concat(entries.Take(1))));
|
||||
Reject(() => new SceneHud(source,path), "Unbounded texture count");
|
||||
if (args.Length == 1)
|
||||
{
|
||||
var originalHud = new SceneHud(source, args[0]);
|
||||
originalHud.Update(originalHud.Mesh,1,true,true);
|
||||
Check(originalHud.Mesh.Textures.Values.Any(p=>p.Rgba.Any(v=>v!=0)), "Actual original RGBA loaded");
|
||||
}
|
||||
Console.WriteLine("PASS original UI geometry/visibility/final buffer and bounded prepared manifest checks");
|
||||
}
|
||||
finally { Directory.Delete(temp,true); }
|
||||
|
||||
static void Check(bool value,string message) { if(!value)throw new Exception(message); }
|
||||
static void Near(Vector3 a,Vector3 b,string message) => Check(Vector3.Distance(a,b)<.00001f,message);
|
||||
static void Reject(Action action,string message)
|
||||
{
|
||||
try { action(); }
|
||||
catch (Exception e) when (e is InvalidDataException or ArgumentException) { return; }
|
||||
throw new Exception("Accepted invalid input: " + message);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Original UI extraction regressions; stdlib only, no original writes."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / 'tools' / 'extractors'))
|
||||
from omt import Database, FormatError, read_canvas
|
||||
from ui import export_ui
|
||||
|
||||
|
||||
class UiTests(unittest.TestCase):
|
||||
def test_original_canvases_and_hashes(self):
|
||||
original = ROOT.parent / 'Original'
|
||||
screens = Database(original / 'omt' / 'screens.omt')
|
||||
alpha = Database(original / 'alpha.omt')
|
||||
before = [hashlib.sha256(db.path.read_bytes()).hexdigest() for db in (screens, alpha)]
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
output = Path(target) / 'ui'
|
||||
result = export_ui(screens, output, alpha)
|
||||
self.assertEqual(8, len(result['textures']))
|
||||
self.assertEqual([120,121,122,156,169,83,84,85], [t['id'] for t in result['textures']])
|
||||
for entry in result['textures']:
|
||||
database = alpha if entry['source'] == 'alpha.omt' else screens
|
||||
raw = next(e for e in database.entries if e.type == 'Canv' and e.id == entry['id'])
|
||||
rgba = read_canvas(database.payload(raw))['rgba']
|
||||
self.assertEqual(rgba, (output / entry['path']).read_bytes())
|
||||
self.assertEqual(hashlib.sha256(rgba).hexdigest(), entry['rgbaSha256'])
|
||||
self.assertEqual(result, json.loads((output / 'ui.json').read_text()))
|
||||
self.assertEqual(before, [hashlib.sha256(db.path.read_bytes()).hexdigest() for db in (screens, alpha)])
|
||||
|
||||
def test_missing_canvas_and_original_output_rejected(self):
|
||||
original = ROOT.parent / 'Original'
|
||||
screens = Database(original / 'omt' / 'screens.omt')
|
||||
alpha = Database(original / 'alpha.omt')
|
||||
with self.assertRaises(ValueError):
|
||||
export_ui(screens, screens.path.parent / 'generated', alpha)
|
||||
screens.entries = [e for e in screens.entries if e.id != 120]
|
||||
with tempfile.TemporaryDirectory() as target:
|
||||
output = Path(target) / 'ui'
|
||||
with self.assertRaises(FormatError):
|
||||
export_ui(screens, output, alpha)
|
||||
self.assertFalse(output.exists(), 'Validate identities before creating output')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user