Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
151 lines (139 loc) · 5.55 KB
/
Copy pathextension.js
File metadata and controls
151 lines (139 loc) · 5.55 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
"use strict";
const vscode = require('vscode');
const path = require('path');
const { TrainerEditorPanel } = require('./lib/trainerEditorPanel');
const { ItemEditorPanel } = require('./lib/itemEditorPanel');
const { AttackEditorPanel } = require('./lib/attackEditorPanel');
const { PokemonEditorPanel } = require('./lib/pokemonEditorPanel');
/**
* Find the pokeemerald-expansion project root from one of its editor data files.
* @returns {Promise<vscode.Uri|null>}
*/
async function findProjectRoot() {
let files = await vscode.workspace.findFiles('**/src/data/trainers.party', null, 1);
if (files.length === 0) {
files = await vscode.workspace.findFiles('**/src/data/items.h', null, 1);
}
if (files.length === 0) {
files = await vscode.workspace.findFiles('**/src/data/pokemon/species_info.h', null, 1);
if (files.length === 0) return null;
return vscode.Uri.file(path.resolve(files[0].fsPath, '..', '..', '..', '..'));
}
// The standard data files are at <root>/src/data/<file>.
return vscode.Uri.file(
path.resolve(files[0].fsPath, '..', '..', '..')
);
}
class EditorTreeItem extends vscode.TreeItem {
/**
* @param {string} label
* @param {string} commandId
* @param {string} description
*/
constructor(label, commandId, description) {
super(label, vscode.TreeItemCollapsibleState.None);
this.description = description;
this.command = {
command: commandId,
title: label,
arguments: [],
};
this.iconPath = new vscode.ThemeIcon('edit');
}
}
class PokeCompEditorViewProvider {
getTreeItem(element) { return element; }
getChildren() {
return [
new EditorTreeItem('Trainer Editor', 'pokeCompEditor.openTrainerEditor', 'trainers.party'),
new EditorTreeItem('Trainer Editor (FRLG)', 'pokeCompEditor.openTrainerEditorFRLG', 'trainers_frlg.party'),
new EditorTreeItem('Item Editor', 'pokeCompEditor.openItemEditor', 'items.h'),
new EditorTreeItem('Attack Editor', 'pokeCompEditor.openAttackEditor', 'moves_info.h'),
new EditorTreeItem('Pokemon Editor', 'pokeCompEditor.openPokemonEditor', 'species_info'),
];
}
}
/**
* @param {vscode.ExtensionContext} context
*/
async function activate(context) {
// Sidebar view
vscode.window.registerTreeDataProvider(
'pokeCompEditorView',
new PokeCompEditorViewProvider()
);
// Command: open standard trainer editor
context.subscriptions.push(
vscode.commands.registerCommand('pokeCompEditor.openTrainerEditor', async () => {
const root = await findProjectRoot();
if (!root) {
vscode.window.showErrorMessage(
'PokeCompEditor: Could not find trainers.party. ' +
'Make sure you have a pokeemerald-expansion project open.'
);
return;
}
const partyFile = path.join(root.fsPath, 'src', 'data', 'trainers.party');
TrainerEditorPanel.createOrShow(context, root, partyFile);
})
);
// Command: open FRLG trainer editor
context.subscriptions.push(
vscode.commands.registerCommand('pokeCompEditor.openTrainerEditorFRLG', async () => {
const root = await findProjectRoot();
if (!root) {
vscode.window.showErrorMessage(
'PokeCompEditor: Could not find trainers_frlg.party. ' +
'Make sure you have a pokeemerald-expansion project open.'
);
return;
}
const partyFile = path.join(root.fsPath, 'src', 'data', 'trainers_frlg.party');
TrainerEditorPanel.createOrShow(context, root, partyFile);
})
);
// Command: open item editor
context.subscriptions.push(
vscode.commands.registerCommand('pokeCompEditor.openItemEditor', async () => {
const root = await findProjectRoot();
if (!root) {
vscode.window.showErrorMessage(
'PokeCompEditor: Could not find items.h. ' +
'Make sure you have a pokeemerald-expansion project open.'
);
return;
}
ItemEditorPanel.createOrShow(context, root);
})
);
// Command: open attack editor
context.subscriptions.push(
vscode.commands.registerCommand('pokeCompEditor.openAttackEditor', async () => {
const root = await findProjectRoot();
if (!root) {
vscode.window.showErrorMessage(
'PokeCompEditor: Could not find moves_info.h. ' +
'Make sure you have a pokeemerald-expansion project open.'
);
return;
}
AttackEditorPanel.createOrShow(context, root);
})
);
// Command: open Pokemon editor
context.subscriptions.push(
vscode.commands.registerCommand('pokeCompEditor.openPokemonEditor', async () => {
const root = await findProjectRoot();
if (!root) {
vscode.window.showErrorMessage(
'PokeCompEditor: Could not find species_info.h. ' +
'Make sure you have a pokeemerald-expansion project open.'
);
return;
}
PokemonEditorPanel.createOrShow(context, root);
})
);
}
function deactivate() {}
module.exports = { activate, deactivate };