screeps-simple-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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: '111111@outlook.com',
    // 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)
})

Readme

Keywords

Package Sidebar

Install

npm i screeps-simple-api

Weekly Downloads

5

Version

1.0.3

License

ISC

Unpacked Size

870 kB

Total Files

11

Last publish

Collaborators

  • lovekeqing