Skip to content

Commit 58da2fe

Browse files
committed
feat(plugin): add SDK v1 and v2 compatibility with config handling
- Update build.js to include config JSON replacement - Enhance instance.js with SDK version detection, unified DOM methods, and load promises - Add version logging and initialization checks
1 parent 475a6b1 commit 58da2fe

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A plugin that integrate with Pipelab <br>
55
Author: Armaldio <br>
66
Website: https://github.com/CynToolkit/construct-plugin <br>
77
Addon Url: https://github.com/CynToolkit/construct-plugin <br>
8-
Download Latest Version : [Version: 2.1.2](https://github.com/CynToolkit/construct-plugin/releases/latest) <br>
8+
Download Latest Version : [Version: 2.1.3](https://github.com/CynToolkit/construct-plugin/releases/latest) <br>
99
<sub>Made using [c3ide2-framework](https://github.com/ConstructFund/c3ide2-framework) </sub><br>
1010

1111
## Table of Contents

build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ try {
573573
const pluginWithPluginInfo = plugin
574574
.replaceAll("//<-- PLUGIN_INFO -->", pluginPluginInfo)
575575
.replaceAll("//<-- INSTANCE -->", instance)
576+
.replaceAll("//<-- CONFIG -->", `config = ${JSON.stringify(config, undefined, 2)}`)
576577
.replaceAll("//<-- DOM_COMPONENT_ID -->", `DOM_COMPONENT_ID = "${config.id}";`)
577578
.replaceAll("//<-- C3_INSTANCE -->", `const C3 = ${sdk === 'v1' ? 'self' : 'globalThis'}.C3;`)
578579
.replaceAll("//<-- SDK_VERSION -->", `sdk = "${sdk}"`)

src/instance.js

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ const defaultSteamId = {
215215
let DOM_COMPONENT_ID = ''
216216
//<-- DOM_COMPONENT_ID -->
217217

218+
let config = {}
219+
//<-- CONFIG -->
220+
221+
218222
/**
219223
* @typedef {string | undefined} Tag
220224
*/
@@ -223,6 +227,8 @@ let DOM_COMPONENT_ID = ''
223227
export function getInstanceJs(parentClass, addonTriggers, C3) {
224228
// @ts-ignore
225229
return class Pipelab extends parentClass {
230+
_additionalLoadPromises = []
231+
226232
/** @type {SDK.IObjectInstance | undefined} */
227233
_inst;
228234

@@ -349,6 +355,9 @@ export function getInstanceJs(parentClass, addonTriggers, C3) {
349355
* @param {any} _properties
350356
*/
351357
constructor(inst, _properties) {
358+
console.info('Pipelab v' + config.version)
359+
console.info('SDK ' + sdk)
360+
352361
let dummyInst = undefined
353362
if (sdk === 'v1') {
354363
dummyInst = inst
@@ -379,8 +388,38 @@ export function getInstanceJs(parentClass, addonTriggers, C3) {
379388
this._trigger = this.Trigger;
380389
}
381390

382-
this.runtime.sdk.addLoadPromise(
383-
this._postToDOMAsync("get-fullscreen-state")
391+
if (sdk === "v1") {
392+
this.c3runtime = this._runtime
393+
} else {
394+
this.c3runtime = this.runtime
395+
}
396+
397+
if (sdk === "v1") {
398+
this.addLoadPromise = this.c3runtime.AddLoadPromise
399+
} else {
400+
this.addLoadPromise = this.c3runtime.sdk.addLoadPromise
401+
}
402+
403+
if (sdk === "v1") {
404+
this.postToDOMAsync = this.PostToDOMAsync
405+
} else {
406+
this.postToDOMAsync = this._postToDOMAsync
407+
}
408+
409+
if (sdk === "v1") {
410+
this.postToDOM = this.PostToDOM
411+
} else {
412+
this.postToDOM = this._postToDOM
413+
}
414+
415+
if (sdk === "v1") {
416+
this.addDOMMessageHandler = this.AddDOMMessageHandler
417+
} else {
418+
this.addDOMMessageHandler = this._addDOMMessageHandler
419+
}
420+
421+
this?.addLoadPromise?.(
422+
this.postToDOMAsync("get-fullscreen-state")
384423
.then(
385424
/** @type {import("./sdk.js").PostFullscreenState} */
386425
data =>
@@ -389,7 +428,7 @@ export function getInstanceJs(parentClass, addonTriggers, C3) {
389428
})
390429
);
391430

392-
this._addDOMMessageHandler('fullscreen-state-changed', (data) => {
431+
this.addDOMMessageHandler('fullscreen-state-changed', (data) => {
393432
this._fullscreenState = data.state
394433
})
395434
}
@@ -427,6 +466,10 @@ export function getInstanceJs(parentClass, addonTriggers, C3) {
427466
wrap(base, callback, fallback, force) {
428467
// @ts-expect-error
429468
return (/** @type {Parameters<T>} */ ...args) => {
469+
if (!this._isInitialized) {
470+
console.warn("Plugin has no been initialized. Please use the according action at the start of layout")
471+
}
472+
430473
// is initialized
431474
if (this._isInitialized) {
432475
// and is connected to an engine
@@ -980,12 +1023,12 @@ export function getInstanceJs(parentClass, addonTriggers, C3) {
9801023
await this.ws?.sendAndWaitForResponse(order)
9811024
}, (toggle) => {
9821025
// Use DOM handler for fullscreen operations
983-
if (this.runtime.platformInfo.exportType === 'preview') {
1026+
if (this.c3runtime.platformInfo.exportType === 'preview') {
9841027
/** @type {import('./sdk.js').PostFullscreenState} */
9851028
const state = {
9861029
state: toggle === 0 ? 0 : 1
9871030
}
988-
this._postToDOM('set-fullscreen', state)
1031+
this.postToDOM('set-fullscreen', state)
9891032
}
9901033
})
9911034
_SetFullscreen = this._SetFullscreenBase

src/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let WorldInstanceVar = sdk === 'v1'
7171
let DOMInstanceVar = sdk === 'v1'
7272
? self.IDOMInstance
7373
: globalThis.IDOMInstance
74-
74+
7575
const parentClass = {
7676
object: {
7777
scripting: InstanceVar,

0 commit comments

Comments
 (0)