Fix chemistry and food/drinks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Hamcha 2021-08-20 16:33:54 +02:00
parent 5074d6180f
commit 960c1ff7b8
Signed by: hamcha
GPG key ID: 41467804B19A3315
6 changed files with 92 additions and 55 deletions

View file

@ -8,7 +8,8 @@ import unknown from "~/assets/images/tab-icons/unknown.svg";
import { bindFunctions } from "./scripts/index"; import { bindFunctions } from "./scripts/index";
// Enable single page mode for developing scripts // Enable single page mode for developing scripts
const devSinglePage = null; // ["Other", "Guide_to_food_and_drinks"]; // const devSinglePage = ["Medical", "Guide_to_chemistry"];
const devSinglePage = null;
async function load() { async function load() {
const sectionListContainer = document.getElementById("section-list"); const sectionListContainer = document.getElementById("section-list");

View file

@ -1,6 +1,7 @@
import { chemistryScript, processChemistry } from "./pages/chemistry"; import { chemistryScript, processChemistry } from "./pages/chemistry";
import { processVirology, virologyScript } from "./pages/virology"; import { processVirology, virologyScript } from "./pages/virology";
import { processFood, foodScript } from "./pages/food"; import { processFood, foodScript } from "./pages/food";
import { processDrinks, drinkScript } from "./pages/drinks";
import { genericScript } from "./pages/generic"; import { genericScript } from "./pages/generic";
import { processGlobal } from "./pages/global"; import { processGlobal } from "./pages/global";
import { welcomeScript } from "./pages/welcome"; import { welcomeScript } from "./pages/welcome";
@ -10,8 +11,8 @@ import { welcomeScript } from "./pages/welcome";
export const PAGE_VERSIONS = { export const PAGE_VERSIONS = {
Infections: "fcebeda2fddb46d924f4538cd9c0daeb55aa4c9b", Infections: "fcebeda2fddb46d924f4538cd9c0daeb55aa4c9b",
Guide_to_food_and_drinks: "131e010df66ed689d31df53c3ca17ad16635a827", Guide_to_food_and_drinks: "131e010df66ed689d31df53c3ca17ad16635a827",
Guide_to_chemistry: "8583fc3b707920eb5cc3a814ec934cfff88803a5", Guide_to_chemistry: "5074d6180fc8b283bac00b99c6aa2325b797da6b",
$DEFAULT: "bb7abd544a19369d4b6b7e3dde3eb3cc34c023d4", $DEFAULT: "5074d6180fc8b283bac00b99c6aa2325b797da6b",
}; };
const MAX_WIDTH = 440; const MAX_WIDTH = 440;
@ -26,9 +27,12 @@ export function processHTML(root: HTMLElement, docname: string): void {
case "Infections": case "Infections":
processVirology(root); processVirology(root);
break; break;
case "Guide_to_food_and_drinks": case "Guide_to_food":
processFood(root); processFood(root);
break; break;
case "Guide_to_drinks":
processDrinks(root);
break;
default: default:
} }
} }
@ -69,10 +73,14 @@ export function bindFunctions(root: HTMLElement, docname: string): void {
case "$Welcome": case "$Welcome":
welcomeScript(root); welcomeScript(root);
break; break;
case "Guide_to_food_and_drinks": case "Guide_to_food":
genericScript(root, docname); genericScript(root, docname);
foodScript(root); foodScript(root);
break; break;
case "Guide_to_drinks":
genericScript(root, docname);
drinkScript(root);
break;
default: default:
genericScript(root, docname); genericScript(root, docname);
break; break;

View file

@ -76,6 +76,8 @@ export function processChemistry(root: HTMLElement): void {
return; return;
} }
const rows = Array.from(row.querySelectorAll("td")).slice(1); const rows = Array.from(row.querySelectorAll("td")).slice(1);
let conditions: HTMLTableCellElement = null;
let explosive: HTMLTableCellElement = null;
let ph: HTMLTableCellElement = null; let ph: HTMLTableCellElement = null;
let treatment: HTMLTableCellElement = null; let treatment: HTMLTableCellElement = null;
let desc: HTMLTableCellElement = null; let desc: HTMLTableCellElement = null;
@ -83,7 +85,6 @@ export function processChemistry(root: HTMLElement): void {
let overdose: HTMLTableCellElement = null; let overdose: HTMLTableCellElement = null;
let addiction: HTMLTableCellElement = null; let addiction: HTMLTableCellElement = null;
// Handle special cases // Handle special cases
console.log(section);
switch (section) { switch (section) {
case "Components": case "Components":
[ph, desc] = rows; [ph, desc] = rows;
@ -98,6 +99,8 @@ export function processChemistry(root: HTMLElement): void {
[ph, desc, metabolism] = rows; [ph, desc, metabolism] = rows;
break; break;
case "Explosive Strength": case "Explosive Strength":
[conditions, desc, explosive] = rows;
break;
case "Mutation Toxins": case "Mutation Toxins":
[desc, metabolism] = rows; [desc, metabolism] = rows;
break; break;
@ -113,6 +116,12 @@ export function processChemistry(root: HTMLElement): void {
if (metabolism) { if (metabolism) {
content += `<p class="metabolism">${metabolism.innerHTML}</p>`; content += `<p class="metabolism">${metabolism.innerHTML}</p>`;
} }
if (conditions) {
content += `<p class="conditions">${conditions.innerHTML}</p>`;
}
if (explosive) {
content += `<p class="explosive">${explosive.innerHTML}</p>`;
}
if (addiction && addiction.innerHTML.trim() !== "N/A") { if (addiction && addiction.innerHTML.trim() !== "N/A") {
content += `<p class="addiction">${addiction.innerHTML}</p>`; content += `<p class="addiction">${addiction.innerHTML}</p>`;
} }
@ -130,6 +139,8 @@ export function processChemistry(root: HTMLElement): void {
if (desc) desc.parentElement.removeChild(desc); if (desc) desc.parentElement.removeChild(desc);
if (treatment) treatment.parentElement.removeChild(treatment); if (treatment) treatment.parentElement.removeChild(treatment);
if (metabolism) metabolism.parentElement.removeChild(metabolism); if (metabolism) metabolism.parentElement.removeChild(metabolism);
if (conditions) conditions.parentElement.removeChild(conditions);
if (explosive) explosive.parentElement.removeChild(explosive);
if (overdose) overdose.parentElement.removeChild(overdose); if (overdose) overdose.parentElement.removeChild(overdose);
if (addiction) addiction.parentElement.removeChild(addiction); if (addiction) addiction.parentElement.removeChild(addiction);
if (ph) ph.parentElement.removeChild(ph); if (ph) ph.parentElement.removeChild(ph);

View file

@ -0,0 +1,50 @@
import { parseTable, makeTable } from "../utils";
import { registerSearchEntries } from "../search";
export function processDrinks(root: HTMLElement): void {
const drinkTables = ["#Basic_Drink_Ingredients", "#Mixed_Drinks"];
drinkTables.forEach((selector) => {
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
const drinks = parseTable(table).map((row) => {
const foodBlock = document.createElement("td");
foodBlock.innerHTML = `
<div class="food-pic">${row["Picture"].innerHTML}</div>
<div class="food-name">${row["Cocktail"].innerHTML}</div>
<p class="strength">${row["Strength"].innerHTML}</p>
<p class="description">${row["Drink Description"].innerHTML}</p>
<p class="notes">${row["Notes"].innerHTML}</p>
`;
const ingredients = row["Ingredients"].innerHTML
.split(/,|\+/gi)
.map((s) => `<p>${s.trim()}</p>`);
row["Ingredients"].innerHTML = ingredients.join("");
return { Drink: foodBlock, Ingredients: row["Ingredients"] };
});
const betterTable = makeTable(["Drink", "Ingredients"], drinks);
betterTable.className = "drink-ext wikitable";
table.replaceWith(betterTable);
});
}
export function drinkScript(root: HTMLElement): void {
// Init fuzzy search with elements
const foodEntries = Array.from(
root.querySelectorAll<HTMLElement>(
".drink-ext tr:not(:first-child), .food-base-ext tr:not(:first-child), .food-ext tr:not(:first-child)"
)
);
registerSearchEntries(
foodEntries.map((element, id) => ({
page: "Guide_to_drinks",
name: element.querySelector(".food-name").textContent.trim(),
element,
alignment: "center",
id,
}))
);
}
export default {
processDrinks,
drinkScript,
};

View file

@ -2,29 +2,6 @@ import { parseTable, makeTable } from "../utils";
import { registerSearchEntries } from "../search"; import { registerSearchEntries } from "../search";
export function processFood(root: HTMLElement): void { export function processFood(root: HTMLElement): void {
const drinkTables = ["#Basic_Drink_Ingredients", "#Mixed_Drinks"];
drinkTables.forEach((selector) => {
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
const drinks = parseTable(table).map((row) => {
const foodBlock = document.createElement("td");
foodBlock.innerHTML = `
<div class="food-pic">${row["Picture"].innerHTML}</div>
<div class="food-name">${row["Cocktail"].innerHTML}</div>
<p class="strength">${row["Strength"].innerHTML}</p>
<p class="description">${row["Drink Description"].innerHTML}</p>
<p class="notes">${row["Notes"].innerHTML}</p>
`;
const ingredients = row["Ingredients"].innerHTML
.split(/,|\+/gi)
.map((s) => `<p>${s.trim()}</p>`);
row["Ingredients"].innerHTML = ingredients.join("");
return { Drink: foodBlock, Ingredients: row["Ingredients"] };
});
const betterTable = makeTable(["Drink", "Ingredients"], drinks);
betterTable.className = "drink-ext wikitable";
table.replaceWith(betterTable);
});
const baseFoodTables = [ const baseFoodTables = [
{ {
selector: "#Butchering", selector: "#Butchering",
@ -56,16 +33,6 @@ export function processFood(root: HTMLElement): void {
title: "Dispenses", title: "Dispenses",
process: "Description", process: "Description",
}, },
{
selector: "#Junk_Drinks",
title: "Dispenses",
process: "Description",
},
{
selector: "#Hot_Drinks",
title: "Dispenses",
process: "Description",
},
{ {
selector: "#Other_food", selector: "#Other_food",
title: "Item", title: "Item",
@ -123,22 +90,21 @@ export function processFood(root: HTMLElement): void {
const foodRecipesTables = [ const foodRecipesTables = [
"#Burgers", "#Burgers",
"#Breads", "#Breads",
"#Sandwiches",
"#Pizzas",
"#Pastas",
"#Soups_\\.26_Stews",
"#Seafood",
"#Meat",
"#Misc\\._Food",
"#Frozen",
"#Pies",
"#Salads",
"#Cakes", "#Cakes",
"#Side_Dishes", "#Egg-Based_Food",
"#Pastries", "#Snowcones",
"#Sweets", "#Lizard_Cuisine",
"#Seafood",
"#Mexican",
"#Savory",
"#Waffles",
"#Pies",
"#Pizzas",
"#Salads",
"#Sandwiches",
"#Soups_\\.26_Stews",
"#Spaghettis",
"#Icecream_Vat", "#Icecream_Vat",
"#Exotic",
]; ];
foodRecipesTables.forEach((selector) => { foodRecipesTables.forEach((selector) => {
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`); const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
@ -175,7 +141,7 @@ export function foodScript(root: HTMLElement): void {
); );
registerSearchEntries( registerSearchEntries(
foodEntries.map((element, id) => ({ foodEntries.map((element, id) => ({
page: "Guide_to_food_and_drinks", page: "Guide_to_food",
name: element.querySelector(".food-name").textContent.trim(), name: element.querySelector(".food-name").textContent.trim(),
element, element,
alignment: "center", alignment: "center",

View file

@ -198,7 +198,8 @@ const sections: SectionInfo[] = [
}, },
{ page: "Critters", icon: critter }, { page: "Critters", icon: critter },
{ page: "Guide_to_races", icon: races }, { page: "Guide_to_races", icon: races },
{ page: "Guide_to_food_and_drinks", text: "food", icon: food }, { page: "Guide_to_food", text: "food", icon: food },
{ page: "Guide_to_drinks", text: "drnk", icon: food },
{ page: "Guide_to_hydroponics", icon: hydro }, { page: "Guide_to_hydroponics", icon: hydro },
{ page: "Songs", icon: song }, { page: "Songs", icon: song },
{ page: "Supply_crates", icon: crate }, { page: "Supply_crates", icon: crate },