883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
import struct
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
|
|
import native_doodad_equivalence as nde # noqa: E402
|
|
|
|
|
|
def _m2(name, ids):
|
|
body = bytearray(b'MD20' + bytes(300))
|
|
nm = name.encode() + b'\0'
|
|
struct.pack_into('<II', body, 8, len(nm), len(body)); body += nm
|
|
struct.pack_into('<II', body, 28, len(ids), len(body))
|
|
for i in ids:
|
|
rec = bytearray(64); struct.pack_into('<H', rec, 0, i); body += rec
|
|
return b'MD21' + struct.pack('<I', len(body)) + bytes(body)
|
|
|
|
|
|
def _chunk(tag, data):
|
|
return tag[::-1] + struct.pack('<I', len(data)) + data
|
|
|
|
|
|
class NativeDoodadEquivalenceTest(unittest.TestCase):
|
|
def test_name_match_and_rewrite(self):
|
|
index = nde.listfile_m2_index(['197382;world/x/excavationstake.m2\n', '199634;world/y/crate02.m2\n',
|
|
'199635;world/z/crate02.m2\n', '9000000;wowhybrid/a.m2\n'], below=8400000)
|
|
mapping, held = nde.native_equivalents(
|
|
{8567775: _m2('ExcavationStake', [0]), 8545442: _m2('Crate02', [146]), 8500001: _m2('', [0])},
|
|
index, lambda f: f != 199635)
|
|
self.assertEqual(mapping, {8567775: 197382, 8545442: 199634})
|
|
self.assertEqual(held, {8500001: 'no internal name'})
|
|
self.assertTrue(nde.missing_stand(_m2('Crate02', [148, 146, 147, 149])))
|
|
wmo = _chunk(b'MOHD', bytes(64)) + _chunk(b'MODI', struct.pack('<3I', 8567775, 1, 8545442))
|
|
out, n = nde.rewrite_doodad_refs(wmo, 'wmo', mapping)
|
|
self.assertEqual((n, struct.unpack_from('<3I', out, 72 + 8)), (2, (197382, 1, 199634)))
|
|
entry = lambda f, flags: struct.pack('<I', f) + bytes(30) + struct.pack('<H', flags)
|
|
adt = _chunk(b'MDDF', entry(8567775, 0x40) + entry(8567775, 0))
|
|
out, n = nde.rewrite_doodad_refs(adt, 'adt', mapping)
|
|
self.assertEqual((n, struct.unpack_from('<I', out, 8)[0], struct.unpack_from('<I', out, 44)[0]), (1, 197382, 8567775))
|
|
|
|
def test_unmapped_doodad_with_stand_unchanged(self):
|
|
raw = _m2('BE_Tent03', [0, 4])
|
|
self.assertEqual(nde.prepare_unmapped_doodad(raw), (raw, dict(changed=False)))
|
|
|
|
def test_native_path_bindings(self):
|
|
paths = nde.listfile_m2_paths(['1;World/A/Rock.m2\n', '9000001;world/a/new.m2\n', '2;world/a/gone.m2\n'], below=8400000)
|
|
self.assertEqual(paths, {'world/a/rock.m2': 1, 'world/a/gone.m2': 2})
|
|
got = nde.native_path_bindings(['world/a/rock.mdx', 'world/a/gone.mdx', 'world/a/new.mdx'], paths, lambda f: f != 2)
|
|
self.assertEqual(got, {'world/a/rock.mdx': 1})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|