Skip to content

Commit 4b24689

Browse files
committed
add action to check if path exist
add condition that returns tru if path exist fix typos update example
1 parent f48439e commit 4b24689

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<img src="./src/icon.svg" width="100" /><br>
22
# Pipelab <br>
3-
Description <br>
3+
A plugin that integrate with Pipelab <br>
44
<br>
55
Author: Armaldio <br>
6-
Addon Url: https://www.construct.net/en/make-games/addons/####/XXXX <br>
6+
Website: https://github.com/CynToolkit/construct-plugin <br>
7+
Addon Url: https://github.com/CynToolkit/construct-plugin <br>
8+
Download Latest Version : [Version: 1.6.0](https://github.com/CynToolkit/construct-plugin/releases/latest) <br>
79
<sub>Made using [c3ide2-framework](https://github.com/ConstructFund/c3ide2-framework) </sub><br>
810

911
## Table of Contents
@@ -64,6 +66,7 @@ The main files you may want to look at would be instance.js
6466
| Write text file | Writes the text file. | Path *(string)* <br>Contents *(string)* <br> |
6567
| Write text file | Writes the text file. | Path *(string)* <br>Contents *(string)* <br> |
6668
| Read text file | Reads the text file. | Path *(string)* <br> |
69+
| Check if the path exist | Check if the path exist. | Path *(string)* <br> |
6770
| Show folder dialog | Show a folder dialog | |
6871
| Show open dialog | Show an open dialog | Accept *(string)* <br> |
6972
| Show save dialog | Show a save dialog | Accept *(string)* <br> |
@@ -82,13 +85,15 @@ The main files you may want to look at would be instance.js
8285
| Set y | Set the y position of the window. | Y *(number)* <br> |
8386
| Show dev tools | Show or hide the dev tools. | Show *(combo)* <br> |
8487
| Unmaximize | Unmaximize the window | |
88+
| Set Fullscreen | Change fullscreen state | Fullscreen *(combo)* <br> |
8589

8690

8791
---
8892
## Conditions
8993
| Condition | Description | Params
9094
| --- | --- | --- |
9195
| Is engine | Return true if the engine running the app is the one selected | Engine *(combo)* <br> |
96+
| If last checked path exist | Return 'true' if the last checked path exists. 'false' otherwise | |
9297
| On folder dialog cancel | Triggered when the folder dialog is canceled | |
9398
| On folder dialog ok | Triggered after a folder chosen from a folder dialog | |
9499
| On open dialog cancel | Triggered when the open dialog is canceled | |

examples/example.c3p

852 Bytes
Binary file not shown.

src/instance.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ts-check
22

3-
43
class WebSocketClient {
54
constructor(url, options = {}) {
65
this.url = url;
@@ -220,6 +219,9 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
220219
/** @type {number} */
221220
_fileSize
222221

222+
/** @type {boolean} */
223+
_lastPathExists
224+
223225
/** @type {number} */
224226
_windowHeight
225227

@@ -434,7 +436,24 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
434436

435437
const answer = await this.ws?.sendAndWaitForResponse(order)
436438
// console.log('this', this)
437-
this._readFile = answer?.body.content
439+
if (answer?.body.success === true) {
440+
this._readFile = answer?.body.content
441+
}
442+
}, this.unsupportedEngine)
443+
444+
_CheckIfPathExist = this.wrap(super._CheckIfPathExist, async (path) => {
445+
// console.log('Read text', path);
446+
447+
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageExistFile, 'input'>} */
448+
const order = {
449+
url: '/fs/exist',
450+
body: {
451+
path,
452+
}
453+
}
454+
455+
const answer = await this.ws?.sendAndWaitForResponse(order)
456+
this._lastPathExists = answer?.body.success ?? false
438457
}, this.unsupportedEngine)
439458

440459
_Maximize = this.wrap(super._Maximize, async () => {
@@ -1141,6 +1160,10 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
11411160
return this._engine === engine
11421161
})
11431162

1163+
_LastPathExists = this.wrap(super._LastPathExists, () => {
1164+
return this._lastPathExists
1165+
})
1166+
11441167
//
11451168

11461169
_saveToJson() {

src/pluginConfig.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,25 @@ const Config = /** @type {const} */({
541541
listName: "Read text file",
542542
displayText: "Read text file [b]{0}[/b]",
543543
},
544+
CheckIfPathExist: {
545+
category: "filesystem",
546+
forward: "_CheckIfPathExist",
547+
highlight: false,
548+
deprecated: false,
549+
isAsync: true,
550+
params: [
551+
{
552+
id: 'path',
553+
desc: "The path to check",
554+
name: "Path",
555+
type: 'string',
556+
initialValue: "\"\"",
557+
}
558+
],
559+
description: "Check if the path exist.",
560+
listName: "Check if the path exist",
561+
displayText: "Check if path [b]{0}[/b] exists",
562+
},
544563

545564
// file-dialogs
546565
ShowFolderDialog: {
@@ -698,7 +717,7 @@ const Config = /** @type {const} */({
698717
}
699718
],
700719
listName: "Set height",
701-
displayText: "Set windown height to {0}",
720+
displayText: "Set window height to {0}",
702721
description: "Set the height of the window.",
703722
},
704723

@@ -815,7 +834,7 @@ const Config = /** @type {const} */({
815834
}
816835
],
817836
listName: "Set width",
818-
displayText: "Set windown width to {0}",
837+
displayText: "Set window width to {0}",
819838
description: "Set the width of the window.",
820839
},
821840

@@ -938,6 +957,16 @@ const Config = /** @type {const} */({
938957
],
939958
listName: "Is engine",
940959
},
960+
LastPathExists: {
961+
category: "filesystem",
962+
forward: "_LastPathExists",
963+
highlight: false,
964+
deprecated: false,
965+
description: "Return 'true' if the last checked path exists. 'false' otherwise",
966+
displayText: 'Last checked path exists',
967+
listName: 'If last checked path exist',
968+
params: []
969+
},
941970

942971
OnFolderDialogCancel: {
943972
category: "file-dialogs",

0 commit comments

Comments
 (0)