screeps-simple-api
v1.0.3
Published
use screeps api simply
Downloads
2
Readme
screeps-simple-api
对 screeps 的 api 的简单封装
基本使用
更多 api 请见源码下 ScreepsApi.d.ts 文件
import { ScreepsApi } from 'screeps-simple-api'
import { ResourceConstant } from 'screeps-simple-api/dist/interface/resource'
// 传入邮箱密码进行登录
const api = new ScreepsApi({
// screeps官网注册的邮箱
email: '[email protected]',
// screeps官网登录密码
password: '000000',
})
// 下面是一些api示例
// 获取个人信息
api.getMyInfo().then((data) => {
console.log(data.gcl)
})
// 获取指定用户名信息
api.getUserInfoByUserName('keqing').then((data) => {
console.log(data.user.gcl)
})
// 获取房间对象信息
api.getRoomObject('E13S13', 'shard3').then((data) => {
// 比如统计房间中的资源
const resStat: { [type in ResourceConstant]?: number } = {}
for (const obj of data.objects) {
if (obj.type === 'storage' || obj.type == 'terminal') {
for (const resType in obj.store) {
const type = resType as ResourceConstant
resStat[type] = (resStat[type] || 0) + obj.store[type]
}
}
}
console.log(resStat)
})