screeps-connectivity 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/ScreepsClient.ts +1 -1
- package/src/index.ts +3 -0
- package/src/stores/MapStatsStore.ts +53 -14
- package/src/types/api.ts +21 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cc7f5be: Add `MapStatName`, `MapStatPrefix`, `MapStatInterval` const objects and `mapStat()` helper for typed map-stats API access; add `TerrainColors` interface and decoration fields to `MapStatsRoomData`; expose `MapStatsStoreEvents` and `statName` in room events.
|
|
8
|
+
|
|
9
|
+
Client: world map shard selector, "out of borders" black overlay, reveal-when-ready terrain/stats sync, mineral overlay on demand, room terrain decorations from player themes.
|
|
10
|
+
|
|
3
11
|
## 0.10.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/package.json
CHANGED
package/src/ScreepsClient.ts
CHANGED
|
@@ -83,7 +83,7 @@ export class ScreepsClient {
|
|
|
83
83
|
user: new UserStore(this.http, this.socket, this.cache, this.logger.child('user')),
|
|
84
84
|
server: new ServerStore(this.http, this.socket, this.cache, this.logger.child('server')),
|
|
85
85
|
map: new MapStore(this.socket, map2Storage, { maxSubscriptions: opts.map2?.maxSubscriptions ?? 500 }, this.logger.child('map')),
|
|
86
|
-
mapStats: new MapStatsStore(this.http, 100,
|
|
86
|
+
mapStats: new MapStatsStore(this.http, 100, 100, this.logger.child('mapStats')),
|
|
87
87
|
navigation: new NavigationStore(50, this.logger.child('navigation')),
|
|
88
88
|
}
|
|
89
89
|
|
package/src/index.ts
CHANGED
|
@@ -60,3 +60,6 @@ export type { UserStore } from './stores/UserStore.js'
|
|
|
60
60
|
export type { ServerStore } from './stores/ServerStore.js'
|
|
61
61
|
export type { MapStore, Map2Subscription, MapStoreOptions } from './stores/MapStore.js'
|
|
62
62
|
export type { NavigationStore, NavigationState, NavigationStoreEvents } from './stores/NavigationStore.js'
|
|
63
|
+
export { MapStatName, MapStatPrefix, MapStatInterval, mapStat } from './stores/MapStatsStore.js'
|
|
64
|
+
export type { MapStatsRoomData, MapStatsStoreEvents, TerrainColors } from './stores/MapStatsStore.js'
|
|
65
|
+
|
|
@@ -3,6 +3,41 @@ import type { Logger } from '../logger.js'
|
|
|
3
3
|
import type { HttpClient } from '../http/HttpClient.js'
|
|
4
4
|
import type { ApiMapStatsRoomStat, ApiMapStatsBadge } from '../types/api.js'
|
|
5
5
|
|
|
6
|
+
/** Fixed stat names for the map-stats API (no interval parameter). */
|
|
7
|
+
export const MapStatName = {
|
|
8
|
+
owner: 'owner0',
|
|
9
|
+
minerals: 'minerals0',
|
|
10
|
+
power: 'power0',
|
|
11
|
+
} as const
|
|
12
|
+
|
|
13
|
+
/** Stat name prefixes that take an interval suffix — combine with {@link MapStatInterval} via {@link mapStat}. */
|
|
14
|
+
export const MapStatPrefix = {
|
|
15
|
+
energyControl: 'energyControl',
|
|
16
|
+
energyHarvested: 'energyHarvested',
|
|
17
|
+
energyConstruction: 'energyConstruction',
|
|
18
|
+
energyCreeps: 'energyCreeps',
|
|
19
|
+
creepsProduced: 'creepsProduced',
|
|
20
|
+
creepsLost: 'creepsLost',
|
|
21
|
+
powerProcessed: 'powerProcessed',
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
/** Tick-bucket intervals supported by the Screeps API for parameterised stats. */
|
|
25
|
+
export const MapStatInterval = {
|
|
26
|
+
hour1: 8,
|
|
27
|
+
hours24: 180,
|
|
28
|
+
days7: 1440,
|
|
29
|
+
} as const
|
|
30
|
+
|
|
31
|
+
/** Build a parameterised stat name, e.g. `mapStat(MapStatPrefix.energyControl, MapStatInterval.hours24)` → `"energyControl180"`. */
|
|
32
|
+
export const mapStat = (prefix: string, interval: number): string => `${prefix}${interval}`
|
|
33
|
+
|
|
34
|
+
/** Custom terrain palette extracted from a room's active world-map decoration. */
|
|
35
|
+
export interface TerrainColors {
|
|
36
|
+
plain?: string // CSS color string, e.g. "#68DFFF"
|
|
37
|
+
swamp?: string
|
|
38
|
+
road?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
6
41
|
export interface MapStatsRoomData {
|
|
7
42
|
own?: { user: string; level: number }
|
|
8
43
|
mineral?: string
|
|
@@ -16,10 +51,12 @@ export interface MapStatsRoomData {
|
|
|
16
51
|
* response's user map and may be absent if the signer isn't included there.
|
|
17
52
|
*/
|
|
18
53
|
sign?: { user: string; text: string; datetime: number; username?: string; badge?: ApiMapStatsBadge }
|
|
54
|
+
/** Custom terrain colors from an active world-map decoration, if any. */
|
|
55
|
+
terrainColors?: TerrainColors
|
|
19
56
|
}
|
|
20
57
|
|
|
21
58
|
export interface MapStatsStoreEvents {
|
|
22
|
-
'mapStats:room': { room: string; shard: string | null; stat: MapStatsRoomData }
|
|
59
|
+
'mapStats:room': { room: string; shard: string | null; stat: MapStatsRoomData; statName: string }
|
|
23
60
|
}
|
|
24
61
|
|
|
25
62
|
interface PendingBatch {
|
|
@@ -79,15 +116,16 @@ export class MapStatsStore extends TypedStore<MapStatsStoreEvents> {
|
|
|
79
116
|
|
|
80
117
|
const userMap = res.users ?? {}
|
|
81
118
|
|
|
119
|
+
const shardKey = batch.shard === 'shard0' ? null : batch.shard
|
|
82
120
|
for (const [room, stat] of Object.entries(res.stats)) {
|
|
83
121
|
const data = this.buildData(stat, userMap)
|
|
84
|
-
this.emit('mapStats:room', { room, shard:
|
|
122
|
+
this.emit('mapStats:room', { room, shard: shardKey, stat: data, statName: batch.statName })
|
|
85
123
|
}
|
|
86
124
|
|
|
87
125
|
// Emit empty data for rooms that don't exist on server
|
|
88
126
|
for (const room of allRooms) {
|
|
89
127
|
if (!res.stats[room]) {
|
|
90
|
-
this.emit('mapStats:room', { room, shard:
|
|
128
|
+
this.emit('mapStats:room', { room, shard: shardKey, stat: {}, statName: batch.statName })
|
|
91
129
|
}
|
|
92
130
|
}
|
|
93
131
|
} catch (err) {
|
|
@@ -97,19 +135,19 @@ export class MapStatsStore extends TypedStore<MapStatsStoreEvents> {
|
|
|
97
135
|
}
|
|
98
136
|
|
|
99
137
|
private buildData(stat: ApiMapStatsRoomStat, userMap: Record<string, { username: string; badge: ApiMapStatsBadge }>): MapStatsRoomData {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
for (let i = 0; i < 3; i++) {
|
|
103
|
-
const mineralKey = `minerals${i}` as `minerals${number}`
|
|
104
|
-
const mineralData = stat[mineralKey]
|
|
105
|
-
if (mineralData) {
|
|
106
|
-
mineral = mineralData.type
|
|
107
|
-
density = mineralData.density
|
|
108
|
-
break
|
|
109
|
-
}
|
|
110
|
-
}
|
|
138
|
+
const mineral = stat.minerals0?.type
|
|
139
|
+
const density = stat.minerals0?.density
|
|
111
140
|
const ownerId = stat.own?.user
|
|
112
141
|
const signUserId = stat.sign?.user
|
|
142
|
+
|
|
143
|
+
// Find the terrain-theme decoration (world=true + floor/swamp color properties).
|
|
144
|
+
const terrainDeco = stat.decorations?.find(d => d.active.world && (d.active.floorBackgroundColor || d.active.swampColor))
|
|
145
|
+
const terrainColors: TerrainColors | undefined = terrainDeco ? {
|
|
146
|
+
plain: terrainDeco.active.floorBackgroundColor,
|
|
147
|
+
swamp: terrainDeco.active.swampColor,
|
|
148
|
+
road: terrainDeco.active.roadsColor,
|
|
149
|
+
} : undefined
|
|
150
|
+
|
|
113
151
|
return {
|
|
114
152
|
own: stat.own,
|
|
115
153
|
mineral,
|
|
@@ -127,6 +165,7 @@ export class MapStatsStore extends TypedStore<MapStatsStoreEvents> {
|
|
|
127
165
|
badge: signUserId ? userMap[signUserId]?.badge : undefined,
|
|
128
166
|
}
|
|
129
167
|
: undefined,
|
|
168
|
+
terrainColors,
|
|
130
169
|
}
|
|
131
170
|
}
|
|
132
171
|
}
|
package/src/types/api.ts
CHANGED
|
@@ -142,6 +142,25 @@ export interface ApiLeaderboardSeasonsResponse {
|
|
|
142
142
|
seasons: Array<{ _id: string; name: string; date: string }>
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
export interface ApiDecorationActive {
|
|
146
|
+
world?: boolean
|
|
147
|
+
tileScale?: number | string
|
|
148
|
+
// terrain theme
|
|
149
|
+
floorBackgroundColor?: string
|
|
150
|
+
floorForegroundColor?: string
|
|
151
|
+
floorForegroundAlpha?: string | number
|
|
152
|
+
swampColor?: string
|
|
153
|
+
swampStrokeColor?: string
|
|
154
|
+
roadsColor?: string
|
|
155
|
+
roadsBrightness?: number | string
|
|
156
|
+
// room overlay (not used on world map yet)
|
|
157
|
+
foregroundColor?: string
|
|
158
|
+
foregroundAlpha?: number | string
|
|
159
|
+
backgroundColor?: string
|
|
160
|
+
strokeColor?: string
|
|
161
|
+
[key: string]: unknown
|
|
162
|
+
}
|
|
163
|
+
|
|
145
164
|
export interface ApiMapStatsRoomStat {
|
|
146
165
|
status: string
|
|
147
166
|
novice: number | null
|
|
@@ -150,7 +169,8 @@ export interface ApiMapStatsRoomStat {
|
|
|
150
169
|
own?: { user: string; level: number }
|
|
151
170
|
sign?: { user: string; text: string; time: number; datetime: number }
|
|
152
171
|
safeMode?: boolean
|
|
153
|
-
|
|
172
|
+
minerals0?: { type: string; density: number }
|
|
173
|
+
decorations?: Array<{ _id: string; user: string; decoration: string; active: ApiDecorationActive }>
|
|
154
174
|
}
|
|
155
175
|
|
|
156
176
|
export interface ApiMapStatsBadge {
|