883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
53 lines
2.6 KiB
Python
53 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 adt_obj1 # noqa: E402
|
|
|
|
|
|
def _chunk(tag, data):
|
|
return tag[::-1] + struct.pack('<I', len(data)) + data
|
|
|
|
|
|
def _obj0(doodads, objects):
|
|
mddf = b''.join(struct.pack('<II3f3fHH', *d) for d in doodads)
|
|
modf = b''.join(struct.pack('<II3f3f6fHHHH', *o) for o in objects)
|
|
return _chunk(b'MVER', struct.pack('<I', 18)) + _chunk(b'MDDF', mddf) + _chunk(b'MODF', modf) + _chunk(b'MCNK', b'')
|
|
|
|
|
|
class Obj1Test(unittest.TestCase):
|
|
def test_native_wmo_box_from_extents(self):
|
|
# Native Kalimdor 30_11 WMO 112832: MODF extents -> MLMX box, radius 513.5.
|
|
box = adt_obj1.extents_world_box((16004.5, 1313.7, 6326.4, 16518.0, 1601.4, 6834.4))
|
|
for got, want in zip(box, (10232.3, 548.7, 1313.7, 10740.2, 1062.2, 1601.4)):
|
|
self.assertAlmostEqual(got, want, delta=0.1)
|
|
|
|
def test_doodad_box_heading(self):
|
|
# rot[1]=0 turns the model half a turn about up: local +x maps to world -x.
|
|
box = adt_obj1.doodad_world_box((adt_obj1.MAP_HALF, 5.0, adt_obj1.MAP_HALF), (0, 0, 0), 2048, (0, -1, 0, 10, 1, 3))
|
|
for got, want in zip(box, (-20, -2, 5, 0, 2, 11)):
|
|
self.assertAlmostEqual(got, want, places=3)
|
|
|
|
def test_lists_sorted_flagged_and_held(self):
|
|
c = adt_obj1.MAP_HALF
|
|
obj0 = _obj0([(10, 1, c, 0, c, 0, 0, 0, 1024, 0x40), (11, 2, c, 0, c, 0, 0, 0, 1024, 0x240), (12, 3, c, 0, c, 0, 0, 0, 1024, 0x40)],
|
|
[(7, 9, 1, 2, 3, 0, 0, 0, 100, 0, 100, 110, 5, 140, 0xc, 0, 0, 1024)])
|
|
boxes = {10: (0, 0, 0, 1, 1, 1), 11: (0, 0, 0, 8, 1, 1)}
|
|
raw, audit = adt_obj1.build_obj1(obj0, boxes.get)
|
|
self.assertEqual(audit, dict(doodads=2, objects=1, held_models=[12]))
|
|
chunks = dict(adt_obj1._chunks(raw))
|
|
self.assertEqual([t[::-1] for t, _ in adt_obj1._chunks(raw)], [b'MVER', b'MLDD', b'MLDX', b'MLMD', b'MLMX'])
|
|
names = [struct.unpack_from('<I', chunks[b'DDLM'], 36 * i)[0] for i in range(2)]
|
|
flags = [struct.unpack_from('<H', chunks[b'DDLM'], 36 * i + 34)[0] for i in range(2)]
|
|
self.assertEqual((names, flags), ([11, 10], [0x260, 0x60]))
|
|
self.assertAlmostEqual(struct.unpack_from('<f', chunks[b'XDLM'], 24)[0], 8.0, places=4)
|
|
self.assertEqual(len(chunks[b'DMLM']), 40)
|
|
self.assertEqual(struct.unpack_from('<HHHH', chunks[b'DMLM'], 32), (0xc, 0, 0, 1024))
|
|
self.assertAlmostEqual(struct.unpack_from('<f', chunks[b'XMLM'], 24)[0], 40.0, places=3)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|