Files
ft/CodexOutput/upserver/KVGameplayLoopTests/create_bindings.py

49 lines
2.7 KiB
Python

from pathlib import Path
import re,uuid
root=Path(__file__).resolve().parents[3]
src=root/'Client/Assets/Scripts/Services/PlayerData/PlayerKVEditorValidationHost.cs'
text=src.read_text(encoding='utf-8')
snapshot=text[text.index(' var snapshot=new PlayerKVSchemaSnapshot("local-full-4B2"'):]
snapshot=snapshot[:snapshot.index('\n ValidationContextAccess.Use')]
snapshot=snapshot.replace('var snapshot=', 'return ').replace('"local-full-4B2"','"kv-loop"').replace('new DateTime(2026,9,23,0,0,0,DateTimeKind.Utc)','nowUtc')
bindings=text[text.index(' var player=new GameCore.PlayerData(tables,null);'):]
bindings=bindings[:bindings.index('\n user.ConfigureKVForValidation')]
start=bindings.index(' var modules=')
declarations=bindings[:start]
declarations=re.sub(r'new ([\w.]+)\([^;]*?\)',lambda m:'Require<'+m[1]+'>()',declarations)
declarations=declarations.replace('var foot=Require<FootPrintService>()','var foot=Require<IFootPrintService>() as FootPrintService ?? throw new InvalidOperationException("M23 FootPrint binding mismatch.")')
declarations=declarations[:declarations.index(' var pinataTarget=')]+' var pinata=Require<EventPinataPackDataManager>(); var digging=Require<Script.RuntimeScript.DiggingGameManager>();\n'
body=bindings[start:].replace('transaction=new PlayerKVGameLoadTransaction','return new PlayerKVGameLoadTransaction')
code='''#if UNITY_EDITOR && !SERVICE_HOST
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using asap.core;
namespace game.PlayerDataStorage
{
// Bind the existing game container. Missing registrations fail closed; no parallel fixture objects.
internal static class PlayerKVGameplayBindings
{
static T Require<T>() where T:class => GContext.container.Resolve<T>() ??
throw new InvalidOperationException("KV game module is not registered: "+typeof(T).FullName);
internal static PlayerKVSchemaSnapshot Snapshot(DateTime nowUtc)
{
var tables=Require<cfg.Tables>();
'''+snapshot+'''
}
internal static PlayerKVGameLoadTransaction Bind(PlayFabUserService user)
{
'''+declarations+body+'''
}
}
}
#endif
'''
(src.parent/'PlayerKVGameplayBindings.cs').write_text(code,encoding='utf-8')
for rel in ['Scripts/Services/UserService.KVGameplayLoop.cs','Scripts/Services/PlayerData/PlayerKVGameplayBindings.cs','Editor/KVGameplayLoopSetup.cs']:
p=root/'Client/Assets'/ (rel+'.meta')
if not p.exists(): p.write_text('fileFormatVersion: 2\nguid: '+uuid.uuid4().hex+'\n',encoding='utf-8')
print('Created fixed bindings and new GUIDs; existing assets unchanged.')