Files
joywayer 35216f75e7 feat: integrate room framework and isolated subgame bundles
Complete room UI and protocol integration, move game definitions and resources behind bundle entries, publish authoritative version XML, and document single-game builds. Include all current resource changes and experiment artifacts.
2026-09-09 03:13:18 +08:00

40 lines
4.1 KiB
JavaScript

import {readFileSync,writeFileSync} from 'node:fs';
const p='G:/Works/YouleGamesCocosCreator/cocoscreator_projects/YouleNexus/assets/scripts/platform-login/RoomChatPanel.ts';
let s=readFileSync(p,'utf8');
s=s.replace("import {BlockInputEvents,","import {Director,director,BlockInputEvents,");
s=s.replace("import {requireNode}","import {KeyedRows} from '../../framework/presentation/keyed-rows.ts';\nimport {requireNode}");
s=s.replace(' private historyUi:RoomUi;',` private readonly historyRows:KeyedRows<RoomSocialMessage,{node:Node;ui:RoomUi;index:number;message:RoomSocialMessage}>;
private pendingRender:(()=>void)|null=null;
private readonly flush=()=>{const render=this.pendingRender;this.pendingRender=null;render?.();};
private readonly visited=new Set<string>();`);
s=s.replace('this.ui=new RoomUi(actions.error);this.historyUi=new RoomUi(actions.error);this.root=this.ui.mount(prefab,canvas);',`this.ui=new RoomUi(actions.error);this.root=this.ui.mount(prefab,canvas);
this.historyRows=new KeyedRows({key:message=>message.id,create:(message,index)=>this.createHistoryRow(message,index),
update:(row,message,index)=>{if(row.message!==message){row.ui.dispose();Object.assign(row,this.createHistoryRow(message,index));}row.index=index;},remove:row=>{row.node.removeFromParent();row.ui.dispose();}});`);
s=s.replace("if(page==='History'||page==='Announcements')this.scroll(page).scrollToBottom(0);","if(!this.visited.has(page)&&(page==='History'||page==='Announcements'))this.scroll(page).scrollToBottom(0);this.visited.add(page);");
s=s.replace(' render(state:PlatformState,announcementAllowed:boolean,announcementCost:string):void{',` render(state:PlatformState,announcementAllowed:boolean,announcementCost:string):void{
if(this.pendingRender===null)director.once(Director.EVENT_BEFORE_DRAW,this.flush);
this.pendingRender=()=>this.renderState(state,announcementAllowed,announcementCost);
}
private renderState(state:PlatformState,announcementAllowed:boolean,announcementCost:string):void{`);
const start=s.indexOf(' private renderHistory('),end=s.indexOf(' private renderNews(',start);
let body=s.slice(start,end);
body=body.slice(body.indexOf(' const row='),body.indexOf(" });this.layout('History')"));
body=body.replaceAll('this.historyUi','ui').replace('const row=ui.mount(this.historyPrefab,content);row.name=`ChatHistoryItem_${index}`;',"const ui=new RoomUi(this.actions.error),row=ui.mount(this.historyPrefab,this.content('History'));row.name=`ChatHistoryItem_${message.id}`;\n const holder={node:row,ui,index,message};");
body=body.replace("roomNeed(message.voiceurl,'voice URL'),index)","roomNeed(message.voiceurl,'voice URL'),holder.index)");
const replacement=` private renderHistory(messages:readonly RoomSocialMessage[]):void{
const scroll=this.scroll('History'),offset=scroll.getScrollOffset(),follow=offset.y>=scroll.getMaxScrollOffset().y-2;
this.historyRows.render(messages);this.layout('History');
if(follow)scroll.scrollToBottom(0);else scroll.scrollToOffset(offset,0);
}
private createHistoryRow(message:RoomSocialMessage,index:number):{node:Node;ui:RoomUi;index:number;message:RoomSocialMessage}{
${body}
return holder;
}
`;
s=s.slice(0,start)+replacement+s.slice(end);
s=s.replace(" const content=this.content('Announcements');this.clear(content);"," const scroll=this.scroll('Announcements'),offset=scroll.getScrollOffset(),follow=offset.y>=scroll.getMaxScrollOffset().y-2;\n const content=this.content('Announcements');this.clear(content);");
s=s.replace("this.layout('Announcements');this.scroll('Announcements').scrollToBottom(0);","this.layout('Announcements');if(follow)scroll.scrollToBottom(0);else scroll.scrollToOffset(offset,0);");
s=s.replace("const row=this.content('History').getChildByName(`ChatHistoryItem_${index}`);","const message=this.history?.[index],row=message?this.historyRows.get(message.id)?.node:undefined;");
s=s.replace('dispose():void{this.historyUi.dispose();this.ui.dispose();}','dispose():void{director.off(Director.EVENT_BEFORE_DRAW,this.flush);this.pendingRender=null;try{this.historyRows.dispose();}finally{this.ui.dispose();}}');
writeFileSync(p,s);