import sys,unittest,tempfile from pathlib import Path HERE=Path(__file__).resolve().parents[1];sys.path.insert(0,str(HERE)) import make_items as m READER=HERE.parents[3]/'metin2-server/src/server/db/src/ProtoReader.cpp' def row(vnum,t,st,anti='NONE',flags='NONE',wear='NONE',applies=('APPLY_NONE','0')*3,values=('0',)*6,refine=('0','0')): return [str(vnum),'x',t,st,'1',anti,flags,wear,'NONE','10','20',refine[0],refine[1],'0','LEVEL','120','LIMIT_NONE','0',*applies,*values,'0','0','-1',''] class UIAssetTests(unittest.TestCase): def test_private_v1_and_v2_atlas_closure(self): with tempfile.TemporaryDirectory() as tmp: assets=Path(tmp)/'assets';sources=Path(tmp)/'sources';sources.mkdir() a=sources/'properties.dds';a.write_bytes(b'AVA2 atlas') b=sources/'switchbot.tga';b.write_bytes(b'switchbot atlas') files={'d:/ymir work/ui/properties_01.dds':a,'d:/ymir work/ui/switchbot/switchbot.tga':b} v1=assets/'d:/ymir work/ui/game/attr6th7th/material_slot.sub';v1.parent.mkdir(parents=True) v1.write_bytes(b'version 1.0\nimage "properties_01.dds"\nleft 44\n') v2=assets/'d:/ymir work/ui/switchbot/btn.sub';v2.parent.mkdir(parents=True) v2.write_bytes(b'version 2.0\nimage "switchbot.tga"\nleft 0\n') base=assets/'d:/ymir work/ui/properties_01.dds';base.write_bytes(b'base atlas') m.pack_ui_subimages(assets,files) self.assertEqual(base.read_bytes(),b'base atlas') self.assertIn(b'image "ava2_native/properties_01.dds"',v1.read_bytes()) self.assertIn(b'version 1.0',v2.read_bytes()) self.assertEqual((assets/'d:/ymir work/ui/ava2_native/switchbot/switchbot.tga').read_bytes(),b'switchbot atlas') def test_missing_atlas_rejects_pack(self): with tempfile.TemporaryDirectory() as tmp: root=Path(tmp);(root/'a.sub').write_bytes(b'version 1.0\nimage "missing.dds"\n') with self.assertRaisesRegex(ValueError,'missing UI subimage atlas'):m.pack_ui_subimages(root,{}) @unittest.skipUnless(READER.is_file(),'needs ../metin2-server') class ConvertTests(unittest.TestCase): E=m.enums(READER) if READER.is_file() else None def test_weapon_kept_without_unknown_flags(self): s,c,kept=m.convert(row(320,'ITEM_WEAPON','WEAPON_SWORD','ANTI_MUDANG | ANTI_WOLFMAN','ITEM_TUNABLE','WEAR_WEAPON', ('APPLY_ATT_SPEED','18','APPLY_ATTBONUS_BOSS','5','APPLY_NONE','0'),refine=('321','81')),self.E,{320}) self.assertTrue(kept);self.assertEqual(s[5],'ANTI_MUDANG');self.assertEqual(s[7],'WEAR_WEAPON') self.assertEqual(s[18:22],['APPLY_ATT_SPEED','18','APPLY_ATTBONUS_BOSS','5']) # ported apply kept self.assertEqual(s[11:13],['0','0']) # the +1 item is not imported self.assertEqual(c[1:3],[self.E['type'].index('ITEM_WEAPON'),0]);self.assertEqual(c[4],1<