-
Notifications
You must be signed in to change notification settings - Fork 3
/
Helper.ts
282 lines (248 loc) · 9.21 KB
/
Helper.ts
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* eslint-disable @typescript-eslint/naming-convention */
import * as vscode from "vscode";
import { Path } from "./utils/Path";
import { setGamePath } from "./commands/SetGamePath";
import { ConfigService } from "./services/ConfigService";
import { LoggingService } from "./services/LoggingService";
import { Packer } from "./Packer";
import { Unpacker } from "./Unpacker";
import { openGameFolder } from "./commands/OpenGameFolder";
import { GamePlayService } from "./commands/TestGamePlay";
import { ScriptExplorerProvider } from "./providers/ScriptViewer";
import { StatusbarProvider } from "./providers/StatusbarProvider";
import { Events } from "./events/EventHandler";
/**
* @namespace Helper
* @description
* Helper provides commands that can be helpfuled in visual studio code extension.
*/
export namespace Helper {
/**
* @class Extension
*/
export class Extension {
private scriptProvider?: ScriptExplorerProvider;
constructor(
private readonly configService: ConfigService,
private readonly loggingService: LoggingService,
private readonly statusbarProvider: StatusbarProvider,
) {
this.updateConfiguration();
}
setScriptProvider(scriptProvider: ScriptExplorerProvider) {
this.scriptProvider = scriptProvider;
}
getScriptProvider() {
return this.scriptProvider;
}
async updateConfiguration() {
const config =
vscode.workspace.getConfiguration("rgssScriptCompiler");
if (!config.has("showStatusBar")) {
await config.update("showStatusBar", false);
}
}
setGamePathCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.setGamePath",
async () => {
await setGamePath(this.configService);
this.configService.ON_LOAD_GAME_FOLDER.event(
(gameFolder) => {
Events.emit(
"info",
`Game folder is changed to ${gameFolder}`,
);
this.statusbarProvider.show();
},
);
},
);
}
saveCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.save",
async () => {
await this.configService.detectRGSSVersion();
await vscode.commands.executeCommand(
"workbench.action.files.save",
);
await vscode.commands.executeCommand(
"rgss-script-compiler.compile",
);
},
);
}
testPlayCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.testPlay",
() => {
const gamePlayService = new GamePlayService(
this.configService,
this.loggingService,
);
gamePlayService.run();
},
);
}
unpackCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.unpack",
() => {
if (!this.configService) {
Events.emit("info", "There is no workspace folder.");
return;
}
const unpacker = new Unpacker(
this.configService,
this.loggingService,
() => {
vscode.commands
.executeCommand(
"rgss-script-compiler.refreshScriptExplorer",
)
.then(() => {
Events.emit("info", "refreshed");
});
},
);
unpacker.unpack();
},
);
}
compileCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.compile",
() => {
if (!this.configService) {
Events.emit("info", "There is no workspace folder.");
return;
}
const bundler = new Packer(
this.configService,
this.loggingService,
);
bundler.pack();
},
);
}
/**
* Opens the game folder on Windows or MacOS.
*
*/
openGameFolderCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.openGameFolder",
() => {
openGameFolder(this.configService, this.loggingService);
},
);
}
openScriptFileCommand() {
return vscode.commands.registerCommand(
"rgss-script-compiler.openScript",
(scriptFile: vscode.Uri) => {
vscode.window.showTextDocument(scriptFile);
},
);
}
/**
* Gets command elements.
* @returns
*/
getCommands() {
return [
this.setGamePathCommand(),
this.unpackCommand(),
this.compileCommand(),
this.openGameFolderCommand(),
this.testPlayCommand(),
this.saveCommand(),
this.openScriptFileCommand(),
];
}
}
/**
* @class StatusBarProviderImpl
*/
class StatusBarProviderImpl {
getGameFolderOpenStatusBarItem() {
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
);
statusBarItem.text = `$(file-directory) RGSS: Set Game Folder`;
statusBarItem.command = "rgss-script-compiler.setGamePath";
return statusBarItem;
}
getUnpackStatusBarItem() {
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
);
statusBarItem.text = `$(sync~spin) RGSS: Import`;
statusBarItem.command = "rgss-script-compiler.unpack";
return statusBarItem;
}
getCompileStatusBarItem() {
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
);
statusBarItem.text = `$(sync) RGSS: Compile`;
statusBarItem.command = "rgss-script-compiler.compile";
return statusBarItem;
}
getGameFolderPathStatusBarItem(projectPath: vscode.Uri) {
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
);
statusBarItem.text = `$(pulse) Game Path: ${projectPath.fsPath}`;
statusBarItem.backgroundColor = "yellow";
return statusBarItem;
}
getOpenGameFolderButtonItem() {
const statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Left,
);
statusBarItem.text = `$(folder) RGSS: Open Game Folder`;
statusBarItem.command = "rgss-script-compiler.openGameFolder";
return statusBarItem;
}
}
export const StatusBarProvider = new StatusBarProviderImpl();
export const getStatusBarProvider = () => {
return StatusBarProvider;
};
export const getStatusBarItems = () => {
return [
Helper.StatusBarProvider.getGameFolderOpenStatusBarItem(),
Helper.StatusBarProvider.getUnpackStatusBarItem(),
Helper.StatusBarProvider.getCompileStatusBarItem(),
Helper.StatusBarProvider.getOpenGameFolderButtonItem(),
];
};
export const createScriptProviderFunction = (
helper: Helper.Extension,
configService: ConfigService,
loggingService: LoggingService,
) => {
if (!helper.getScriptProvider()) {
Events.emit("info", "Importing the scripts....");
const scriptViewerPath = Path.resolve(
configService.getMainGameFolder(),
);
const scriptProvider = new ScriptExplorerProvider(
scriptViewerPath,
loggingService,
configService,
);
helper.setScriptProvider(scriptProvider);
const context = configService.getExtensionContext();
const view = vscode.window.createTreeView("rgssScriptViewer", {
treeDataProvider: scriptProvider,
showCollapseAll: true,
canSelectMany: true,
dragAndDropController: scriptProvider,
});
context.subscriptions.push(view);
}
};
}