This repository has been archived by the owner on Apr 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmutils.js
104 lines (94 loc) · 2.85 KB
/
wmutils.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
if (typeof (console) === "undefined" || typeof (console.log) === "undefined") {
var console = { log: function () { } };
// console.info = console.log;
console.error = console.log;
console.warn = console.log;
}
if (!Array.prototype.indexOf) {
// Based on the Mozilla-provided sample:
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf#Compatibility
Array.prototype.indexOf = function (elt, from) {
var from = Number(from) || 0;
var len = this.length;
for (var i = from; i < len; i++) {
if (this[i] == elt) {
return i;
}
}
return -1;
}
}
/**
* Prettifies a mail string, given the amount of rows and the length of the middle column. Outer column
* width is automagically calculated.
* @param String Mail string to prettify
* @param Number Amount of rows
* @param Number Amount of characters in the middle column
* @return String Prettified mail string
*/
function prettyMailString(mailString, rows, middleColumnSize) {
mailString = WMSParser.sanitize(mailString);
// If our mailString is 18 bytes and the middle column is 5 bytes with 2 rows, we'll have 8 bytes left for the rest.
// There'll be 2 columns for 2 rows each = 8/2/2 = 2 bytes.
// (18 - (2 * 5)) / (2 * 2) = 2
var outerColumnSize = (mailString.length - (rows * middleColumnSize)) / (rows * 2);
var prettyString = "";
var stringPtr = 0;
for (var row = 0; row < rows; row++) {
if (prettyString != "") {
prettyString += "\n";
}
prettyString += mailString.substr(stringPtr, outerColumnSize) + " ";
stringPtr += outerColumnSize;
prettyString += mailString.substr(stringPtr, middleColumnSize) + " ";
stringPtr += middleColumnSize;
prettyString += mailString.substr(stringPtr, outerColumnSize);
stringPtr += outerColumnSize;
}
return prettyString;
}
/**
* Returns the item name for a given item ID. Requires the sky_item file to be loaded.
* @param Number Item ID
* @return String Item name or "Unknown Item"
*/
function getItemName(itemId) {
if (WMSkyItem[itemId]) {
return WMSkyItem[itemId];
}
else {
return "Unknown Item";
}
}
/**
* Returns the dungeon name for a given dungeon ID. Requires the sky_dungeon file to be loaded.
* @param Number Dungeon ID
* @return String Dungeon name or "Unknown"
*/
function getDungeonName(dungeonId) {
// TODO: keep list of valid/invalid WMS dungeons
if (WMSkyDungeon[dungeonId]) {
return WMSkyDungeon[dungeonId];
}
else {
return "Unknown";
}
}
/**
* Returns the monster name for a given monster ID. Requires the sky_monster file to be loaded.
* @param Number Monster ID
* @return String Monster name or "Unknown"
*/
function getMonName(monId) {
var female = (monId > 600);
if (female) {
monId -= 600;
}
if (WMSkyPoke[monId]) {
// (female ? "[F]" : "[M]") +
return WMSkyPoke[monId];
}
else {
return "Unknown";
}
}