mirror of
https://github.com/smogon/pokemon-showdown-client.git
synced 2026-09-08 20:08:38 -05:00
Add githooks/build-indexes
This is the search index build script from the Gen 6 Learnsets repository, slightly rewritten for the PS client environment. It expects a checkout of the server respository in `data/Pokemon-Showdown`.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,7 @@
|
||||
/js/config.js
|
||||
/index.php
|
||||
/index.html
|
||||
/data/Pokemon-Showdown/
|
||||
node_modules/
|
||||
eslint-cache/
|
||||
.DS_Store
|
||||
|
||||
@@ -98,6 +98,7 @@ RewriteRule ^~~([^:/]*):([0-9]*)(/.*)?$ http://$1-$2.psim.us$3 [R=301,L]
|
||||
|
||||
RewriteRule ^backup/ - [F]
|
||||
RewriteRule ^\.git/ - [F]
|
||||
RewriteRule ^data/Pokemon-Showdown/ - [F]
|
||||
RewriteRule ^lib/ - [F]
|
||||
RewriteRule ^githooks/ - [F]
|
||||
|
||||
|
||||
105
githooks/build-indexes
Executable file
105
githooks/build-indexes
Executable file
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
require('sugar');
|
||||
global.toId = function (text) {
|
||||
if (text && text.id) {
|
||||
text = text.id;
|
||||
} else if (text && text.userid) {
|
||||
text = text.userid;
|
||||
}
|
||||
if (typeof text !== 'string' && typeof text !== 'number') return '';
|
||||
return ('' + text).toLowerCase().replace(/[^a-z0-9]+/g, '');
|
||||
};
|
||||
const Tools = require('../data/Pokemon-Showdown/tools').includeData();
|
||||
const fs = require("fs");
|
||||
|
||||
/*********************************************************
|
||||
* Build search-index.js
|
||||
*********************************************************/
|
||||
|
||||
{
|
||||
process.stdout.write("Building `data/search-index.js`... ");
|
||||
|
||||
var index = [];
|
||||
|
||||
index = index.concat(Object.keys(Tools.data.Pokedex).map(x => x + ' pokemon'));
|
||||
index = index.concat(Object.keys(Tools.data.Movedex).map(x => x + ' move'));
|
||||
index = index.concat(Object.keys(Tools.data.Items).map(x => x + ' item'));
|
||||
index = index.concat(Object.keys(Tools.data.Abilities).map(x => x + ' ability'));
|
||||
index = index.concat(Object.keys(Tools.data.TypeChart).map(x => toId(x) + ' type'));
|
||||
index = index.concat(['physical', 'special', 'status'].map(x => toId(x) + ' category'));
|
||||
index = index.concat(['monster', 'water1', 'bug', 'flying', 'field', 'fairy', 'grass', 'humanlike', 'water3', 'mineral', 'amorphous', 'water2', 'ditto', 'dragon', 'undiscovered'].map(x => toId(x) + ' egggroup'));
|
||||
|
||||
index.sort();
|
||||
|
||||
// manually rearrange
|
||||
index[index.indexOf('grass type')] = 'grass egggroup';
|
||||
index[index.indexOf('grass egggroup')] = 'grass type';
|
||||
|
||||
index[index.indexOf('fairy type')] = 'fairy egggroup';
|
||||
index[index.indexOf('fairy egggroup')] = 'fairy type';
|
||||
|
||||
index[index.indexOf('flying type')] = 'flying egggroup';
|
||||
index[index.indexOf('flying egggroup')] = 'flying type';
|
||||
|
||||
index[index.indexOf('dragon type')] = 'dragon egggroup';
|
||||
index[index.indexOf('dragon egggroup')] = 'dragon type';
|
||||
|
||||
index[index.indexOf('bug type')] = 'bug egggroup';
|
||||
index[index.indexOf('bug egggroup')] = 'bug type';
|
||||
|
||||
index[index.indexOf('psychic type')] = 'psychic move';
|
||||
index[index.indexOf('psychic move')] = 'psychic type';
|
||||
|
||||
index[index.indexOf('ditto pokemon')] = 'ditto egggroup';
|
||||
index[index.indexOf('ditto egggroup')] = 'ditto pokemon';
|
||||
|
||||
|
||||
let BattleSearchIndex = index.map(x => x.split(' ')[0]);
|
||||
let BattleSearchIndexType = index.map(x => x.split(' ')[1]);
|
||||
|
||||
let BattleSearchIndexOffset = BattleSearchIndex.map((id, i) => {
|
||||
var name = '';
|
||||
switch (BattleSearchIndexType[i]) {
|
||||
case 'pokemon': name = Tools.getTemplate(id).species; break;
|
||||
case 'move': name = Tools.getMove(id).name; break;
|
||||
case 'item': name = Tools.getItem(id).name; break;
|
||||
case 'ability': name = Tools.getAbility(id).name; break;
|
||||
}
|
||||
var res = '';
|
||||
var nonAlnum = 0;
|
||||
for (var i = 0, j = 0; i < id.length; i++, j++) {
|
||||
while (!/[a-zA-Z0-9]/.test(name[j])) {
|
||||
j++;
|
||||
nonAlnum++;
|
||||
}
|
||||
res += nonAlnum;
|
||||
}
|
||||
if (nonAlnum) return res;
|
||||
return '';
|
||||
});
|
||||
|
||||
let BattleSearchCountIndex = {};
|
||||
for (const type in Tools.data.TypeChart) {
|
||||
BattleSearchCountIndex[type + ' move'] = Object.keys(Tools.data.Movedex).filter(id => (Tools.data.Movedex[id].type === type)).length;
|
||||
}
|
||||
|
||||
for (const type in Tools.data.TypeChart) {
|
||||
BattleSearchCountIndex[type + ' pokemon'] = Object.keys(Tools.data.Pokedex).filter(id => (Tools.data.Pokedex[id].types.indexOf(type) >= 0)).length;
|
||||
}
|
||||
|
||||
var buf = '// automatically built with githooks/build-indexes\n\n';
|
||||
|
||||
buf += 'exports.BattleSearchIndex = ' + JSON.stringify(BattleSearchIndex) + ';\n\n';
|
||||
|
||||
buf += 'exports.BattleSearchIndexType = ' + JSON.stringify(BattleSearchIndexType) + ';\n\n';
|
||||
|
||||
buf += 'exports.BattleSearchIndexOffset = ' + JSON.stringify(BattleSearchIndexOffset) + ';\n\n';
|
||||
|
||||
buf += 'exports.BattleSearchCountIndex = ' + JSON.stringify(BattleSearchCountIndex) + ';\n\n';
|
||||
|
||||
fs.writeFileSync('data/search-index.js', buf);
|
||||
}
|
||||
|
||||
console.log("DONE");
|
||||
@@ -14,7 +14,8 @@
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"eslint": "~1.10.3"
|
||||
"eslint": "~1.10.3",
|
||||
"sugar": "1.4.1"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user