-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_patching.js
More file actions
105 lines (91 loc) · 3.03 KB
/
Copy pathsetup_patching.js
File metadata and controls
105 lines (91 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
inlets = 5;
outlets = 5;
patcher = this.patcher;
post("Script loaded successfully.\n");
// Utility function to safely get object references with retry mechanism
function getNamedObject(name, retryDelay, maxRetries) {
var obj = patcher.getnamed(name);
if (!obj && maxRetries > 0) {
post("Warning: Object '" + name + "' not found. Retrying in " + retryDelay + " seconds...\n");
var retryTask = new Task(retryGetNamedObject, this, name, retryDelay, maxRetries);
retryTask.schedule(retryDelay * 1000); // Schedule the task in milliseconds
} else if (!obj) {
post("Error: Object '" + name + "' not found after retries.\n");
} else {
post("Object '" + name + "' successfully retrieved.\n");
return obj;
}
return null;
}
function retryGetNamedObject(name, retryDelay, maxRetries) {
getNamedObject(name, retryDelay, maxRetries - 1);
}
const clonePullButton = getNamedObject("button", .5, 3); // Retry every .5 seconds, up to 3 times
const primaryWheel = getNamedObject("primaryWheel", .5, 3);
const secondaryWheel = getNamedObject("secondaryWheel", .5, 3);
const loadingWheelToggle = getNamedObject("loadingWheelToggle", .5, 3);
const progressText = getNamedObject("progressText", .5, 2);
const infoText = getNamedObject("infoText", .5, 2);
const stageText = getNamedObject("stageText", .5, 2);
const successNeedleColor = [0.5, 1., 0.5, 1.];
const failureNeedleColor = [1., 0.5, 0.5, 1.];
const progressNeedleColor = [0.42, 0.79, 0.85, 1.];
var wheelToggleState = false;
function start() {
setPrimaryWheelValue(0);
setSecondaryWheelValue(0);
hideProgressText();
setButtonText("Install");
}
function setSecondaryWheelValue(value) {
if (secondaryWheel) {
secondaryWheel.message("set", value);
}
else {
post("Secondary wheel not found.\n");
}
}
function setPrimaryWheelValue(value) {
if (primaryWheel) {
if (value > 100) {
primaryWheel.message("needlecolor", progressNeedleColor);
} else {
primaryWheel.message("needlecolor", successNeedleColor);
}
primaryWheel.message("set", value);
}
if (progressText) {
progressText.message("set", value + "%");
}
if (clonePullButton) {
clonePullButton.message("text", "");
}
}
function setButtonText(text) {
if (clonePullButton) {
clonePullButton.message("text", text);
}
if (text == "Install" || text == "Update") {
hideProgressText();
}
}
function hideProgressText() {
if (progressText) {
progressText.message("set", "");
}
}
function toggleLoadingWheel(state) {
if (loadingWheelToggle) {
loadingWheelToggle.message("set", state);
loadingWheelToggle.message("outputvalue");
}
if (!state && secondaryWheel) {
setSecondaryWheelValue(0);
}
}
function setInfoText(text) {
if (infoText) {
infoText.message("set", text);
}
}
start();