用户:
Nomen查看:0 回复:1 评论:0 创建时间:2024-01-01T08:22:18
这里是没有开场白的Nomen,我们将用一段简短的代码来模拟玩家获取个人数据并且展示在屏幕上,需要至少RemoteWrapper.js1.1.0和UiNodeWrapper.js1.1.0 服务端代码: //导入RSW,如果已有则不需要这一步 constRemoteServerWrapper=require("../../端连接/RemoteWrapper/1.1.0/Remote.server.js"); classWebApp{ /** *@param{RemoteServerWrapper}rms */ constructor(rms){ this.rms=rms; } get(path,f){ this.rms.onMessage("communicate",async(request,entity)=>{ if(request.path===path&&request.method==="GET"){ returnawaitf(request,entity); } }) } post(path,f){ this.rms.onMessage("communicate",async(request,entity)=>{ if(request.path===path&&request.method==="POST"){ returnawaitf(request,entity); } }) } } //开始监听端口80 letrms=newRemoteServerWrapper([],{ port:80 }); //创建一个模拟Web应用 letapp=newWebApp(rms); //监听/user/profile上的GET操作 app.get("/user/profile",async(request,entity)=>{ returnawaitGET_USER_PROFILE(entity);//返回了Promise{coin:10,photo:"uri",name:"Nomen"} }); //玩家状态变化时监听或取消监听 world.onPlayerJoin(({entity})=>{ rms.add(entity); }); world.onPlayerLeave(({entity})=>{ rms.cancel(entity); }); 客户端代码: //导入RCW,如果已有则不需要这一步 constRemoteClientWrapper=require("../../端连接/RemoteWrapper/1.1.0/Remote.client.js"); //初始化RCW constrcw=RemoteClientWrapper(80); //导入UiNodeWrapper,如果已有则不需要这一步 constUiNodeWrapper=require("UiWrapper.js").createUiNodeWrapper(); //配置uiWrapper constuiWrapper=newUiNodeWrapper(ui); //定义与一个fetch函数 functionfetch(path,content){ returnnewPromise(resolve=>{ rcw.communicate({path,...content},(v)=>{ resolve(v); }) }) } //由于服务端特性,我们需要先等待 setTimeout(()=>{ fetch("/user/profile",{ method:"GET", }).then(v=>{ //这里是设置数据在GUI上的显示 uiWrapper.findChildByName("coin") .config("textContent",v.coin); uiWrapper.findChildByName("photo") .config("image",v.photo); uiWrapper.findChildByName("name") .config("textContent",v.name); }) },1000)
Nomen逆天bcm五次吞我格式,试了十分钟摆烂了,直接看源码吧 github.com/helloyork/Box3-Tools/tree/main/src/%E6%A8%A1%E6%9D%BF%E4%BB%A3%E7%A0%81/%E7%AE%80%E6%98%93%E7%8E%A9%E5%AE%B6%E6%95%B0%E6%8D%AE%E9%80%9A%E4%BF%A1
点赞0
评论