This repository was archived by the owner on Nov 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.js
More file actions
189 lines (177 loc) · 5.92 KB
/
code.js
File metadata and controls
189 lines (177 loc) · 5.92 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { RPM } from "../path.js"
const pluginName = "Typewriter Text";
class WaitUntilDoneTyping extends RPM.EventCommand.Base
{
constructor(id)
{
super();
this.id = id;
}
onKeyPressed(currentState, key)
{
if (RPM.Datas.Keyboards.checkActionMenu(key) || RPM.Datas.Keyboards.checkCancelMenu(key))
{
const p = RPM.Manager.Stack.displayedPictures;
for (var i = 0; i < p.length; i++)
if (p[i][0] === this.id)
p[i][1].typewriterTextPlugin_skip = true;
}
}
onMouseDown(currentState, x, y)
{
if (RPM.Datas.Systems.isMouseControls && RPM.Common.Inputs.mouseLeftPressed)
{
const p = RPM.Manager.Stack.displayedPictures;
for (var i = 0; i < p.length; i++)
if (p[i][0] === this.id)
if (p[i][1].isInside(x, y))
p[i][1].typewriterTextPlugin_skip = true;
}
}
update(currentState)
{
if (RPM.Datas.Systems.isMouseControls && RPM.Common.Inputs.mouseLeftPressed)
return 0;
const p = RPM.Manager.Stack.displayedPictures;
for (var i = 0; i < p.length; i++)
if (p[i][0] === this.id && !!p[i][1].typewriterTextPlugin_doneTyping)
return 1;
return 0;
}
}
function updateWindow(id, x, y, width, height, wholeText, count, sound, volume)
{
var w = null;
const p = RPM.Manager.Stack.displayedPictures;
for (var i = 0; i < p.length; i++)
if (p[i][0] === id)
w = p[i][1];
if (count < wholeText.length)
{
var stride = 1;
var wait = 5;
if (!!w && w.typewriterTextPlugin_skip)
stride = wholeText.length;
RPM.Manager.Songs.playSound(sound, volume);
for (var i = stride; i > 0; i--)
{
if (wholeText[count] == "[")
{
const n = wholeText.indexOf("]", count);
if (wholeText.substr(count).search(/\[wait=\d*\]/) === 0)
{
wait = parseInt(wholeText.slice(count + 6, n));
wholeText = wholeText.substr(0, count) + wholeText.substr(n + 1);
break;
}
console.log(wholeText.substring(count, n + 1), isText(wholeText.substring(count, n + 1)));
if (n > 0 && !isText(wholeText.substring(count, n + 1)))
count = n;
}
count++;
}
spawnWindow(id, x, y, height, width, wholeText.substring(0, count));
setTimeout(updateWindow, wait, id, x, y, width, height, wholeText, count, sound, volume);
}
else
w.typewriterTextPlugin_doneTyping = true;
}
function isText(text)
{
console.log(text);
const m = new RPM.Graphic.Message(text, -1, 0, 0);
m.update();
for (var i = 0; i < m.graphics.length; i++)
{
if (!m.graphics[i])
continue;
if (m.graphics[i].constructor.name !== "Text")
return false;
if (m.graphics[i].text == text)
return true;
}
return false;
}
// Typewriter plugin code - Start
RPM.Manager.Plugins.registerCommand(pluginName, "Show Text", (id, text, sound, volume) =>
{
var i;
text = text.toString();
while (true) // not the best practice but works in this scenario
{
i = text.search(/[^\\]\\n/); // regex for "find \n except when it's \\n"
if (i === -1)
break;
text = text.slice(0, i + 1) + "\n" + text.slice(i + 3);
}
const d = RPM.Datas.Systems.dbOptions;
updateWindow(id, d.v_x, d.v_y, d.v_h, d.v_w, text.replace("\\\\n", "\\n"), 0, sound.kind === RPM.Common.Enum.SongKind.Sound ? sound.id : 0, Math.max(0, Math.min(100, volume / 100)));
const currentCommand = RPM.Core.ReactionInterpreter.currentReaction.currentCommand;
if (!currentCommand.typewriterTextPlugin_finishedText)
{
currentCommand.typewriterTextPlugin_finishedText = true;
const nextCommand = currentCommand.next;
const showText = new RPM.EventCommand.ShowText([8, "", -1, 0, 0, 1, text.replace(/\[wait=\d*\]/, "").replace("\\n", "\n")]);
showText.initialize();
currentCommand.next = new RPM.Core.Node(currentCommand.parent, new WaitUntilDoneTyping(id));
currentCommand.next.next = new RPM.Core.Node(currentCommand.parent, showText);
currentCommand.next.next.next = nextCommand;
}
});
// Typewriter plugin code - End
// "Multiple text boxes" plugin code by @Russo (https://github.com/yaleksander/RPM-Plugin-Multiple-text-boxes) - Start
RPM.Core.WindowBox.prototype.draw = function (isChoice = false, windowDimension = this.windowDimension, contentDimension = this.contentDimension)
{
if (this.content)
this.content.drawBehind(contentDimension[0], contentDimension[1], contentDimension[2], contentDimension[3]);
// Single line alteration from source code
!!this.customWindowSkin ? this.customWindowSkin.drawBox(windowDimension, this.selected, this.bordersVisible) : RPM.Datas.Systems.getCurrentWindowSkin().drawBox(windowDimension, this.selected, this.bordersVisible);
if (this.content)
{
if (!isChoice && this.limitContent)
{
RPM.Common.Platform.ctx.save();
RPM.Common.Platform.ctx.beginPath();
RPM.Common.Platform.ctx.rect(contentDimension[0], contentDimension[1] - RPM.Common.ScreenResolution.getScreenY(this.padding[3] / 2), contentDimension[2], contentDimension[3] + RPM.Common.ScreenResolution.getScreenY(this.padding[3]));
RPM.Common.Platform.ctx.clip();
}
if (isChoice)
this.content.drawChoice(contentDimension[0], contentDimension[1], contentDimension[2], contentDimension[3]);
else
this.content.draw(contentDimension[0], contentDimension[1], contentDimension[2], contentDimension[3]);
if (!isChoice && this.limitContent)
RPM.Common.Platform.ctx.restore();
}
}
// Tweaked this code to be a function instead of command
function spawnWindow(id, x, y, width, height, text)
{
const pad = RPM.Datas.Systems.dbOptions;
const value = [id, new RPM.Core.WindowBox(x, y, width, height,
{
content: new RPM.Graphic.Message(text.toString(), -1, 0, 0),
padding: [pad.v_pLeft, pad.v_pTop, pad.v_pRight, pad.v_pBottom]
})];
value[1].content.update();
value[1].customWindowSkin = RPM.Datas.Systems.getCurrentWindowSkin();
const p = RPM.Manager.Stack.displayedPictures;
var ok = false;
for (var i = 0; i < p.length; i++)
{
if (id === p[i][0])
{
p[i] = value;
ok = true;
break;
}
else if (id < p[i][0])
{
p.splice(i, 0, value);
ok = true;
break;
}
}
if (!ok)
p.push(value);
};
// "Multiple text boxes" plugin code by @Russo - End