-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfvtt-module-rqg-es.js
174 lines (166 loc) · 4.94 KB
/
fvtt-module-rqg-es.js
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
Hooks.once("init", () => {
CONFIG.RQG.debug.showActorActiveEffectsTab = true;
//if (game.settings.get("core", "language") === "es") {
// document.getElementById("logo").src = "/modules/fvtt-module-rqg-es/images/fvtt-rqg-es.webp";
//}
});
Hooks.once("ready", async function () {
function updateMacro(macroFile) {
fetch(macroFile)
.then((res) => res.text())
.then((content) => {
let macroContents = content.split(`\n`);
let versionLine = -1;
for (var i = 0; i < macroContents.length; i++) {
if (macroContents[i].search(/macroVersion/) > -1) {
versionLine = i;
break;
}
}
let macroVersion = parseFloat(
macroContents[versionLine]
.split("=")[1]
.replace(/\;/g, "")
.replace(/\"/g, "")
);
let nameLine = -1;
for (var i = 0; i < macroContents.length; i++) {
if (macroContents[i].search(/macroName/) > -1) {
nameLine = i;
break;
}
}
let macroName = macroContents[nameLine]
.split("=")[1]
.replace(/\;/g, "")
.replace(/\"/g, "")
.trim();
let imageLine = -1;
for (var i = 0; i < macroContents.length; i++) {
if (macroContents[i].search(/macroImage/) > -1) {
imageLine = i;
break;
}
}
let macroImage = macroContents[imageLine]
.split("=")[1]
.replace(/\;/g, "")
.replace(/\"/g, "")
.trim();
let instMacro = game.macros.getName(macroName);
let instVersion = instMacro ? instMacro.flags.version : 0;
console.log("Analizando: " + macroFile);
if (
!instMacro ||
instVersion === undefined ||
parseFloat(instVersion) < macroVersion
) {
if (instMacro) {
console.log(
"Macro: " +
macroName +
", Versión: " +
macroVersion +
", Instalada: ",
instVersion,
" --- Actualizamos macro actual"
);
instMacro.update({
name: macroName,
type: "script",
img: macroImage,
command: content,
flags: {
version: macroVersion,
},
});
} else {
console.log(
"Macro: " +
macroName +
", Versión: " +
macroVersion +
", Instalada: ",
instVersion,
" --- Creamos macro"
);
Macro.create({
name: macroName,
type: "script",
img: macroImage,
command: content,
flags: {
version: macroVersion,
},
});
}
} else {
console.log(
"Macro: " +
macroName +
", Versión: " +
macroVersion +
", Instalada: ",
instVersion,
" --- No hacemos nada"
);
}
});
}
if (game.user.isGM) {
let ficherosjs = await FilePicker.browse(
"data",
"/modules/fvtt-module-rqg-es/scripts"
).then((picker) => picker.files);
for (var i = 0; i < ficherosjs.length; i++) {
if (ficherosjs[i].search(/\.js/) > -1) updateMacro(ficherosjs[i]);
}
}
function onlyUnique(value, index, array) {
return array.indexOf(value) === index;
}
console.log("language:" + game.settings.get("core", "language"))
if (game.user.isGM && game.settings.get("core", "language") === "es") {
document.getElementById("logo").src = "/modules/fvtt-module-rqg-es/images/fvtt-rqg-es.webp";
}
/* Esto se ha eliminado en la 3.3.0, pero lo dejo porque la macro que asigna rqids para localizaciones todavía usa estos valores */
if (game.user.isGM && game.settings.get("core", "language") === "es") {
let hitloc = game.settings.get("rqg", "hitLocations")[
"hitLocationItemNames"
];
hitloc.push(
"Cabeza",
"Abdomen",
"Pecho",
"Cuerpo",
"Cuartos delanteros",
"Cuartos traseros",
"Brazo izquierdo",
"Pierna izquierda",
"Pata central izquierda",
"Pata delantera izquierda",
"Cabeza izquierda",
"Ala izquierda",
"Brazo derecho",
"Pierna derecha",
"Pata central derecha",
"Pata delantera derecha",
"Cabeza derecha",
"Ala derecha",
"Cola",
"Tentáculo 1",
"Tentáculo 2",
"Tentáculo 3",
"Tentáculo 4",
"Tentáculo 5",
"Tentáculo 6",
"Tentáculo 7",
"Tentáculo 8",
"Tórax",
"Tronco"
);
let hitlocunique = hitloc.filter(onlyUnique);
let hitlocuniquearray = { hitLocationItemNames: hitlocunique };
game.settings.set("rqg", "hitLocations", hitlocuniquearray);
}
});