@hagicode/steamworks.js 0.2.1-dev.1 → 0.3.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/README.md +27 -1
- package/client.d.ts +84 -1
- package/dist/linux64/steamworksjs.linux-x64-gnu.node +0 -0
- package/dist/osx/steamworksjs.darwin-arm64.node +0 -0
- package/dist/osx/steamworksjs.darwin-x64.node +0 -0
- package/dist/win64/steamworksjs.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -437,7 +437,7 @@ client.friends.clearRichPresence()
|
|
|
437
437
|
|
|
438
438
|
## Stats, Achievements and Leaderboards
|
|
439
439
|
|
|
440
|
-
`stats` gains float stats, the achievement count and a request for another user's stats. `achievement` gains global unlock percentages. The `leaderboard` namespace finds and creates leaderboards, uploads scores and downloads entries.
|
|
440
|
+
`stats` gains float stats, the achievement count and a request for another user's stats. `achievement` gains global unlock percentages and the data an achievement page needs: display name, description, hidden flag, unlock time, progress limits and icon. The `leaderboard` namespace finds and creates leaderboards, uploads scores and downloads entries.
|
|
441
441
|
|
|
442
442
|
```js
|
|
443
443
|
const steamworks = require('steamworks.js')
|
|
@@ -464,6 +464,32 @@ if (board) {
|
|
|
464
464
|
- The Promise-returning functions (`requestGlobalPercentages`, `find`, `findOrCreate`, `uploadScore`, `downloadEntries`) resolve when Steam answers. Steam delivers those answers inside `runCallbacks()`. `init()` runs it about 30 times a second, so you do not need to call it yourself while the client is initialized.
|
|
465
465
|
- A Promise rejects with a readable message when Steam reports a failure. When the answer is lost, the message says the outcome is unknown, so check the data before retrying an upload.
|
|
466
466
|
|
|
467
|
+
### Achievement display data
|
|
468
|
+
|
|
469
|
+
`achievement.getAll()` and `achievement.getInfo(name)` return what a client needs to list achievements. Call `requestGlobalPercentages()` first to fill `globalPercent`.
|
|
470
|
+
|
|
471
|
+
```js
|
|
472
|
+
await client.achievement.requestGlobalPercentages()
|
|
473
|
+
|
|
474
|
+
for (const item of client.achievement.getAll()) {
|
|
475
|
+
// item: { name, displayName?, description?, hidden?, unlocked, unlockTime?, globalPercent?, progressLimits? }
|
|
476
|
+
const when = item.unlockTime === undefined ? null : new Date(item.unlockTime * 1000)
|
|
477
|
+
console.log(item.displayName ?? item.name, item.unlocked, when, item.globalPercent)
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Icon as raw RGBA pixels; loadIcon waits for Steam to fetch it, getIcon does not
|
|
481
|
+
const icon = await client.achievement.loadIcon('FIRST_RUN', 3000) // { width, height, rgba: Buffer } or null
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
- `unlockTime` is in seconds since 1970-01-01 UTC. It is left out for a locked achievement and for unlocks that Steam has no time for (Steam reports `0` for unlocks before December 2009).
|
|
485
|
+
- `displayName`, `description` and `hidden` come from Steam's localized achievement data. They are left out when Steam has no data, for example before the user's stats have arrived.
|
|
486
|
+
- `getInfo` returns `null` when Steam cannot read the achievement (unknown name, stats not received). That is a failed lookup, not a locked achievement. `getAll` skips such entries, so compare its length with `stats.getNumAchievements()`.
|
|
487
|
+
- `names()` returns an empty array when the app defines no achievements instead of throwing.
|
|
488
|
+
- `progressLimits` (also `getProgressLimits(name)`) gives the min and max of the stat that Steam links to the achievement, or is left out when there is none. Steam's achievement API does not return the current value: read the linked stat with `stats.getInt` or `stats.getFloat`.
|
|
489
|
+
- `indicateProgress(name, current, max)` shows the Steam overlay progress notice. It never unlocks the achievement.
|
|
490
|
+
- `getIcon` and `loadIcon` return `null` while Steam has not fetched the icon and when the achievement has no icon. Steam picks the locked or unlocked artwork from the user's state. Convert the RGBA pixels to PNG on your side if you need a file.
|
|
491
|
+
- Not verified against a live Steam client in this checkout: only the export list and the TypeScript declarations are tested offline.
|
|
492
|
+
|
|
467
493
|
## Networking: `networking` and the New Namespaces
|
|
468
494
|
|
|
469
495
|
Two families of networking APIs coexist. The `networking` namespace is the original P2P packet API (`sendP2PPacket`, `readP2PPacket`, `acceptP2PSession`), and it is unchanged. The new `networkingSockets`, `networkingMessages` and `networkingUtils` namespaces wrap Steam's Networking Sockets, Networking Messages and Networking Utils interfaces.
|
package/client.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export declare namespace achievement {
|
|
|
54
54
|
export function clear(achievement: string): boolean
|
|
55
55
|
/**
|
|
56
56
|
* Returns the API names of all achievements defined for the app. Needs `init()`.
|
|
57
|
-
*
|
|
57
|
+
* Returns an empty array when the app defines no achievements or Steam has no list yet, so an empty result can mean either; use `getNumAchievements()` on `stats` to tell "not loaded" from a count.
|
|
58
58
|
* @returns the achievement API names defined for the app.
|
|
59
59
|
*/
|
|
60
60
|
export function names(): Array<string>
|
|
@@ -68,6 +68,89 @@ export declare namespace achievement {
|
|
|
68
68
|
* Call `requestGlobalPercentages()` first.
|
|
69
69
|
*/
|
|
70
70
|
export function getAchievedPercent(achievement: string): number | null
|
|
71
|
+
/** The bounds of the progress stat that Steam links to an achievement. */
|
|
72
|
+
export interface AchievementProgressLimits {
|
|
73
|
+
/** Lowest value of the linked stat. */
|
|
74
|
+
min: number
|
|
75
|
+
/** Value of the linked stat at which the achievement is complete. */
|
|
76
|
+
max: number
|
|
77
|
+
/** `true` when the linked stat is a float stat, `false` when it is an integer stat. */
|
|
78
|
+
isFloat: boolean
|
|
79
|
+
}
|
|
80
|
+
/** Everything Steam knows about one achievement for the local user, ready for display. */
|
|
81
|
+
export interface AchievementInfo {
|
|
82
|
+
/** The achievement API name as configured in Steamworks. */
|
|
83
|
+
name: string
|
|
84
|
+
/** Localized display name, or left out (`undefined`) when Steam has none (stats not received, or the achievement is not published). */
|
|
85
|
+
displayName?: string
|
|
86
|
+
/** Localized description, or left out when Steam has none. Steam may return a placeholder text for hidden achievements that are still locked. */
|
|
87
|
+
description?: string
|
|
88
|
+
/** `true` for a hidden achievement, left out when Steam does not say. */
|
|
89
|
+
hidden?: boolean
|
|
90
|
+
/** Whether the local user has unlocked the achievement. */
|
|
91
|
+
unlocked: boolean
|
|
92
|
+
/** When the achievement was unlocked, in seconds since 1970-01-01 UTC (multiply by 1000 for `new Date()`). left out when the achievement is locked or Steam has no time for it. Steam reports `0` for unlocks before December 2009, which is also left out. */
|
|
93
|
+
unlockTime?: number
|
|
94
|
+
/** Global percentage of players who unlocked it (0 to 100). left out until `requestGlobalPercentages()` has resolved, or when Steam has no data (always for AppId 480). */
|
|
95
|
+
globalPercent?: number
|
|
96
|
+
/** Bounds of the progress stat linked to the achievement, or left out when the achievement has none. */
|
|
97
|
+
progressLimits?: AchievementProgressLimits
|
|
98
|
+
}
|
|
99
|
+
/** An achievement icon as raw pixels. */
|
|
100
|
+
export interface AchievementIcon {
|
|
101
|
+
/** Width in pixels. */
|
|
102
|
+
width: number
|
|
103
|
+
/** Height in pixels. */
|
|
104
|
+
height: number
|
|
105
|
+
/** `width * height * 4` bytes of RGBA, row by row. */
|
|
106
|
+
rgba: Buffer
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reads everything needed to display one achievement: name, description, hidden flag, unlocked state, unlock time, global percentage and progress limits. Needs `init()`, which requests the user's stats.
|
|
110
|
+
* Call `requestGlobalPercentages()` first to get `globalPercent`; the icon is read separately with `getIcon()`.
|
|
111
|
+
* @param achievement - The achievement API name as configured in Steamworks.
|
|
112
|
+
* @returns the achievement, or `null` when Steam cannot read it (unknown name, or stats not received yet). That failure is not the same as a locked achievement.
|
|
113
|
+
*/
|
|
114
|
+
export function getInfo(achievement: string): AchievementInfo | null
|
|
115
|
+
/**
|
|
116
|
+
* Reads every achievement the app defines, in the order Steam lists them. Same data as `getInfo()` per entry.
|
|
117
|
+
* An achievement Steam cannot read is skipped, so compare the length with `stats.getNumAchievements()` to detect missing entries. Returns an empty array when the app defines no achievements or the stats are not loaded.
|
|
118
|
+
* Call `requestGlobalPercentages()` first to fill `globalPercent`.
|
|
119
|
+
*/
|
|
120
|
+
export function getAll(): Array<AchievementInfo>
|
|
121
|
+
/**
|
|
122
|
+
* Returns when the user unlocked an achievement.
|
|
123
|
+
* @param achievement - The achievement API name as configured in Steamworks.
|
|
124
|
+
* @returns seconds since 1970-01-01 UTC, or `null` when the achievement is locked, Steam has no time for it, or the lookup fails.
|
|
125
|
+
*/
|
|
126
|
+
export function getUnlockTime(achievement: string): number | null
|
|
127
|
+
/**
|
|
128
|
+
* Returns the bounds of the progress stat that Steam links to an achievement. The current value of that stat is not part of the achievement API; read it with `stats.getInt()` or `stats.getFloat()` using the stat name from the Steamworks configuration.
|
|
129
|
+
* @param achievement - The achievement API name as configured in Steamworks.
|
|
130
|
+
* @returns the limits, or `null` when the achievement has no linked progress stat or the lookup fails.
|
|
131
|
+
*/
|
|
132
|
+
export function getProgressLimits(achievement: string): AchievementProgressLimits | null
|
|
133
|
+
/**
|
|
134
|
+
* Shows the Steam overlay progress notification for an achievement. It does not unlock the achievement, even when `current` equals `max`; call `activate()` for that.
|
|
135
|
+
* @param achievement - The achievement API name as configured in Steamworks.
|
|
136
|
+
* @param current - the progress reached
|
|
137
|
+
* @param max - the progress that completes the achievement
|
|
138
|
+
* @returns `true` when Steam accepted the request, otherwise `false`.
|
|
139
|
+
*/
|
|
140
|
+
export function indicateProgress(achievement: string, current: number, max: number): boolean
|
|
141
|
+
/**
|
|
142
|
+
* Reads the icon of an achievement as raw RGBA pixels, unlocked or locked according to the user's state (Steam chooses).
|
|
143
|
+
* @param achievement - The achievement API name as configured in Steamworks.
|
|
144
|
+
* @returns the icon, or `null` while Steam has not fetched it yet or when the achievement has no icon. Use `loadIcon()` to wait for it.
|
|
145
|
+
*/
|
|
146
|
+
export function getIcon(achievement: string): AchievementIcon | null
|
|
147
|
+
/**
|
|
148
|
+
* Like `getIcon()`, but waits for Steam to fetch the icon. Steam answers inside `runCallbacks()`, which `init()` already runs on a timer.
|
|
149
|
+
* @param achievement - The achievement API name as configured in Steamworks.
|
|
150
|
+
* @param timeoutMs - how long to wait, in milliseconds; defaults to 5000
|
|
151
|
+
* @returns the icon, or `null` when it is still missing after the timeout (no icon is set, or Steam is slow). The two cases cannot be told apart.
|
|
152
|
+
*/
|
|
153
|
+
export function loadIcon(achievement: string, timeoutMs?: number | undefined | null): Promise<AchievementIcon | null>
|
|
71
154
|
}
|
|
72
155
|
export declare namespace apps {
|
|
73
156
|
/**
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|