inline the character map, use vanilla js

This commit is contained in:
2026-07-08 12:54:45 -06:00
parent 1df9177e14
commit cdfcf749c3
+64 -41
View File
@@ -1,4 +1,4 @@
$(function () { (function () {
// Positions are 1-indexed to match how the original tool (and the // Positions are 1-indexed to match how the original tool (and the
// in-game name entry screen) describes trainer-name character slots. // in-game name entry screen) describes trainer-name character slots.
// Position 1 is never read by the glitch; it's rendered but inert. // Position 1 is never read by the glitch; it's rendered but inert.
@@ -19,40 +19,60 @@ $(function () {
var FALLBACK_SPECIES = "MissingNo."; var FALLBACK_SPECIES = "MissingNo.";
var FALLBACK_LEVEL = 127; var FALLBACK_LEVEL = 127;
var charmap = {}; var charmap = {"A":{"decimal":128,"pokemon":"Golduck"},"B":{"decimal":129,"pokemon":"Hypno"},"C":{"decimal":130,"pokemon":"Golbat"},"D":{"decimal":131,"pokemon":"Mewtwo"},"E":{"decimal":132,"pokemon":"Snorlax"},"F":{"decimal":133,"pokemon":"Magikarp"},"G":{"decimal":134,"pokemon":"MissingNo."},"H":{"decimal":135,"pokemon":"MissingNo."},"I":{"decimal":136,"pokemon":"Muk"},"J":{"decimal":137,"pokemon":"MissingNo."},"K":{"decimal":138,"pokemon":"Kingler"},"L":{"decimal":139,"pokemon":"Cloyster"},"M":{"decimal":140,"pokemon":"MissingNo."},"N":{"decimal":141,"pokemon":"Electrode"},"O":{"decimal":142,"pokemon":"Clefable"},"P":{"decimal":143,"pokemon":"Weezing"},"Q":{"decimal":144,"pokemon":"Persian"},"R":{"decimal":145,"pokemon":"Marowak"},"S":{"decimal":146,"pokemon":"MissingNo."},"T":{"decimal":147,"pokemon":"Haunter"},"U":{"decimal":148,"pokemon":"Abra"},"V":{"decimal":149,"pokemon":"Alakazam"},"W":{"decimal":150,"pokemon":"Pidgeotto"},"X":{"decimal":151,"pokemon":"Pidgeot"},"Y":{"decimal":152,"pokemon":"Starmie"},"Z":{"decimal":153,"pokemon":"Bulbasaur"},"(":{"decimal":154,"pokemon":"Venusaur"},")":{"decimal":155,"pokemon":"Tentacruel"},":":{"decimal":156,"pokemon":"MissingNo."},";":{"decimal":157,"pokemon":"Goldeen"},"[":{"decimal":158,"pokemon":"Seaking"},"]":{"decimal":159,"pokemon":"MissingNo."},"a":{"decimal":160,"pokemon":"MissingNo."},"b":{"decimal":161,"pokemon":"MissingNo."},"c":{"decimal":162,"pokemon":"MissingNo."},"d":{"decimal":163,"pokemon":"Ponyta"},"e":{"decimal":164,"pokemon":"Rapidash"},"f":{"decimal":165,"pokemon":"Rattata"},"g":{"decimal":166,"pokemon":"Raticate"},"h":{"decimal":167,"pokemon":"Nidorino"},"i":{"decimal":168,"pokemon":"Nidorina"},"j":{"decimal":169,"pokemon":"Geodude"},"k":{"decimal":170,"pokemon":"Porygon"},"l":{"decimal":171,"pokemon":"Aerodactyl"},"m":{"decimal":172,"pokemon":"MissingNo."},"n":{"decimal":173,"pokemon":"Magnemite"},"o":{"decimal":174,"pokemon":"MissingNo."},"p":{"decimal":175,"pokemon":"MissingNo."},"q":{"decimal":176,"pokemon":"Charmander"},"r":{"decimal":177,"pokemon":"Squirtle"},"s":{"decimal":178,"pokemon":"Charmeleon"},"t":{"decimal":179,"pokemon":"Wartortle"},"u":{"decimal":180,"pokemon":"Charizard"},"v":{"decimal":181,"pokemon":"MissingNo."},"w":{"decimal":182,"pokemon":"Kabutops Fossil"},"x":{"decimal":183,"pokemon":"Aerodactyl Fossil"},"y":{"decimal":184,"pokemon":"Ghost"},"z":{"decimal":185,"pokemon":"Oddish"},"PK":{"decimal":225,"pokemon":"Rival (#1)"},"MN":{"decimal":226,"pokemon":"Professor Oak"},"-":{"decimal":227,"pokemon":"Chief"},"?":{"decimal":230,"pokemon":"Rocket"},"!":{"decimal":231,"pokemon":"Cooltrainer Male"},"♂":{"decimal":239,"pokemon":"Blaine"},"×":{"decimal":241,"pokemon":"Gentleman"},".":{"decimal":242,"pokemon":"Rival (#2)"},"/":{"decimal":243,"pokemon":"Rival (Final)"},",":{"decimal":244,"pokemon":"Lorelei"},"♀":{"decimal":245,"pokemon":"Channeler"},"0":{"decimal":246,"pokemon":"Agatha"},"1":{"decimal":247,"pokemon":"Lance"},"2":{"decimal":248,"pokemon":"Glitch - Freezes Game"},"3":{"decimal":249,"pokemon":"Glitch - Freezes Game"},"4":{"decimal":250,"pokemon":"Glitch - Freezes Game"},"5":{"decimal":251,"pokemon":"Glitch Trainer (Can be used for ZZAZZ Glitch)"},"6":{"decimal":252,"pokemon":"Glitch Trainer (Can be used for ZZAZZ Glitch)"},"7":{"decimal":253,"pokemon":"Glitch Trainer (Freezes after battle)"},"8":{"decimal":254,"pokemon":"Glitch Trainer (Can be used for ZZAZZ Glitch)"},"9":{"decimal":255,"pokemon":"Glitch Trainer (Can be used for ZZAZZ Glitch)"}};
var $nameRow = $("#name-row");
var $results = $("#results"); var nameRow = document.getElementById("name-row");
var results = document.getElementById("results");
for (var i = 1; i <= 7; i++) { for (var i = 1; i <= 7; i++) {
var $slot = $('<div class="slot"></div>'); (function (i) {
$slot.append('<div class="index">char ' + i + '</div>'); var slot = document.createElement("div");
$slot.append('<div class="role">' + ROLE_LABEL[i] + '</div>'); slot.className = "slot";
var $input = $('<input type="text" maxlength="2" autocomplete="off" spellcheck="false">') var index = document.createElement("div");
.attr("id", "char" + i) index.className = "index";
.data("pos", i); index.textContent = "char " + i;
$slot.append($input); slot.appendChild(index);
var role = document.createElement("div");
role.className = "role";
role.textContent = ROLE_LABEL[i];
slot.appendChild(role);
var input = document.createElement("input");
input.type = "text";
input.maxLength = 2;
input.autocomplete = "off";
input.spellcheck = false;
input.id = "char" + i;
input.dataset.pos = i;
slot.appendChild(input);
if (i > 1) { if (i > 1) {
var $symbols = $('<div class="symbols"></div>'); var symbols = document.createElement("div");
symbols.className = "symbols";
SYMBOL_BUTTONS.forEach(function (sym) { SYMBOL_BUTTONS.forEach(function (sym) {
var $btn = $('<button type="button"></button>').text(sym); var btn = document.createElement("button");
$btn.on("click", function () { btn.type = "button";
$input.val($(this).text()); btn.textContent = sym;
btn.addEventListener("click", function () {
input.value = sym;
decode(); decode();
focusNext(i); focusNext(i);
}); });
$symbols.append($btn); symbols.appendChild(btn);
}); });
$slot.append($symbols); slot.appendChild(symbols);
} }
$nameRow.append($slot); nameRow.appendChild(slot);
})(i);
} }
$nameRow.on("input", "input", function () { nameRow.addEventListener("input", function (event) {
var pos = $(this).data("pos"); if (event.target.tagName !== "INPUT") return;
if (this.value.length >= 1) { var pos = parseInt(event.target.dataset.pos, 10);
if (event.target.value.length >= 1) {
focusNext(pos); focusNext(pos);
} }
decode(); decode();
@@ -60,7 +80,7 @@ $(function () {
function focusNext(pos) { function focusNext(pos) {
if (pos < 7) { if (pos < 7) {
$("#char" + (pos + 1)).trigger("focus"); document.getElementById("char" + (pos + 1)).focus();
} }
} }
@@ -72,10 +92,10 @@ $(function () {
function decode() { function decode() {
var chars = []; var chars = [];
for (var i = 1; i <= 7; i++) { for (var i = 1; i <= 7; i++) {
chars[i] = $("#char" + i).val(); chars[i] = document.getElementById("char" + i).value;
} }
$results.empty(); results.innerHTML = "";
for (var pair = 0; pair < 3; pair++) { for (var pair = 0; pair < 3; pair++) {
var speciesPos = SPECIES_POSITIONS[pair]; var speciesPos = SPECIES_POSITIONS[pair];
var levelPos = LEVEL_POSITIONS[pair]; var levelPos = LEVEL_POSITIONS[pair];
@@ -86,24 +106,27 @@ $(function () {
var species = speciesEntry ? speciesEntry.pokemon : FALLBACK_SPECIES; var species = speciesEntry ? speciesEntry.pokemon : FALLBACK_SPECIES;
var level = levelEntry ? levelEntry.decimal : FALLBACK_LEVEL; var level = levelEntry ? levelEntry.decimal : FALLBACK_LEVEL;
var $card = $('<div class="encounter"></div>'); var card = document.createElement("div");
$card.append('<div class="from">from char ' + speciesPos + ' &amp; char ' + levelPos + '</div>'); card.className = "encounter";
$card.append('<div class="species">' + escapeHtml(species) + '</div>');
$card.append('<div class="level">Level ' + level + '</div>'); var from = document.createElement("div");
$results.append($card); from.className = "from";
from.textContent = "from char " + speciesPos + " & char " + levelPos;
card.appendChild(from);
var speciesEl = document.createElement("div");
speciesEl.className = "species";
speciesEl.textContent = species;
card.appendChild(speciesEl);
var levelEl = document.createElement("div");
levelEl.className = "level";
levelEl.textContent = "Level " + level;
card.appendChild(levelEl);
results.appendChild(card);
} }
} }
function escapeHtml(str) {
return $("<div>").text(str).html();
}
$.getJSON("data/charmap.json")
.done(function (data) {
charmap = data;
decode(); decode();
}) })();
.fail(function () {
$("#load-error").show();
});
});