feat: port native AVA2 chest preview and CG235 pickup flows
This commit is contained in:
@@ -111,7 +111,7 @@ def names():
|
||||
for grade,suffix in enumerate(('普通','精致','高级','个人')):
|
||||
result[base+grade]=label+'披风('+suffix+')'
|
||||
for v in sorted(STONE_IDS):result[v]=stone_name(v)
|
||||
result.update({50348:'属性锁定符',50349:'属性解锁符'})
|
||||
result.update({50348:'属性锁定符',50349:'属性解锁符',70002:'第三只手'})
|
||||
for month in range(1,13):result[25149+month]='%d月战令票'%month
|
||||
return result
|
||||
|
||||
@@ -122,7 +122,8 @@ def convert(cols,E,imported):
|
||||
kept=t in KEEP_TYPES or (t,st) in KEEP_SUBTYPES or ((t,st)==('ITEM_USE','USE_CHANGE_ATTRIBUTE') and
|
||||
any(lo<=int(c[0])<=hi for lo,hi in ENCHANT_KEEP)) or (
|
||||
(t,st) in (('ITEM_USE','USE_CHANGE_ATTRIBUTE'),('ITEM_USE','USE_ADD_ATTRIBUTE')) and int(c[0]) in PENDANT_SCROLLS) or (
|
||||
int(c[0]) in (50348,50349) and (t,st)==('ITEM_USE','USE_CHANGE_ATTRIBUTE'))
|
||||
int(c[0]) in (50348,50349) and (t,st)==('ITEM_USE','USE_CHANGE_ATTRIBUTE')) or (
|
||||
int(c[0])==70002 and (t,st)==('ITEM_USE','USE_SPECIAL'))
|
||||
if stone_lock_reason(c,E):kept=False
|
||||
anti=tokens(c[5]);flags=tokens(c[6])
|
||||
if 'ITEM_STACKABLE' in anti:anti.remove('ITEM_STACKABLE');flags.append('ITEM_STACKABLE')
|
||||
@@ -184,6 +185,27 @@ def pack_index(pack_maker):
|
||||
index.setdefault(archived.lower().replace('\\','/'),pack_maker.parent/source)
|
||||
return index
|
||||
|
||||
def pack_ui_subimages(assets,files):
|
||||
"""Resolve original v1 subimage atlases under a private path; never replace the base UI atlas."""
|
||||
root='d:/ymir work/ui/'
|
||||
for sub in list(assets.rglob('*.sub')):
|
||||
text=sub.read_bytes()
|
||||
match=re.search(rb'(?im)^image\s+"([^"\r\n]+)"',text)
|
||||
if not match:continue
|
||||
image=match[1].decode('latin1').lower().replace('\\','/')
|
||||
version=re.search(rb'(?im)^version\s+(\S+)',text)
|
||||
parent=sub.relative_to(assets).as_posix().rsplit('/',1)[0]+'/'
|
||||
source=image if image.startswith('d:/') else (parent if version and version[1]==b'2.0' else root)+image
|
||||
# AVA2 v1 images resolve against the global UI search path.
|
||||
if source not in files:raise ValueError('missing UI subimage atlas %s for %s'%(source,sub))
|
||||
alias='ava2_native/'+source[len(root):] if source.startswith(root) else 'ava2_native/'+source.rsplit('/',1)[-1]
|
||||
target=assets/(root+alias);target.parent.mkdir(parents=True,exist_ok=True)
|
||||
if not target.exists():shutil.copy2(files[source],target)
|
||||
# v1's image is relative to the global UI search path.
|
||||
updated=text[:match.start(1)]+alias.encode('ascii')+text[match.end(1):]
|
||||
updated=re.sub(rb'(?im)^version\s+\S+',b'version 1.0',updated)
|
||||
sub.write_bytes(updated)
|
||||
|
||||
def server_proto(ava,filename):
|
||||
path=ava/'2. Backup SF+SRC and SQL/home/srv1/db'/filename
|
||||
if path.is_file():return path.read_bytes()
|
||||
@@ -246,6 +268,25 @@ def prepare(ava,proto_reader,locale,output,tool,packer,wrap=lambda text:text):
|
||||
if q not in files:raise SystemExit('missing AVA2 asset %s'%q)
|
||||
target=assets/q;target.parent.mkdir(parents=True,exist_ok=True)
|
||||
if not target.exists():shutil.copy2(files[q],target);copied+=1
|
||||
# AVA2 native chest preview layout, including all referenced images.
|
||||
layout=pack_maker/'uiscript/uiscript/chestdropinfowindow.py'
|
||||
layout_text=layout.read_text().replace('"thinboard_circle"','"thinboard"')
|
||||
layout_target=assets/'uiscript/chestdropinfowindow.py'
|
||||
layout_target.parent.mkdir(parents=True,exist_ok=True)
|
||||
layout_target.write_text(layout_text)
|
||||
chest_prefixes=('d:/ymir work/ui/pattern/border_a_', 'd:/ymir work/ui/game/attr6th7th/',
|
||||
'd:/ymir work/ui/public/public_intro_btn/')
|
||||
for q in files:
|
||||
if q.startswith(chest_prefixes):
|
||||
target=assets/q;target.parent.mkdir(parents=True,exist_ok=True)
|
||||
if not target.exists():shutil.copy2(files[q],target);copied+=1
|
||||
pickup_layout=pack_maker/'uiscript/uiscript/game_option_0_1.py'
|
||||
(assets/'uiscript/game_option_0_1.py').write_bytes(pickup_layout.read_bytes())
|
||||
for q in files:
|
||||
if q.startswith('d:/ymir work/ui/game/gameoption/') or q in ('icon/item/70002.tga','d:/ymir work/ui/game/farm/premium_pickup.tga'):
|
||||
target=assets/q;target.parent.mkdir(parents=True,exist_ok=True)
|
||||
if not target.exists():shutil.copy2(files[q],target);copied+=1
|
||||
pack_ui_subimages(assets,files)
|
||||
(output/'items-server.tsv').write_bytes(b'\n'.join(server)+b'\n')
|
||||
(output/'items-client.tsv').write_bytes(b'\n'.join(client)+b'\n')
|
||||
mobs={}
|
||||
@@ -272,7 +313,8 @@ def prepare(ava,proto_reader,locale,output,tool,packer,wrap=lambda text:text):
|
||||
if v in STONE_IDS:
|
||||
desc=stone_lock_reason(rows[v],E) or ('可镶嵌到%s的空孔中。必定成功,每次消耗1颗;同类灵石不能重复镶嵌。'%('武器或铠甲' if 'WEAR_BODY' in rows[v][7] and 'WEAR_WEAPON' in rows[v][7] else '铠甲' if 'WEAR_BODY' in rows[v][7] else '武器'))
|
||||
if v==28960:desc='镶嵌失败留下的碎石,不能作为普通灵石镶嵌。'
|
||||
if v==50348:desc='装备有5条普通属性时,可锁定其中一条;最多锁定2组。每次消耗1张。'
|
||||
if v==70002:desc='激活第三只手30天;重复激活不会消耗道具。拾取分类可在拾取设置中调整。'
|
||||
elif v==50348:desc='装备有5条普通属性时,可锁定其中一条;最多锁定2组。每次消耗1张。'
|
||||
elif v==50349:desc='解除装备上的属性锁定,每次消耗1张。'
|
||||
elif 25150<=v<=25161:desc='仅限对应月份激活战令,确认后消耗;激活后开始累计任务进度。'
|
||||
result.append(('%d\t%s\t%s'%(v,zh[v],wrap(desc) if desc else '')).encode('gbk'))
|
||||
@@ -287,7 +329,7 @@ def prepare(ava,proto_reader,locale,output,tool,packer,wrap=lambda text:text):
|
||||
'source_applies':rows[v][18:24],'source_values':rows[v][24:30],
|
||||
'source_wear':rows[v][7]} for v in sorted(STONE_IDS)]}
|
||||
(output/'stones.json').write_text(json.dumps(stone_report,ensure_ascii=False,indent=2)+'\n')
|
||||
report['assets']=copied
|
||||
report['assets']=sum(1 for path in assets.rglob('*') if path.is_file())
|
||||
(output/'items.json').write_text(json.dumps(report,indent=1)+'\n')
|
||||
return report
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import sys,unittest
|
||||
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
|
||||
@@ -7,6 +7,28 @@ 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
|
||||
@@ -142,8 +164,13 @@ class ConvertTests(unittest.TestCase):
|
||||
self.assertTrue(kept);self.assertEqual(server[24],str(month));self.assertEqual(client[23],month)
|
||||
|
||||
|
||||
def test_premium_pickup_consumable(self):
|
||||
s,c,kept=m.convert(row(70002,'ITEM_USE','USE_SPECIAL',values=('60','0','0','0','0','0')),self.E,{70002})
|
||||
self.assertTrue(kept);self.assertEqual(s[2:4],['ITEM_USE','USE_SPECIAL'])
|
||||
self.assertEqual(m.names()[70002],'第三只手')
|
||||
|
||||
def test_names_cover_ranges(self):
|
||||
n=m.names();self.assertEqual(len(n),518+6*200+4*9+14+12+136);self.assertEqual(n[54100],'武器外观强化石')
|
||||
n=m.names();self.assertEqual(len(n),518+6*200+4*9+14+12+136+1);self.assertEqual(n[54100],'武器外观强化石')
|
||||
self.assertEqual([n[v] for v in (21210,21219,21279)],['暗龙铠甲+0','暗龙铠甲+9','神龙铠甲+9'])
|
||||
self.assertTrue(all(len(v.encode('gbk'))<=24 for v in n.values()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user