|
楼主 |
发表于 2021-10-9 01:50:01
|
显示全部楼层
为机器人加入载具模式。
所谓载具,就是行走的工具。
默认的载具是run,快速移动,可以多步移动,直接发送命令。
一个额外的载具是go, 就是在发送命令前加入go,比如 go west,会过滤命令,不会多步移动。
另外引入一个赶车的载具cart,在发送命令前加入gan che to,比如gan che to west,会过滤命令,不会多步移动。
过滤命令是有一个替换列表,具体为
- (function(){
- return {
- "east": "%1east",
- "south": "%1south",
- "west": "%1west",
- "north": "%1north",
- "southeast": "%1southeast",
- "southwest": "%1southwest",
- "northeast": "%1northeast",
- "northwest": "%1northwest",
- "eastup": "%1eastup",
- "eastdown": "%1eastdown",
- "southup": "%1southup",
- "southdown": "%1southdown",
- "westup": "%1westup",
- "westdownwd": "%1westdown",
- "northup": "%1northup",
- "northdown": "%1northdown",
- "up": "%1up",
- "down": "%1down",
- "e": "%1east",
- "s": "%1south",
- "w": "%1west",
- "n": "%1north",
- "se": "%1southeast",
- "sw": "%1southwest",
- "ne": "%1northeast",
- "nw": "%1northwest",
- "eu": "%1eastup",
- "ed": "%1eastdown",
- "su": "%1southup",
- "sd": "%1southdown",
- "wu": "%1westup",
- "wd": "%1westdown",
- "nu": "%1northup",
- "nd": "%1northdown",
- "u": "%1up",
- "d": "%1down",
- "enter": "%1enter",
- "out": "%1out",
- "e·": "%1east",
- "s·": "%1south",
- "w·": "%1west",
- "n·": "%1north",
- "se·": "%1southeast",
- "sw·": "%1southwest",
- "ne·": "%1northeast",
- "nw·": "%1northwest",
- "eu·": "%1eastup",
- "ed·": "%1eastdown",
- "su·": "%1southup",
- "sd·": "%1southdown",
- "wu·": "%1westup",
- "wd·": "%1westdown",
- "nu·": "%1northup",
- "nd·": "%1northdown",
- "u·": "%1up",
- "d·": "%1down",
- "enter·": "%1enter",
- "out·": "%1out",
- "yell boat。":"yell boat",
- "#wait":"#wait"
- }
- })()
复制代码
载具的基础类是
- (function(app){
- let _drivepath=Include("include/drivepath.js")
- let Vehicle=function(){
- this.TagDrive=false
- this.MultiStep=false
- this.ID=""
- this.RetryInterval=0.5
- this.Fly=false
- this.Sender=function(cmd){
- app.Send(cmd)
- }
- }
- Vehicle.prototype.Send=function(cmd){
- this.Sender(cmd)
- }
- Vehicle.prototype.ConvertDrivePath=function(cmd,path){
- let p=_drivepath[path]
- if (!p){
- throw "无效的drivepath"+path
- }
- p=p.replace("%1",cmd)
- return p
- }
- return Vehicle
- })(App)
复制代码
默认的run
- (function (app) {
- let Vehicle = Include("core/vehicle/vehicle.js")
- let Run = function () {
- Vehicle.call(this)
- this.ID="run"
- this.MultiStep=true
- this.Fly=true
- }
- Run.prototype = Object.create(Vehicle.prototype)
- return Run
- })(App)
复制代码 额外的go
- (function (app) {
- let Vehicle = Include("core/vehicle/vehicle.js")
- let Go = function () {
- Vehicle.call(this)
- this.ID="go"
- this.TagDrive=true
- this.Sender=function(cmd){
- app.Send(this.ConvertDrivePath("go ",cmd))
- }
- }
- Go.prototype = Object.create(Vehicle.prototype)
- return Go
- })(App)
复制代码
额外的cart
- (function (app) {
- let Vehicle = Include("core/vehicle/vehicle.js")
- let Cart = function () {
- Vehicle.call(this)
- this.TagDrive=true
- this.ID="cart"
- this.Sender=function(cmd){
- app.Send(this.ConvertDrivePath("gan che to ",cmd))
- }
- }
- Cart.prototype = Object.create(Vehicle.prototype)
- return Cart
- })(App)
复制代码 全局引入 Drive方法切换载具,go方法发送前进命令
- let cart = Include("core/vehicle/cart.js")
- app.Vehicle=null
- app.Vehicles={
- Run:new run(),
- Go:new go(),
- Cart:new cart(),
- }
- app.Vehicle=app.Vehicles.Run
- app.Drive=function(id){
- if(id){
- for (let key in app.Vehicles) {
- if (app.Vehicles[key].ID == id){
- app.Vehicle=app.Vehicles[key]
- return
- }
- }
- throw "未知的载具 " +id
- }else{
- app.Vehicle=app.Vehicles.Run
- }
- }
- app.RegisterCallback("core.vehicle.inittags",function(){
- Mapper.settag("drive",app.Vehicle.TagDrive)
- })
- app.Bind("PathInit","core.vehicle.inittags")
- app.Go=function(cmd){
- app.Vehicle.Send(cmd)
- }
复制代码
并在移动模块里做相应调整。
同时#to命令支持设置载具
比如#to yzkd,#to go yzgc,#to cart yzyp
更新较多
详细内容见
https://github.com/hellclient-sc ... 7b48c313484bf9816fa
|
|