Skip to content

Commit dde1880

Browse files
authored
Add screenshot actions (#3)
* Added a few screenshot actions
1 parent 43d5b94 commit dde1880

3 files changed

Lines changed: 212 additions & 0 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ When Download type is Around the user, the offsets are the amount of entries aro
151151
| Activate Steam overlay to store | Activates the Steam Overlay to the Steam store page for the provided app | App ID *(number)* <br>Flag *(combo)* <br> |
152152
| Trigger screenshot (synchronous) | Captures the current screen and saves to Steam screenshot library (synchronous) | Tag *(string)* <br> |
153153
| Trigger screenshot | Captures the current screen and saves to Steam screenshot library | |
154+
| Save screenshot from URL (synchronous) | Saves an image from a URL as a Steam screenshot. The image will be loaded, converted to base64, and its dimensions calculated automatically. (synchronous) | URL *(string)* <br>Tag *(string)* <br> |
155+
| Save screenshot from URL | Saves an image from a URL as a Steam screenshot. The image will be loaded, converted to base64, and its dimensions calculated automatically. | URL *(string)* <br> |
156+
| Add screenshot to library (synchronous) | Adds an existing screenshot file to the Steam screenshot library. Returns the handle of the screenshot. (synchronous) | Filename *(string)* <br>Thumbnail Filename *(string)* <br>Width *(number)* <br>Height *(number)* <br>Tag *(string)* <br> |
157+
| Add screenshot to library | Adds an existing screenshot file to the Steam screenshot library. Returns the handle of the screenshot. | Filename *(string)* <br>Thumbnail Filename *(string)* <br>Width *(number)* <br>Height *(number)* <br> |
154158
| Check DLC is installed (synchronous) | Checks if the user owns and has installed a specific DLC (synchronous) | DLC App ID *(number)* <br>Tag *(string)* <br> |
155159
| Check DLC is installed | Checks if the user owns and has installed a specific DLC | DLC App ID *(number)* <br> |
156160
| Create workshop item (synchronous) | Creates a new workshop item for the specified Steam App ID and returns its ID (synchronous) | App ID *(number)* <br>Tag *(string)* <br> |
@@ -385,6 +389,14 @@ When Download type is Around the user, the offsets are the amount of entries aro
385389
| On any "TriggerScreenshot" success | Trigger when any of the "TriggerScreenshot" are executed with success. | |
386390
| On "TriggerScreenshot" error | Trigger when the "TriggerScreenshot" failed to execute. | Tag *(string)* <br> |
387391
| On any "TriggerScreenshot" error | Trigger when any of the "TriggerScreenshot" failed to execute. | |
392+
| On "SaveScreenshotFromURL" success | Trigger when the "SaveScreenshotFromURL" is executed with success. | Tag *(string)* <br> |
393+
| On any "SaveScreenshotFromURL" success | Trigger when any of the "SaveScreenshotFromURL" are executed with success. | |
394+
| On "SaveScreenshotFromURL" error | Trigger when the "SaveScreenshotFromURL" failed to execute. | Tag *(string)* <br> |
395+
| On any "SaveScreenshotFromURL" error | Trigger when any of the "SaveScreenshotFromURL" failed to execute. | |
396+
| On "AddScreenshotToLibrary" success | Trigger when the "AddScreenshotToLibrary" is executed with success. | Tag *(string)* <br> |
397+
| On any "AddScreenshotToLibrary" success | Trigger when any of the "AddScreenshotToLibrary" are executed with success. | |
398+
| On "AddScreenshotToLibrary" error | Trigger when the "AddScreenshotToLibrary" failed to execute. | Tag *(string)* <br> |
399+
| On any "AddScreenshotToLibrary" error | Trigger when any of the "AddScreenshotToLibrary" failed to execute. | |
388400
| On "CheckDLCIsInstalled" success | Trigger when the "CheckDLCIsInstalled" is executed with success. | Tag *(string)* <br> |
389401
| On any "CheckDLCIsInstalled" success | Trigger when any of the "CheckDLCIsInstalled" are executed with success. | |
390402
| On "CheckDLCIsInstalled" error | Trigger when the "CheckDLCIsInstalled" failed to execute. | Tag *(string)* <br> |
@@ -557,6 +569,10 @@ When Download type is Around the user, the offsets are the amount of entries aro
557569
| ActivateToStoreResult | The result of the "ActivateToStore last call" | string | |
558570
| TriggerScreenshotError | The error of the "TriggerScreenshot last call" | string | |
559571
| TriggerScreenshotResult | The result of the "TriggerScreenshot last call" | string | |
572+
| SaveScreenshotFromURLError | The error of the "SaveScreenshotFromURL last call" | string | |
573+
| SaveScreenshotFromURLResult | The result of the "SaveScreenshotFromURL last call" | string | |
574+
| AddScreenshotToLibraryError | The error of the "AddScreenshotToLibrary last call" | string | |
575+
| AddScreenshotToLibraryResult | The result of the "AddScreenshotToLibrary last call" | string | |
560576
| CheckDLCIsInstalledError | The error of the "CheckDLCIsInstalled last call" | string | |
561577
| CheckDLCIsInstalledResult | The result of the "CheckDLCIsInstalled last call" | string | |
562578
| CreateWorkshopItemError | The error of the "CreateWorkshopItem last call" | string | |

src/instance.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,115 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
23022302
_TriggerScreenshot = this._TriggerScreenshotBase
23032303
_TriggerScreenshotSync = this._TriggerScreenshotBase
23042304

2305+
// Save Screenshot from URL
2306+
_SaveScreenshotFromURLBase = this.wrap(super._SaveScreenshotFromURL, async (
2307+
/** @type {string} */ url,
2308+
/** @type {Tag} */ tag
2309+
) => {
2310+
try {
2311+
// Load the image from URL and convert to base64
2312+
const img = new Image();
2313+
img.crossOrigin = 'anonymous';
2314+
2315+
const imageLoaded = new Promise((resolve, reject) => {
2316+
img.onload = () => resolve(img);
2317+
img.onerror = (e) => reject(new Error('Failed to load image from URL'));
2318+
});
2319+
2320+
img.src = url;
2321+
await imageLoaded;
2322+
2323+
// Get dimensions
2324+
const width = img.naturalWidth;
2325+
const height = img.naturalHeight;
2326+
2327+
// Convert to base64 data URL
2328+
const canvas = document.createElement('canvas');
2329+
canvas.width = width;
2330+
canvas.height = height;
2331+
const ctx = canvas.getContext('2d');
2332+
if (!ctx) {
2333+
throw new Error('Failed to get canvas context');
2334+
}
2335+
ctx.drawImage(img, 0, 0);
2336+
const dataUrl = canvas.toDataURL('image/png');
2337+
2338+
const order = {
2339+
url: '/steam/screenshots/save',
2340+
body: {
2341+
dataUrl,
2342+
width,
2343+
height,
2344+
},
2345+
};
2346+
const answer = await this.ws?.sendAndWaitForResponse(order);
2347+
if (answer?.body.success === false) {
2348+
throw new Error(answer?.body.error || 'Failed to save screenshot')
2349+
}
2350+
this._SaveScreenshotFromURLResultValue = answer?.body.data ?? ''
2351+
this._SaveScreenshotFromURLErrorValue = ''
2352+
2353+
await this.trigger(tag, [
2354+
C3.Plugins.pipelabv2.Cnds.OnSaveScreenshotFromURLSuccess,
2355+
C3.Plugins.pipelabv2.Cnds.OnAnySaveScreenshotFromURLSuccess
2356+
])
2357+
} catch (e) {
2358+
if (e instanceof Error) {
2359+
this._SaveScreenshotFromURLErrorValue = e.message
2360+
this._SaveScreenshotFromURLResultValue = ''
2361+
await this.trigger(tag, [
2362+
C3.Plugins.pipelabv2.Cnds.OnSaveScreenshotFromURLError,
2363+
C3.Plugins.pipelabv2.Cnds.OnAnySaveScreenshotFromURLError
2364+
])
2365+
}
2366+
}
2367+
}, this.unsupportedEngine)
2368+
_SaveScreenshotFromURL = this._SaveScreenshotFromURLBase
2369+
_SaveScreenshotFromURLSync = this._SaveScreenshotFromURLBase
2370+
2371+
// Add Screenshot to Library
2372+
_AddScreenshotToLibraryBase = this.wrap(super._AddScreenshotToLibrary, async (
2373+
/** @type {string} */ filename,
2374+
/** @type {string} */ thumbnailFilename,
2375+
/** @type {number} */ width,
2376+
/** @type {number} */ height,
2377+
/** @type {Tag} */ tag
2378+
) => {
2379+
try {
2380+
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').SteamRaw<'screenshots', 'addScreenshotToLibrary'>, 'input'>} */
2381+
const order = {
2382+
url: '/steam/raw',
2383+
body: {
2384+
namespace: 'screenshots',
2385+
method: 'addScreenshotToLibrary',
2386+
args: [filename, thumbnailFilename || null, width, height],
2387+
},
2388+
};
2389+
const answer = await this.ws?.sendAndWaitForResponse(order);
2390+
if (answer?.body.success === false) {
2391+
throw new Error(answer?.body.error || 'Failed to add screenshot to library')
2392+
}
2393+
this._AddScreenshotToLibraryResultValue = answer?.body.data ?? -1
2394+
this._AddScreenshotToLibraryErrorValue = ''
2395+
2396+
await this.trigger(tag, [
2397+
C3.Plugins.pipelabv2.Cnds.OnAddScreenshotToLibrarySuccess,
2398+
C3.Plugins.pipelabv2.Cnds.OnAnyAddScreenshotToLibrarySuccess
2399+
])
2400+
} catch (e) {
2401+
if (e instanceof Error) {
2402+
this._AddScreenshotToLibraryErrorValue = e.message
2403+
this._AddScreenshotToLibraryResultValue = -1
2404+
await this.trigger(tag, [
2405+
C3.Plugins.pipelabv2.Cnds.OnAddScreenshotToLibraryError,
2406+
C3.Plugins.pipelabv2.Cnds.OnAnyAddScreenshotToLibraryError
2407+
])
2408+
}
2409+
}
2410+
}, this.unsupportedEngine)
2411+
_AddScreenshotToLibrary = this._AddScreenshotToLibraryBase
2412+
_AddScreenshotToLibrarySync = this._AddScreenshotToLibraryBase
2413+
23052414
// Steam DLC
23062415
_CheckDLCIsInstalledBase = this.wrap(super._CheckDLCIsInstalled, async (
23072416
/** @type {number} */ appId,
@@ -3566,6 +3675,16 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
35663675
_OnTriggerScreenshotError = this.wrap(super._OnTriggerScreenshotError, (/** @type {Tag} */ tag) => this._currentTag === tag)
35673676
_OnAnyTriggerScreenshotError = this.wrap(super._OnAnyTriggerScreenshotError, () => true)
35683677

3678+
_OnSaveScreenshotFromURLSuccess = this.wrap(super._OnSaveScreenshotFromURLSuccess, (/** @type {Tag} */ tag) => this._currentTag === tag)
3679+
_OnAnySaveScreenshotFromURLSuccess = this.wrap(super._OnAnySaveScreenshotFromURLSuccess, () => true)
3680+
_OnSaveScreenshotFromURLError = this.wrap(super._OnSaveScreenshotFromURLError, (/** @type {Tag} */ tag) => this._currentTag === tag)
3681+
_OnAnySaveScreenshotFromURLError = this.wrap(super._OnAnySaveScreenshotFromURLError, () => true)
3682+
3683+
_OnAddScreenshotToLibrarySuccess = this.wrap(super._OnAddScreenshotToLibrarySuccess, (/** @type {Tag} */ tag) => this._currentTag === tag)
3684+
_OnAnyAddScreenshotToLibrarySuccess = this.wrap(super._OnAnyAddScreenshotToLibrarySuccess, () => true)
3685+
_OnAddScreenshotToLibraryError = this.wrap(super._OnAddScreenshotToLibraryError, (/** @type {Tag} */ tag) => this._currentTag === tag)
3686+
_OnAnyAddScreenshotToLibraryError = this.wrap(super._OnAnyAddScreenshotToLibraryError, () => true)
3687+
35693688
_OnCheckDLCIsInstalledSuccess = this.wrap(super._OnCheckDLCIsInstalledSuccess, (/** @type {Tag} */ tag) => this._currentTag === tag)
35703689
_OnAnyCheckDLCIsInstalledSuccess = this.wrap(super._OnAnyCheckDLCIsInstalledSuccess, () => true)
35713690
_OnCheckDLCIsInstalledError = this.wrap(super._OnCheckDLCIsInstalledError, (/** @type {Tag} */ tag) => this._currentTag === tag)
@@ -4130,6 +4249,20 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
41304249
return this._TriggerScreenshotResultValue
41314250
})
41324251

4252+
_SaveScreenshotFromURLError = this.exprs(super._SaveScreenshotFromURLError, () => {
4253+
return this._SaveScreenshotFromURLErrorValue
4254+
})
4255+
_SaveScreenshotFromURLResult = this.exprs(super._SaveScreenshotFromURLResult, () => {
4256+
return this._SaveScreenshotFromURLResultValue
4257+
})
4258+
4259+
_AddScreenshotToLibraryError = this.exprs(super._AddScreenshotToLibraryError, () => {
4260+
return this._AddScreenshotToLibraryErrorValue
4261+
})
4262+
_AddScreenshotToLibraryResult = this.exprs(super._AddScreenshotToLibraryResult, () => {
4263+
return this._AddScreenshotToLibraryResultValue
4264+
})
4265+
41334266
_CheckDLCIsInstalledError = this.exprs(super._CheckDLCIsInstalledError, () => {
41344267
return this._CheckDLCIsInstalledErrorValue
41354268
})

src/pluginConfig.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,63 @@ const TriggerScreenshot = ACEGenerator("TriggerScreenshot", /** @type {const} */
12231223
description: "Captures the current screen and saves to Steam screenshot library",
12241224
}))
12251225

1226+
const SaveScreenshotFromURL = ACEGenerator("SaveScreenshotFromURL", /** @type {const} */({
1227+
category: "steam",
1228+
highlight: false,
1229+
deprecated: false,
1230+
params: [
1231+
{
1232+
id: 'url',
1233+
desc: "The URL of the image to save as a screenshot (will be converted to base64)",
1234+
name: "URL",
1235+
type: 'string',
1236+
initialValue: "\"\"",
1237+
}
1238+
],
1239+
listName: "Save screenshot from URL",
1240+
displayText: "Save screenshot from URL [b]{0}[/b]",
1241+
description: "Saves an image from a URL as a Steam screenshot. The image will be loaded, converted to base64, and its dimensions calculated automatically.",
1242+
}))
1243+
1244+
const AddScreenshotToLibrary = ACEGenerator("AddScreenshotToLibrary", /** @type {const} */({
1245+
category: "steam",
1246+
highlight: false,
1247+
deprecated: false,
1248+
params: [
1249+
{
1250+
id: 'filename',
1251+
desc: "The absolute path to the screenshot file on disk",
1252+
name: "Filename",
1253+
type: 'string',
1254+
initialValue: "\"\"",
1255+
},
1256+
{
1257+
id: 'thumbnailFilename',
1258+
desc: "Optional absolute path to a thumbnail file (leave empty for no thumbnail)",
1259+
name: "Thumbnail Filename",
1260+
type: 'string',
1261+
initialValue: "\"\"",
1262+
},
1263+
{
1264+
id: 'width',
1265+
desc: "The width of the screenshot in pixels",
1266+
name: "Width",
1267+
type: 'number',
1268+
initialValue: "0",
1269+
},
1270+
{
1271+
id: 'height',
1272+
desc: "The height of the screenshot in pixels",
1273+
name: "Height",
1274+
type: 'number',
1275+
initialValue: "0",
1276+
}
1277+
],
1278+
listName: "Add screenshot to library",
1279+
displayText: "Add screenshot [b]{0}[/b] to library (thumbnail: {1}, size: {2}x{3})",
1280+
description: "Adds an existing screenshot file to the Steam screenshot library. Returns the handle of the screenshot.",
1281+
}))
1282+
12261283
// Steam DLC
12271284
const CheckDLCIsInstalled = ACEGenerator("CheckDLCIsInstalled", /** @type {const} */({
12281285
category: "steam",
@@ -1789,6 +1846,8 @@ const Config = /** @type {const} */({
17891846
...ActivateToWebPage.actions,
17901847
...ActivateToStore.actions,
17911848
...TriggerScreenshot.actions,
1849+
...SaveScreenshotFromURL.actions,
1850+
...AddScreenshotToLibrary.actions,
17921851
...CheckDLCIsInstalled.actions,
17931852
...CreateWorkshopItem.actions,
17941853
...UpdateWorkshopItem.actions,
@@ -1856,6 +1915,8 @@ const Config = /** @type {const} */({
18561915
...ActivateToWebPage.conditions,
18571916
...ActivateToStore.conditions,
18581917
...TriggerScreenshot.conditions,
1918+
...SaveScreenshotFromURL.conditions,
1919+
...AddScreenshotToLibrary.conditions,
18591920
...CheckDLCIsInstalled.conditions,
18601921
...CreateWorkshopItem.conditions,
18611922
...UpdateWorkshopItem.conditions,
@@ -1994,6 +2055,8 @@ const Config = /** @type {const} */({
19942055
...ActivateToWebPage.expressions,
19952056
...ActivateToStore.expressions,
19962057
...TriggerScreenshot.expressions,
2058+
...SaveScreenshotFromURL.expressions,
2059+
...AddScreenshotToLibrary.expressions,
19972060
...CheckDLCIsInstalled.expressions,
19982061
...CreateWorkshopItem.expressions,
19992062
...UpdateWorkshopItem.expressions,

0 commit comments

Comments
 (0)