Fewer merge conflicts: actions by area, one city per line, sorted dictionaries
- ACT is split by area into game/90-actions/*.js (const ACT in the first file, Object.assign in the rest) - CITY_LL, CITY_NUDGE and LANDS_LL have one entry per line; the id-keyed ones are sorted - site/i18n/*.js are sorted, one entry per line; i18n-check enforces it and --fix (npm run i18n:fix) restores it; scripts/i18n-add.js adds, removes and renames entries in place - scripts/legacy/port-branch.js moves a branch's site/index.html edits into src/ during a merge with main - perf workflow and PR template build the base page with scripts/lib/page.js
This commit is contained in:
parent
67a40942b4
commit
c64b139a86
27 changed files with 9582 additions and 8971 deletions
5
.github/pull_request_template.md
vendored
5
.github/pull_request_template.md
vendored
|
|
@ -8,8 +8,7 @@
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
|
|
||||||
<!-- Changes to site/ must show their performance on a big network. The Performance check posts the
|
<!-- Changes to src/ must show their performance on a big network. The Performance check posts the
|
||||||
numbers as a comment on this PR. Locally:
|
numbers as a comment on this PR. Locally:
|
||||||
git show origin/main:site/index.html > /tmp/base.html
|
npm run perf -- --base-ref origin/main
|
||||||
npm run perf -- --base /tmp/base.html
|
|
||||||
Explain anything marked slower. -->
|
Explain anything marked slower. -->
|
||||||
|
|
|
||||||
5
.github/workflows/perf.yml
vendored
5
.github/workflows/perf.yml
vendored
|
|
@ -6,7 +6,9 @@ name: Performance
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
|
- 'src/**'
|
||||||
- 'site/**'
|
- 'site/**'
|
||||||
|
- 'scripts/lib/**'
|
||||||
- 'scripts/perf-*.js'
|
- 'scripts/perf-*.js'
|
||||||
- 'tests/fixtures/**'
|
- 'tests/fixtures/**'
|
||||||
- 'tests/harness.js'
|
- 'tests/harness.js'
|
||||||
|
|
@ -32,7 +34,8 @@ jobs:
|
||||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||||
run: |
|
run: |
|
||||||
git fetch --depth=1 origin "$BASE_SHA"
|
git fetch --depth=1 origin "$BASE_SHA"
|
||||||
git show FETCH_HEAD:site/index.html > "$RUNNER_TEMP/base.html"
|
# The base's page, assembled by the base's own scripts (or its site/index.html from before the split).
|
||||||
|
node scripts/lib/page.js --ref FETCH_HEAD -o "$RUNNER_TEMP/base.html"
|
||||||
echo "BASE_ARG=--base $RUNNER_TEMP/base.html" >> "$GITHUB_ENV"
|
echo "BASE_ARG=--base $RUNNER_TEMP/base.html" >> "$GITHUB_ENV"
|
||||||
- name: Benchmark
|
- name: Benchmark
|
||||||
# The runner image ships Google Chrome; playwright-core (a dev dependency) drives it, no browser download.
|
# The runner image ships Google Chrome; playwright-core (a dev dependency) drives it, no browser download.
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
"test": "node scripts/test.js",
|
"test": "node scripts/test.js",
|
||||||
"build": "node scripts/build.js",
|
"build": "node scripts/build.js",
|
||||||
"i18n:check": "node scripts/i18n-check.js",
|
"i18n:check": "node scripts/i18n-check.js",
|
||||||
|
"i18n:fix": "node scripts/i18n-check.js --fix",
|
||||||
"dev": "node scripts/dev.js",
|
"dev": "node scripts/dev.js",
|
||||||
"page": "node scripts/lib/page.js",
|
"page": "node scripts/lib/page.js",
|
||||||
"serve": "npm run build && npx --yes serve@14.2.4 _site",
|
"serve": "npm run build && npx --yes serve@14.2.4 _site",
|
||||||
|
|
|
||||||
39
scripts/i18n-add.js
Normal file
39
scripts/i18n-add.js
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
// Adds, changes, renames or removes dictionary entries, keeping every site/i18n/*.js sorted (scripts/lib/dict.js).
|
||||||
|
//
|
||||||
|
// node scripts/i18n-add.js changes.json {"it": {"English": "Italiano", "Old text": null}, "pt": {…}}
|
||||||
|
// a string adds or replaces the entry, null removes it
|
||||||
|
// node scripts/i18n-add.js - the same JSON from stdin
|
||||||
|
// node scripts/i18n-add.js --rename "Old English" "New English" move a key in every dictionary
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const D = require('./lib/dict');
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
if (args[0] === '--rename') {
|
||||||
|
const [, from, to] = args;
|
||||||
|
if (!from || !to) { console.error('usage: i18n-add.js --rename "Old English" "New English"'); process.exit(2); }
|
||||||
|
for (const lang of D.langs()) {
|
||||||
|
const { header, dict } = D.read(lang);
|
||||||
|
if (!(from in dict)) { console.log(`${lang}: no entry for ${JSON.stringify(from)}`); continue; }
|
||||||
|
if (to in dict && to !== from) { console.error(`${lang}: already has ${JSON.stringify(to)}`); process.exit(1); }
|
||||||
|
dict[to] = dict[from];
|
||||||
|
if (to !== from) delete dict[from];
|
||||||
|
D.write(lang, dict, header);
|
||||||
|
console.log(`${lang}: renamed`);
|
||||||
|
}
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
if (args.length !== 1) { console.error('usage: i18n-add.js changes.json | - | --rename OLD NEW'); process.exit(2); }
|
||||||
|
const changes = JSON.parse(fs.readFileSync(args[0] === '-' ? 0 : args[0], 'utf8'));
|
||||||
|
for (const [lang, entries] of Object.entries(changes)) {
|
||||||
|
if (!D.langs().includes(lang)) { console.error(`no dictionary site/i18n/${lang}.js`); process.exit(1); }
|
||||||
|
const { header, dict } = D.read(lang);
|
||||||
|
let add = 0, del = 0;
|
||||||
|
for (const [en, xx] of Object.entries(entries)) {
|
||||||
|
if (xx === null) { if (en in dict) { delete dict[en]; del++; } continue; }
|
||||||
|
if (typeof xx !== 'string' || !xx.trim()) { console.error(`${lang}: empty translation for ${JSON.stringify(en)}`); process.exit(1); }
|
||||||
|
dict[en] = xx; add++;
|
||||||
|
}
|
||||||
|
D.write(lang, dict, header);
|
||||||
|
console.log(`${lang}: ${add} added or changed, ${del} removed`);
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
// Checks a translation against the English text in the game page (assembled from src/): every tr()/trn()/N_() literal and
|
// Checks a translation against the English text in the game page (assembled from src/): every tr()/trn()/N_() literal and
|
||||||
// every data-i18n text, aria-label and title in the static markup should have an entry, no stale entry
|
// every data-i18n text, aria-label and title in the static markup should have an entry, no stale entry
|
||||||
// should linger, and each translation must keep the {placeholders} and HTML tags of its English key.
|
// should linger, and each translation must keep the {placeholders} and HTML tags of its English key.
|
||||||
// Usage: node scripts/i18n-check.js [lang ...] [--summary FILE] (default: every site/i18n/*.js)
|
// Usage: node scripts/i18n-check.js [lang ...] [--summary FILE] [--fix] (default: every site/i18n/*.js)
|
||||||
|
// Dictionaries must also be sorted, one entry per line (scripts/lib/dict.js); --fix sorts them.
|
||||||
// It also checks that each language is offered in the game and cached for offline play, and with --summary
|
// It also checks that each language is offered in the game and cached for offline play, and with --summary
|
||||||
// appends a Markdown coverage table (the CI job writes it to the run's summary page).
|
// appends a Markdown coverage table (the CI job writes it to the run's summary page).
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
|
|
@ -65,6 +66,7 @@ function registration(lang) {
|
||||||
const m = html.match(/SOT_LANGS=\{([^}]*)\}/);
|
const m = html.match(/SOT_LANGS=\{([^}]*)\}/);
|
||||||
if (!m || !new RegExp(String.raw`(^|[,{\s])${lang}\s*:`).test(m[1])) out.push('not in the language list (SOT_LANGS in src/index.html)');
|
if (!m || !new RegExp(String.raw`(^|[,{\s])${lang}\s*:`).test(m[1])) out.push('not in the language list (SOT_LANGS in src/index.html)');
|
||||||
if (!sw.includes(`/i18n/${lang}.js`)) out.push('not cached for offline play (CORE in site/sw.js)');
|
if (!sw.includes(`/i18n/${lang}.js`)) out.push('not cached for offline play (CORE in site/sw.js)');
|
||||||
|
if (!require('./lib/dict').tidy(lang)) out.push('not sorted one entry per line: run npm run i18n:fix');
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,6 +74,12 @@ if (require.main === module) {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const si = args.indexOf('--summary');
|
const si = args.indexOf('--summary');
|
||||||
const summary = si >= 0 ? args.splice(si, 2)[1] : null; // append a Markdown table here (CI: $GITHUB_STEP_SUMMARY)
|
const summary = si >= 0 ? args.splice(si, 2)[1] : null; // append a Markdown table here (CI: $GITHUB_STEP_SUMMARY)
|
||||||
|
const fi = args.indexOf('--fix');
|
||||||
|
if (fi >= 0) {
|
||||||
|
args.splice(fi, 1);
|
||||||
|
const D = require('./lib/dict');
|
||||||
|
for (const lang of args.length ? args : D.langs()) { const { header, dict } = D.read(lang); D.write(lang, dict, header); }
|
||||||
|
}
|
||||||
const keys = sourceKeys(page());
|
const keys = sourceKeys(page());
|
||||||
const files = (args.length ? args.map((l) => `${l}.js`) : fs.readdirSync(path.join(SITE, 'i18n')))
|
const files = (args.length ? args.map((l) => `${l}.js`) : fs.readdirSync(path.join(SITE, 'i18n')))
|
||||||
.map((f) => path.join(SITE, 'i18n', f));
|
.map((f) => path.join(SITE, 'i18n', f));
|
||||||
|
|
|
||||||
96
scripts/legacy/port-branch.js
Normal file
96
scripts/legacy/port-branch.js
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
// Carries a branch that still edits site/index.html (started before the page was split into src/) over
|
||||||
|
// to the src/ layout. Run it in the middle of merging main into that branch:
|
||||||
|
//
|
||||||
|
// git checkout my-branch
|
||||||
|
// git merge origin/main # stops: site/index.html was deleted on main
|
||||||
|
// node scripts/legacy/port-branch.js # moves your edits into src/, merges the dictionaries
|
||||||
|
// git status # fix any conflict markers it reports, then
|
||||||
|
// git commit
|
||||||
|
//
|
||||||
|
// How: your branch's site/index.html and the one you started from are both split with the same rules
|
||||||
|
// that made src/ (split-index-html.js + transforms.js), and each partial gets a three-way merge
|
||||||
|
// (git merge-file) into the src/ file from main. Your dictionary changes (site/i18n/*.js) are applied
|
||||||
|
// entry by entry onto main's sorted dictionaries, so appended lines never conflict.
|
||||||
|
//
|
||||||
|
// Options: --base REF (the pre-split commit your page started from; default: merge-base of HEAD and
|
||||||
|
// MERGE_HEAD) and --theirs REF (your branch; default HEAD).
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const os = require('node:os');
|
||||||
|
const path = require('node:path');
|
||||||
|
const { execFileSync, spawnSync } = require('node:child_process');
|
||||||
|
const { split } = require('./split-index-html');
|
||||||
|
const { transform } = require('./transforms');
|
||||||
|
const D = require('../lib/dict');
|
||||||
|
|
||||||
|
const ROOT = path.join(__dirname, '..', '..');
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const opt = (k, d) => { const i = args.indexOf(k); return i >= 0 ? args[i + 1] : d; };
|
||||||
|
const git = (...a) => execFileSync('git', a, { cwd: ROOT, encoding: 'utf8', maxBuffer: 1 << 28, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||||
|
const show = (ref, p) => { try { return git('show', `${ref}:${p}`); } catch { return null; } };
|
||||||
|
const die = (m) => { console.error(`port-branch: ${m}`); process.exit(1); };
|
||||||
|
|
||||||
|
let mergeHead = null;
|
||||||
|
try { mergeHead = git('rev-parse', '-q', '--verify', 'MERGE_HEAD').trim(); } catch {}
|
||||||
|
const theirs = opt('--theirs', 'HEAD');
|
||||||
|
const base = opt('--base', null) || (mergeHead ? git('merge-base', theirs, mergeHead).trim() : null);
|
||||||
|
if (!base) die('no merge in progress: run `git merge origin/main` first, or pass --base REF');
|
||||||
|
if (!fs.existsSync(path.join(ROOT, 'src', 'index.html'))) die('src/ is missing: merge main (which has src/) first');
|
||||||
|
|
||||||
|
const basePage = show(base, 'site/index.html'), theirPage = show(theirs, 'site/index.html');
|
||||||
|
if (!basePage) die(`${base} has no site/index.html; is it from before the split?`);
|
||||||
|
if (!theirPage) die(`${theirs} has no site/index.html; nothing to port`);
|
||||||
|
|
||||||
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-port-'));
|
||||||
|
const parts = (html, label) => {
|
||||||
|
try { return new Map(transform(split(html))); }
|
||||||
|
catch (e) { die(`could not split ${label}'s site/index.html the way src/ was made: ${e.message}`); }
|
||||||
|
};
|
||||||
|
const B = parts(basePage, 'the base'), T = parts(theirPage, 'your branch');
|
||||||
|
let changed = 0;
|
||||||
|
const conflicts = [];
|
||||||
|
for (const [file, t] of T) {
|
||||||
|
const b = B.get(file);
|
||||||
|
if (b === t) continue; // you did not touch this part
|
||||||
|
const ours = path.join(ROOT, 'src', file);
|
||||||
|
if (!fs.existsSync(ours)) { conflicts.push(`${file} (no longer exists on main; apply your change by hand)`); continue; }
|
||||||
|
const fb = path.join(tmp, 'base'), ft = path.join(tmp, 'theirs');
|
||||||
|
fs.writeFileSync(fb, b || '');
|
||||||
|
fs.writeFileSync(ft, t);
|
||||||
|
const r = spawnSync('git', ['merge-file', '-L', 'main', '-L', 'base', '-L', 'your branch', ours, fb, ft], { cwd: ROOT });
|
||||||
|
changed++;
|
||||||
|
if (r.status !== 0) conflicts.push(`src/${file}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dictionaries: your additions, edits and removals, applied onto main's sorted files.
|
||||||
|
for (const lang of D.langs()) {
|
||||||
|
const rel = `site/i18n/${lang}.js`;
|
||||||
|
const tb = show(base, rel), tt = show(theirs, rel);
|
||||||
|
if (!tt || tb === tt) continue;
|
||||||
|
const db = tb ? D.parse(tb, lang) : {}, dt = D.parse(tt, lang);
|
||||||
|
const main = mergeHead ? show(mergeHead, rel) : null;
|
||||||
|
// During a merge the working file may hold conflict markers, so start from main's own copy.
|
||||||
|
const { header, dict } = main ? { header: main.slice(0, main.indexOf('(window.I18N')), dict: D.parse(main, lang) } : D.read(lang);
|
||||||
|
let n = 0;
|
||||||
|
for (const k of new Set([...Object.keys(db), ...Object.keys(dt)])) {
|
||||||
|
if (db[k] === dt[k]) continue;
|
||||||
|
if (k in dict && db[k] !== dict[k] && dict[k] !== dt[k] && k in dt) conflicts.push(`${rel}: ${JSON.stringify(k)} changed on both sides (kept yours)`);
|
||||||
|
if (k in dt) dict[k] = dt[k]; else delete dict[k];
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
D.write(lang, dict, header);
|
||||||
|
git('add', rel);
|
||||||
|
console.log(`${rel}: ${n} of your entries applied`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(path.join(ROOT, 'site', 'index.html'))) fs.rmSync(path.join(ROOT, 'site', 'index.html'));
|
||||||
|
try { git('rm', '-q', '--cached', '--ignore-unmatch', 'site/index.html'); } catch {}
|
||||||
|
fs.rmSync(tmp, { recursive: true, force: true });
|
||||||
|
console.log(`Ported your site/index.html changes into ${changed} file(s) under src/.`);
|
||||||
|
if (conflicts.length) {
|
||||||
|
console.log('Resolve these by hand (look for <<<<<<< markers), then git add them:');
|
||||||
|
for (const c of conflicts) console.log(` ${c}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
git('add', 'src');
|
||||||
|
console.log('No conflicts. Run npm test, then git commit.');
|
||||||
|
|
@ -1,2 +1,98 @@
|
||||||
// Tidying applied after the split (filled in by the next commit).
|
// Tidying applied right after the split, to cut down merge conflicts. Each one keeps behaviour the same
|
||||||
module.exports = { transform: (parts) => parts };
|
// and only changes where code sits or how a literal is laid out. They run as part of
|
||||||
|
// split-index-html.js, so work from older branches lines up with src/ when it is ported.
|
||||||
|
//
|
||||||
|
// 1. The ACT map (every player action) becomes one file per area under game/90-actions/: the first file
|
||||||
|
// declares `const ACT={…}` and the others add to it with Object.assign. Two people adding actions in
|
||||||
|
// different areas no longer touch the same lines.
|
||||||
|
// 2. Coordinate tables that lived on one very long line (CITY_LL, CITY_NUDGE, LANDS_LL) get one entry per
|
||||||
|
// line, CITY_LL and CITY_NUDGE sorted by id: adding a city no longer edits a 4,000-character line
|
||||||
|
// that everyone else is editing too.
|
||||||
|
|
||||||
|
// [file, first action in it]. A group runs until the next group's first action.
|
||||||
|
const ACT_GROUPS = [
|
||||||
|
['game/90-actions/10-interface.js', 'speed'],
|
||||||
|
['game/90-actions/20-pops-transit-ix.js', 'buildPop'],
|
||||||
|
['game/90-actions/30-route-script-and-tools.js', 'teEdit'],
|
||||||
|
['game/90-actions/40-sites-peering-caches.js', 'addSite'],
|
||||||
|
['game/90-actions/50-customers.js', 'advertise'],
|
||||||
|
['game/90-actions/60-links.js', 'upLink'],
|
||||||
|
['game/90-actions/70-dashboard-lists.js', 'custGo'],
|
||||||
|
['game/90-actions/80-security-and-china.js', 'applyCn'],
|
||||||
|
['game/90-actions/85-routing-and-routers.js', 'via'],
|
||||||
|
['game/90-actions/87-fiber-and-hardware.js', 'dfMode'],
|
||||||
|
['game/90-actions/89-game-and-settings.js', 'randomName'],
|
||||||
|
];
|
||||||
|
|
||||||
|
function splitActions(text) {
|
||||||
|
const lines = text.split('\n');
|
||||||
|
if (lines[lines.length - 1] === '') lines.pop();
|
||||||
|
const open = lines.indexOf('const ACT={'), close = lines.lastIndexOf('};');
|
||||||
|
if (open < 0 || close < open) throw new Error('90-actions: no `const ACT={ … };` block');
|
||||||
|
if (lines.slice(close + 1).some((l) => l.trim())) throw new Error('90-actions: code after the ACT block');
|
||||||
|
const keyAt = (k) => lines.findIndex((l, i) => i > open && i < close && l.startsWith(` ${k}:`));
|
||||||
|
const starts = ACT_GROUPS.map(([file, k]) => {
|
||||||
|
const i = keyAt(k);
|
||||||
|
if (i < 0) throw new Error(`90-actions: action ${k} not found (for ${file})`);
|
||||||
|
return i;
|
||||||
|
});
|
||||||
|
if (starts.some((s, i) => i && s <= starts[i - 1])) throw new Error('90-actions: actions are out of the expected order');
|
||||||
|
return ACT_GROUPS.map(([file], g) => {
|
||||||
|
const from = g ? starts[g] : 0, to = g + 1 < starts.length ? starts[g + 1] : close;
|
||||||
|
const body = lines.slice(from, to);
|
||||||
|
const out = g ? ['Object.assign(ACT,{', ...body, '});'] : [...body, '};'];
|
||||||
|
return [file, out.join('\n') + '\n'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The top-level entries of an array or object literal source "a,b,c" (no brackets around it).
|
||||||
|
function entries(src) {
|
||||||
|
const out = [];
|
||||||
|
let depth = 0, q = null, start = 0;
|
||||||
|
for (let i = 0; i < src.length; i++) {
|
||||||
|
const c = src[i];
|
||||||
|
if (q) { if (c === '\\') i++; else if (c === q) q = null; continue; }
|
||||||
|
if (c === '"' || c === "'" || c === '`') q = c;
|
||||||
|
else if ('[{('.includes(c)) depth++;
|
||||||
|
else if (']})'.includes(c)) depth--;
|
||||||
|
else if (c === ',' && depth === 0) { out.push(src.slice(start, i).trim()); start = i + 1; }
|
||||||
|
}
|
||||||
|
if (depth || q) throw new Error('unbalanced literal');
|
||||||
|
const last = src.slice(start).trim();
|
||||||
|
if (last) out.push(last);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
const idOf = (e) => e.match(/^["']?([\w$]+)["']?\s*:/)[1];
|
||||||
|
const byId = (a, b) => (idOf(a) < idOf(b) ? -1 : idOf(a) > idOf(b) ? 1 : 0);
|
||||||
|
|
||||||
|
// `HEAD{entries}TAIL` on one line → HEAD, one entry per line, TAIL. Lines that don't match stay as they are.
|
||||||
|
function oneLine(text, re, { sort = false, indent = ' ' } = {}) {
|
||||||
|
return text.split('\n').map((l) => {
|
||||||
|
const m = re.exec(l);
|
||||||
|
if (!m) return l;
|
||||||
|
let es = entries(m[2]);
|
||||||
|
if (sort) {
|
||||||
|
// Sorting is only safe without duplicate keys (with duplicates, the last one wins).
|
||||||
|
const ids = es.map(idOf);
|
||||||
|
if (new Set(ids).size !== ids.length) throw new Error(`duplicate keys in ${m[1]}`);
|
||||||
|
es = es.slice().sort(byId);
|
||||||
|
}
|
||||||
|
return [m[1], ...es.map((e) => indent + e + ','), m[3]].join('\n');
|
||||||
|
}).join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
function transform(parts) {
|
||||||
|
const out = [];
|
||||||
|
for (const [file, text] of parts) {
|
||||||
|
if (file === 'game/90-actions/00-actions.js') out.push(...splitActions(text));
|
||||||
|
else if (file === 'game/20-world/40-city-coords.js') out.push([file, oneLine(text, /^(const CITY_LL=\{)(.*)(\};)$/, { sort: true })]);
|
||||||
|
else if (file === 'game/20-world/50-cities.js') out.push([file, oneLine(text, /^(const CITY_NUDGE=\{)(.*)(\};)$/, { sort: true })]);
|
||||||
|
else if (file === 'game/20-world/20-landmasses.js') {
|
||||||
|
out.push([file, oneLine(oneLine(text, /^(const LANDS_LL=\[)(.*)(\];)$/), /^(LANDS_LL\.push\()(.*)(\);)$/)]);
|
||||||
|
} else out.push([file, text]);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { transform, entries };
|
||||||
|
|
|
||||||
46
scripts/lib/dict.js
Normal file
46
scripts/lib/dict.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
// Reads and writes the translation dictionaries in site/i18n/<lang>.js.
|
||||||
|
//
|
||||||
|
// Every dictionary is kept in one canonical layout: the header comment, then one `"English":"Translation",`
|
||||||
|
// entry per line, sorted by the English text. Sorted entries spread new strings across the file instead of
|
||||||
|
// piling them up at the end, so two pull requests that each add strings rarely touch the same lines.
|
||||||
|
// `npm run i18n:check` reports a dictionary that is out of order; `npm run i18n:fix` puts it back.
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const vm = require('node:vm');
|
||||||
|
|
||||||
|
const DIR = path.join(__dirname, '..', '..', 'site', 'i18n');
|
||||||
|
const fileOf = (lang) => path.join(DIR, `${lang}.js`);
|
||||||
|
const langs = () => fs.readdirSync(DIR).filter((f) => f.endsWith('.js')).map((f) => path.basename(f, '.js')).sort();
|
||||||
|
|
||||||
|
// Plain code-unit order: the same on every machine, whatever its locale.
|
||||||
|
const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
||||||
|
|
||||||
|
function parse(text, lang) {
|
||||||
|
const window = {};
|
||||||
|
vm.runInNewContext(text, { window });
|
||||||
|
return (window.I18N || {})[lang] || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
function read(lang) {
|
||||||
|
const text = fs.readFileSync(fileOf(lang), 'utf8');
|
||||||
|
const open = text.indexOf(`(window.I18N=window.I18N||{}).${lang}={`);
|
||||||
|
if (open < 0) throw new Error(`${lang}.js: missing the (window.I18N=window.I18N||{}).${lang}={ line`);
|
||||||
|
return { text, header: text.slice(0, open), dict: parse(text, lang) };
|
||||||
|
}
|
||||||
|
|
||||||
|
function format(lang, header, dict) {
|
||||||
|
const keys = Object.keys(dict).sort(cmp);
|
||||||
|
return `${header}(window.I18N=window.I18N||{}).${lang}={\n${keys.map((k) => `${JSON.stringify(k)}:${JSON.stringify(dict[k])},\n`).join('')}};\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// True when the file is already in the canonical layout.
|
||||||
|
function tidy(lang) {
|
||||||
|
const { text, header, dict } = read(lang);
|
||||||
|
return text === format(lang, header, dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
function write(lang, dict, header = read(lang).header) {
|
||||||
|
fs.writeFileSync(fileOf(lang), format(lang, header, dict));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { DIR, fileOf, langs, read, write, format, tidy, parse, cmp };
|
||||||
|
|
@ -74,7 +74,7 @@ function locate(map, line) {
|
||||||
|
|
||||||
// The page at a git ref: that commit's src/ through its own assembler, or site/index.html before the split.
|
// The page at a git ref: that commit's src/ through its own assembler, or site/index.html before the split.
|
||||||
function assembleRef(ref, cwd = ROOT) {
|
function assembleRef(ref, cwd = ROOT) {
|
||||||
const git = (...a) => execFileSync('git', a, { cwd, encoding: 'utf8', maxBuffer: 1 << 28 });
|
const git = (...a) => execFileSync('git', a, { cwd, encoding: 'utf8', maxBuffer: 1 << 28, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||||
const has = (p) => { try { git('cat-file', '-e', `${ref}:${p}`); return true; } catch { return false; } };
|
const has = (p) => { try { git('cat-file', '-e', `${ref}:${p}`); return true; } catch { return false; } };
|
||||||
if (!has('src/index.html')) return git('show', `${ref}:site/index.html`);
|
if (!has('src/index.html')) return git('show', `${ref}:site/index.html`);
|
||||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-ref-'));
|
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'tubes-ref-'));
|
||||||
|
|
|
||||||
5794
site/i18n/fr.js
5794
site/i18n/fr.js
File diff suppressed because it is too large
Load diff
5766
site/i18n/it.js
5766
site/i18n/it.js
File diff suppressed because it is too large
Load diff
5766
site/i18n/pt.js
5766
site/i18n/pt.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
|
@ -1 +1,204 @@
|
||||||
const CITY_LL={"chc":[172.55,-43.53],"ivc":[168.35,-46.41],"adl":[138.6,-34.93],"cbr":[149.13,-35.28],"hba":[147.25,-42.85],"hfx":[-63.62,44.68],"bda":[-64.78,32.29],"pdl":[-25.67,37.74],"tci":[-16.3,28.44],"rai":[-23.55,14.98],"jam":[-5.72,-15.93],"man":[-2.24,53.48],"edi":[-3.19,55.95],"bde":[-4.54,50.83],"svg":[5.73,58.97],"bcn":[2.17,41.39],"mil":[9.19,45.46],"rom":[12.5,41.9],"pmo":[13.36,38.12],"lis":[-9.14,38.72],"ath":[23.73,37.98],"atn":[-84.39,33.75],"den":[-104.99,39.74],"phx":[-112.07,33.45],"bos":[-71.06,42.36],"hou":[-95.37,29.76],"slc":[-111.89,40.76],"jed":[39.25,21.55],"ruh":[46.72,24.71],"doh":[51.45,25.28],"kyv":[30.52,50.45],"mel":[144.96, -37.81],"bne":[153.03, -27.47],"drw":[131.05,-12.46],"osa":[135.5, 34.69],"kul":[101.69, 3.14],"bkk":[100.5, 13.76],"sgn":[106.66, 10.76],"khi":[67.14,25.0],"dac":[90.41, 23.81],"cbo":[80.0, 6.95],"waw":[21.01, 52.23],"prg":[14.42, 50.08],"vie":[16.37, 48.21],"bud":[19.04, 47.5],"buh":[26.1, 44.43],"tll":[24.45,58.9],"ist":[28.98, 41.01],"for":[-38.54, -3.73],"rio":[-43.11,-22.57],"bsb":[-47.88,-15.79],"bhz":[-43.94,-19.92],"cwb":[-49.27,-25.43],"poa":[-51.23,-30.03],"aju":[-37.07,-10.91],"bel":[-48.5,-1.46],"bvb":[-60.67,2.82],"cac":[-53.46,-24.96],"cpv":[-35.88,-7.23],"cpq":[-47.06,-22.91],"cgr":[-54.65,-20.47],"cau":[-35.98,-8.28],"cgb":[-56.1,-15.6],"cxj":[-51.18,-29.17],"fec":[-38.97,-12.27],"fln":[-48.55,-27.6],"igu":[-54.59,-25.55],"gyn":[-49.25,-16.69],"jpa":[-34.86,-7.12],"ljd":[-51.96,-29.47],"ldb":[-51.16,-23.31],"mcp":[-51.07,0.03],"mcz":[-35.74,-9.67],"mao":[-60.02,-3.12],"mgf":[-51.94,-23.42],"nat":[-35.21,-5.79],"pmw":[-48.33,-10.18],"pvh":[-63.9,-8.76],"rao":[-47.81,-21.18],"rec":[-34.88,-8.05],"rbr":[-67.81,-9.97],"ssa":[-38.5,-12.97],"ria":[-53.81,-29.68],"sjp":[-49.38,-20.81],"slz":[-44.3,-2.53],"the":[-42.8,-5.09],"vix":[-40.31,-20.32],"mvd":[-56.16,-34.9],"asu":[-57.58,-25.26],"cor":[-64.18,-31.42],"lpb":[-68.15,-16.5],"uio":[-78.47,-0.18],"mde":[-75.57,6.24],"ccs":[-66.9,10.49],"gua":[-90.51,14.63],"sjo":[-84.09,9.93],"qro":[-100.39,20.59],"mty":[-100.31,25.69],"gdl":[-103.35,20.67],"bue":[-58.38, -34.6],"scl":[-70.67, -33.45],"lim":[-76.85,-12.05],"bog":[-74.07, 4.71],"pan":[-79.52, 8.98],"del":[77.21, 28.61],"maa":[80.18,13.25],"blr":[77.59, 12.97],"hyd":[78.49, 17.39],"tpe":[121.56, 25.03],"auh":[54.37, 24.45],"fuj":[56.15,25.07],"cpt":[18.42, -33.92],"dkr":[-17.45,14.69],"abj":[-4.03,5.32],"acc":[-0.19,5.6],"dla":[9.7,4.05],"fih":[15.27,-4.33],"lad":[13.23,-8.84],"cas":[-7.59,33.57],"alg":[3.06,36.75],"tun":[10.18,36.81],"jib":[43.15,11.59],"add":[38.75,9.03],"mba":[39.67,-4.04],"dar":[39.28,-6.79],"kla":[32.58,0.35],"kgl":[30.06,-1.95],"mpm":[32.57,-25.97],"dur":[31.03,-29.86],"wdh":[17.08,-22.56],"lun":[28.32,-15.39],"hre":[31.05,-17.83],"gbe":[25.91,-24.65],"stg":[9.18,48.78],"ber":[13.4,52.52],"zrh":[8.54,47.37],"nbo":[36.82,-1.29],"cai":[31.24,30.04],"sea":[-122.33,47.61],"sjc":[-121.89,37.34],"lax":[-118.24,34.05],"dal":[-96.8,32.78],"chi":[-87.63,41.88],"ash":[-77.49,39.04],"nyc":[-74.0,40.71],"mia":[-80.19,25.76],"tor":[-79.38,43.65],"kcy":[-94.58,39.1],"cal":[-114.07,51.05],"van":[-123.12,49.28],"ott":[-75.7,45.42],"mtl":[-73.57,45.5],"mex":[-99.13,19.43],"sao":[-46.63,-23.55],"lon":[-0.13,51.51],"dub":[-6.26,53.35],"rek":[-21.94,64.15],"ams":[4.9,52.37],"bru":[4.35,50.85],"oos":[3.23,51.15],"bet":[6.1,49.52],"fra":[8.68,50.11],"ham":[9.99,53.55],"dus":[6.78,51.22],"muc":[11.58,48.14],"par":[2.35,48.86],"mrs":[5.37,43.3],"mad":[-3.7,40.42],"sto":[18.07,59.33],"osl":[10.75,59.91],"cph":[12.57,55.68],"hel":[24.94,60.17],"beg":[20.46,44.79],"sof":[23.32,42.7],"mos":[37.62,55.76],"lag":[3.38,6.52],"jnb":[28.05,-26.2],"dxb":[55.27,25.2],"bom":[72.88,19.08],"sin":[103.82,1.35],"jkt":[106.85,-6.2],"mnl":[120.98,14.6],"hkg":[114.17,22.32],"sha":[121.47,31.23],"pek":[116.4,39.9],"icn":[126.98,37.57],"tok":[139.69,35.69],"syd":[151.21,-33.87],"per":[115.86,-31.95],"akl":[174.76,-36.85],"hnl":[-157.86,21.31],"gum":[144.75,13.47],"ror":[134.48,7.34],"maj":[171.38,7.09],"pom":[147.18,-9.44],"hir":[159.95,-9.43],"nou":[166.46,-22.27],"suv":[178.44,-18.14],"tbu":[-175.2,-21.14],"apw":[-171.76,-13.83],"ppg":[-170.7,-14.28],"ppt":[-149.57,-17.53]};
|
const CITY_LL={
|
||||||
|
"abj":[-4.03,5.32],
|
||||||
|
"acc":[-0.19,5.6],
|
||||||
|
"add":[38.75,9.03],
|
||||||
|
"adl":[138.6,-34.93],
|
||||||
|
"aju":[-37.07,-10.91],
|
||||||
|
"akl":[174.76,-36.85],
|
||||||
|
"alg":[3.06,36.75],
|
||||||
|
"ams":[4.9,52.37],
|
||||||
|
"apw":[-171.76,-13.83],
|
||||||
|
"ash":[-77.49,39.04],
|
||||||
|
"asu":[-57.58,-25.26],
|
||||||
|
"ath":[23.73,37.98],
|
||||||
|
"atn":[-84.39,33.75],
|
||||||
|
"auh":[54.37, 24.45],
|
||||||
|
"bcn":[2.17,41.39],
|
||||||
|
"bda":[-64.78,32.29],
|
||||||
|
"bde":[-4.54,50.83],
|
||||||
|
"beg":[20.46,44.79],
|
||||||
|
"bel":[-48.5,-1.46],
|
||||||
|
"ber":[13.4,52.52],
|
||||||
|
"bet":[6.1,49.52],
|
||||||
|
"bhz":[-43.94,-19.92],
|
||||||
|
"bkk":[100.5, 13.76],
|
||||||
|
"blr":[77.59, 12.97],
|
||||||
|
"bne":[153.03, -27.47],
|
||||||
|
"bog":[-74.07, 4.71],
|
||||||
|
"bom":[72.88,19.08],
|
||||||
|
"bos":[-71.06,42.36],
|
||||||
|
"bru":[4.35,50.85],
|
||||||
|
"bsb":[-47.88,-15.79],
|
||||||
|
"bud":[19.04, 47.5],
|
||||||
|
"bue":[-58.38, -34.6],
|
||||||
|
"buh":[26.1, 44.43],
|
||||||
|
"bvb":[-60.67,2.82],
|
||||||
|
"cac":[-53.46,-24.96],
|
||||||
|
"cai":[31.24,30.04],
|
||||||
|
"cal":[-114.07,51.05],
|
||||||
|
"cas":[-7.59,33.57],
|
||||||
|
"cau":[-35.98,-8.28],
|
||||||
|
"cbo":[80.0, 6.95],
|
||||||
|
"cbr":[149.13,-35.28],
|
||||||
|
"ccs":[-66.9,10.49],
|
||||||
|
"cgb":[-56.1,-15.6],
|
||||||
|
"cgr":[-54.65,-20.47],
|
||||||
|
"chc":[172.55,-43.53],
|
||||||
|
"chi":[-87.63,41.88],
|
||||||
|
"cor":[-64.18,-31.42],
|
||||||
|
"cph":[12.57,55.68],
|
||||||
|
"cpq":[-47.06,-22.91],
|
||||||
|
"cpt":[18.42, -33.92],
|
||||||
|
"cpv":[-35.88,-7.23],
|
||||||
|
"cwb":[-49.27,-25.43],
|
||||||
|
"cxj":[-51.18,-29.17],
|
||||||
|
"dac":[90.41, 23.81],
|
||||||
|
"dal":[-96.8,32.78],
|
||||||
|
"dar":[39.28,-6.79],
|
||||||
|
"del":[77.21, 28.61],
|
||||||
|
"den":[-104.99,39.74],
|
||||||
|
"dkr":[-17.45,14.69],
|
||||||
|
"dla":[9.7,4.05],
|
||||||
|
"doh":[51.45,25.28],
|
||||||
|
"drw":[131.05,-12.46],
|
||||||
|
"dub":[-6.26,53.35],
|
||||||
|
"dur":[31.03,-29.86],
|
||||||
|
"dus":[6.78,51.22],
|
||||||
|
"dxb":[55.27,25.2],
|
||||||
|
"edi":[-3.19,55.95],
|
||||||
|
"fec":[-38.97,-12.27],
|
||||||
|
"fih":[15.27,-4.33],
|
||||||
|
"fln":[-48.55,-27.6],
|
||||||
|
"for":[-38.54, -3.73],
|
||||||
|
"fra":[8.68,50.11],
|
||||||
|
"fuj":[56.15,25.07],
|
||||||
|
"gbe":[25.91,-24.65],
|
||||||
|
"gdl":[-103.35,20.67],
|
||||||
|
"gua":[-90.51,14.63],
|
||||||
|
"gum":[144.75,13.47],
|
||||||
|
"gyn":[-49.25,-16.69],
|
||||||
|
"ham":[9.99,53.55],
|
||||||
|
"hba":[147.25,-42.85],
|
||||||
|
"hel":[24.94,60.17],
|
||||||
|
"hfx":[-63.62,44.68],
|
||||||
|
"hir":[159.95,-9.43],
|
||||||
|
"hkg":[114.17,22.32],
|
||||||
|
"hnl":[-157.86,21.31],
|
||||||
|
"hou":[-95.37,29.76],
|
||||||
|
"hre":[31.05,-17.83],
|
||||||
|
"hyd":[78.49, 17.39],
|
||||||
|
"icn":[126.98,37.57],
|
||||||
|
"igu":[-54.59,-25.55],
|
||||||
|
"ist":[28.98, 41.01],
|
||||||
|
"ivc":[168.35,-46.41],
|
||||||
|
"jam":[-5.72,-15.93],
|
||||||
|
"jed":[39.25,21.55],
|
||||||
|
"jib":[43.15,11.59],
|
||||||
|
"jkt":[106.85,-6.2],
|
||||||
|
"jnb":[28.05,-26.2],
|
||||||
|
"jpa":[-34.86,-7.12],
|
||||||
|
"kcy":[-94.58,39.1],
|
||||||
|
"kgl":[30.06,-1.95],
|
||||||
|
"khi":[67.14,25.0],
|
||||||
|
"kla":[32.58,0.35],
|
||||||
|
"kul":[101.69, 3.14],
|
||||||
|
"kyv":[30.52,50.45],
|
||||||
|
"lad":[13.23,-8.84],
|
||||||
|
"lag":[3.38,6.52],
|
||||||
|
"lax":[-118.24,34.05],
|
||||||
|
"ldb":[-51.16,-23.31],
|
||||||
|
"lim":[-76.85,-12.05],
|
||||||
|
"lis":[-9.14,38.72],
|
||||||
|
"ljd":[-51.96,-29.47],
|
||||||
|
"lon":[-0.13,51.51],
|
||||||
|
"lpb":[-68.15,-16.5],
|
||||||
|
"lun":[28.32,-15.39],
|
||||||
|
"maa":[80.18,13.25],
|
||||||
|
"mad":[-3.7,40.42],
|
||||||
|
"maj":[171.38,7.09],
|
||||||
|
"man":[-2.24,53.48],
|
||||||
|
"mao":[-60.02,-3.12],
|
||||||
|
"mba":[39.67,-4.04],
|
||||||
|
"mcp":[-51.07,0.03],
|
||||||
|
"mcz":[-35.74,-9.67],
|
||||||
|
"mde":[-75.57,6.24],
|
||||||
|
"mel":[144.96, -37.81],
|
||||||
|
"mex":[-99.13,19.43],
|
||||||
|
"mgf":[-51.94,-23.42],
|
||||||
|
"mia":[-80.19,25.76],
|
||||||
|
"mil":[9.19,45.46],
|
||||||
|
"mnl":[120.98,14.6],
|
||||||
|
"mos":[37.62,55.76],
|
||||||
|
"mpm":[32.57,-25.97],
|
||||||
|
"mrs":[5.37,43.3],
|
||||||
|
"mtl":[-73.57,45.5],
|
||||||
|
"mty":[-100.31,25.69],
|
||||||
|
"muc":[11.58,48.14],
|
||||||
|
"mvd":[-56.16,-34.9],
|
||||||
|
"nat":[-35.21,-5.79],
|
||||||
|
"nbo":[36.82,-1.29],
|
||||||
|
"nou":[166.46,-22.27],
|
||||||
|
"nyc":[-74.0,40.71],
|
||||||
|
"oos":[3.23,51.15],
|
||||||
|
"osa":[135.5, 34.69],
|
||||||
|
"osl":[10.75,59.91],
|
||||||
|
"ott":[-75.7,45.42],
|
||||||
|
"pan":[-79.52, 8.98],
|
||||||
|
"par":[2.35,48.86],
|
||||||
|
"pdl":[-25.67,37.74],
|
||||||
|
"pek":[116.4,39.9],
|
||||||
|
"per":[115.86,-31.95],
|
||||||
|
"phx":[-112.07,33.45],
|
||||||
|
"pmo":[13.36,38.12],
|
||||||
|
"pmw":[-48.33,-10.18],
|
||||||
|
"poa":[-51.23,-30.03],
|
||||||
|
"pom":[147.18,-9.44],
|
||||||
|
"ppg":[-170.7,-14.28],
|
||||||
|
"ppt":[-149.57,-17.53],
|
||||||
|
"prg":[14.42, 50.08],
|
||||||
|
"pvh":[-63.9,-8.76],
|
||||||
|
"qro":[-100.39,20.59],
|
||||||
|
"rai":[-23.55,14.98],
|
||||||
|
"rao":[-47.81,-21.18],
|
||||||
|
"rbr":[-67.81,-9.97],
|
||||||
|
"rec":[-34.88,-8.05],
|
||||||
|
"rek":[-21.94,64.15],
|
||||||
|
"ria":[-53.81,-29.68],
|
||||||
|
"rio":[-43.11,-22.57],
|
||||||
|
"rom":[12.5,41.9],
|
||||||
|
"ror":[134.48,7.34],
|
||||||
|
"ruh":[46.72,24.71],
|
||||||
|
"sao":[-46.63,-23.55],
|
||||||
|
"scl":[-70.67, -33.45],
|
||||||
|
"sea":[-122.33,47.61],
|
||||||
|
"sgn":[106.66, 10.76],
|
||||||
|
"sha":[121.47,31.23],
|
||||||
|
"sin":[103.82,1.35],
|
||||||
|
"sjc":[-121.89,37.34],
|
||||||
|
"sjo":[-84.09,9.93],
|
||||||
|
"sjp":[-49.38,-20.81],
|
||||||
|
"slc":[-111.89,40.76],
|
||||||
|
"slz":[-44.3,-2.53],
|
||||||
|
"sof":[23.32,42.7],
|
||||||
|
"ssa":[-38.5,-12.97],
|
||||||
|
"stg":[9.18,48.78],
|
||||||
|
"sto":[18.07,59.33],
|
||||||
|
"suv":[178.44,-18.14],
|
||||||
|
"svg":[5.73,58.97],
|
||||||
|
"syd":[151.21,-33.87],
|
||||||
|
"tbu":[-175.2,-21.14],
|
||||||
|
"tci":[-16.3,28.44],
|
||||||
|
"the":[-42.8,-5.09],
|
||||||
|
"tll":[24.45,58.9],
|
||||||
|
"tok":[139.69,35.69],
|
||||||
|
"tor":[-79.38,43.65],
|
||||||
|
"tpe":[121.56, 25.03],
|
||||||
|
"tun":[10.18,36.81],
|
||||||
|
"uio":[-78.47,-0.18],
|
||||||
|
"van":[-123.12,49.28],
|
||||||
|
"vie":[16.37, 48.21],
|
||||||
|
"vix":[-40.31,-20.32],
|
||||||
|
"waw":[21.01, 52.23],
|
||||||
|
"wdh":[17.08,-22.56],
|
||||||
|
"zrh":[8.54,47.37],
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,69 @@ const CITIES=[
|
||||||
{id:'svg',name:'Stavanger',x:0,y:0,land:'eu',reg:'EU',P:60,ix:'Brunost-IX',dc:'Inside-a-Mountain DC',note:tr('Norway’s oil capital, now full of data centers inside mountains, run on hydro and cooled by the fjord. North Sea cables land here.')},
|
{id:'svg',name:'Stavanger',x:0,y:0,land:'eu',reg:'EU',P:60,ix:'Brunost-IX',dc:'Inside-a-Mountain DC',note:tr('Norway’s oil capital, now full of data centers inside mountains, run on hydro and cooled by the fjord. North Sea cables land here.')},
|
||||||
];
|
];
|
||||||
// Display-only nudges for cities that sit on top of each other at map scale; distances still use real lon/lat.
|
// Display-only nudges for cities that sit on top of each other at map scale; distances still use real lon/lat.
|
||||||
const CITY_NUDGE={stg:[7,1],zrh:[-3,3],bru:[1,3],oos:[-3,0],van:[-3,-6],sea:[1,4],ott:[-3,-3],bcn:[-6,-4],auh:[-5,6],dxb:[9,-7],fuj:[8,15],tll:[-4,22],osa:[-10,6],khi:[-2,-6],hou:[0,6],dal:[0,-4],nyc:[.3,-.7],mia:[-.6,.4],mtl:[.8,0],cph:[-.7,.3],hel:[-.8,-.2],akl:[.6,.4],sin:[-1.3,-1.3],hkg:[.8,0],ist:[.8,0],lis:[.8,0],aju:[-13.5,-2.7],bel:[0.4,0.4],cac:[2.4,-0.7],cpv:[-10.2,-5.1],cpq:[-2.8,-5.2],cau:[-10.2,2.4],cxj:[5.4,-9.4],fec:[-10.8,1.4],fln:[0.8,4.4],igu:[-3.9,5.3],gyn:[-4,2.6],jpa:[-0.9,0.6],ljd:[-5.2,-7.7],ldb:[6.2,0.1],mcp:[-1.7,1.7],mcz:[-7.2,8],mgf:[-5.8,-4.4],nat:[-1.5,-3.3],rao:[3.6,-2.6],rec:[-2.4,7.2],ssa:[0.5,-0.2],ria:[-2.4,4.9],sjp:[-3.5,0.4],slz:[0.3,0.3],vix:[-0.4,0.4],mvd:[2.2,-4.3],asu:[-1.2,-0.8],mde:[-1.7,-1.9],qro:[-1.9,-3.9],gdl:[-1.2,0.2],cas:[0.6,0.6],alg:[0.9,0.9],jib:[0.1,0.2],mba:[-0.8,0],dar:[0,12.6],dur:[-0.2,0]};
|
const CITY_NUDGE={
|
||||||
|
aju:[-13.5,-2.7],
|
||||||
|
akl:[.6,.4],
|
||||||
|
alg:[0.9,0.9],
|
||||||
|
asu:[-1.2,-0.8],
|
||||||
|
auh:[-5,6],
|
||||||
|
bcn:[-6,-4],
|
||||||
|
bel:[0.4,0.4],
|
||||||
|
bru:[1,3],
|
||||||
|
cac:[2.4,-0.7],
|
||||||
|
cas:[0.6,0.6],
|
||||||
|
cau:[-10.2,2.4],
|
||||||
|
cph:[-.7,.3],
|
||||||
|
cpq:[-2.8,-5.2],
|
||||||
|
cpv:[-10.2,-5.1],
|
||||||
|
cxj:[5.4,-9.4],
|
||||||
|
dal:[0,-4],
|
||||||
|
dar:[0,12.6],
|
||||||
|
dur:[-0.2,0],
|
||||||
|
dxb:[9,-7],
|
||||||
|
fec:[-10.8,1.4],
|
||||||
|
fln:[0.8,4.4],
|
||||||
|
fuj:[8,15],
|
||||||
|
gdl:[-1.2,0.2],
|
||||||
|
gyn:[-4,2.6],
|
||||||
|
hel:[-.8,-.2],
|
||||||
|
hkg:[.8,0],
|
||||||
|
hou:[0,6],
|
||||||
|
igu:[-3.9,5.3],
|
||||||
|
ist:[.8,0],
|
||||||
|
jib:[0.1,0.2],
|
||||||
|
jpa:[-0.9,0.6],
|
||||||
|
khi:[-2,-6],
|
||||||
|
ldb:[6.2,0.1],
|
||||||
|
lis:[.8,0],
|
||||||
|
ljd:[-5.2,-7.7],
|
||||||
|
mba:[-0.8,0],
|
||||||
|
mcp:[-1.7,1.7],
|
||||||
|
mcz:[-7.2,8],
|
||||||
|
mde:[-1.7,-1.9],
|
||||||
|
mgf:[-5.8,-4.4],
|
||||||
|
mia:[-.6,.4],
|
||||||
|
mtl:[.8,0],
|
||||||
|
mvd:[2.2,-4.3],
|
||||||
|
nat:[-1.5,-3.3],
|
||||||
|
nyc:[.3,-.7],
|
||||||
|
oos:[-3,0],
|
||||||
|
osa:[-10,6],
|
||||||
|
ott:[-3,-3],
|
||||||
|
qro:[-1.9,-3.9],
|
||||||
|
rao:[3.6,-2.6],
|
||||||
|
rec:[-2.4,7.2],
|
||||||
|
ria:[-2.4,4.9],
|
||||||
|
sea:[1,4],
|
||||||
|
sin:[-1.3,-1.3],
|
||||||
|
sjp:[-3.5,0.4],
|
||||||
|
slz:[0.3,0.3],
|
||||||
|
ssa:[0.5,-0.2],
|
||||||
|
stg:[7,1],
|
||||||
|
tll:[-4,22],
|
||||||
|
van:[-3,-6],
|
||||||
|
vix:[-0.4,0.4],
|
||||||
|
zrh:[-3,3],
|
||||||
|
};
|
||||||
for(const c of CITIES){const q=CITY_LL[c.id];if(q){c.lon=q[0];c.lat=q[1];const pt=proj(q[0],q[1]),n=CITY_NUDGE[c.id]||[0,0];c.x=pt[0]+n[0];c.y=pt[1]+n[1];}}
|
for(const c of CITIES){const q=CITY_LL[c.id];if(q){c.lon=q[0];c.lat=q[1];const pt=proj(q[0],q[1]),n=CITY_NUDGE[c.id]||[0,0];c.x=pt[0]+n[0];c.y=pt[1]+n[1];}}
|
||||||
const CITY=Object.fromEntries(CITIES.map(c=>[c.id,c])),CIDX=Object.fromEntries(CITIES.map((c,i)=>[c.id,i]));
|
const CITY=Object.fromEntries(CITIES.map(c=>[c.id,c])),CIDX=Object.fromEntries(CITIES.map((c,i)=>[c.id,i]));
|
||||||
|
|
|
||||||
|
|
@ -1,294 +0,0 @@
|
||||||
/* ================= ACTIONS ================= */
|
|
||||||
function spend(c){if(S.cash<c){toast(tr('<b>Not enough cash.</b><br>Wait for revenue, or speed up time.'),'bad');sfx('err');return false;}S.cash-=c;sfx('build');return true;}
|
|
||||||
const ACT={
|
|
||||||
speed:({v})=>{v=+v;if(![0,0.5,1,2,4,8].includes(v))return;if(v)UI.lastSpeed=v;UI.speed=v;renderHUD();},
|
|
||||||
help:()=>showHelp(),
|
|
||||||
dash:()=>{if(!S)return;const d=$('dash');d.hidden=!d.hidden;if(!d.hidden)renderDash();},
|
|
||||||
dashClose:()=>{$('dash').hidden=true;},
|
|
||||||
dashTab:({k})=>{if(!DTABS.includes(k))return;UI.dtab=k;renderDash();const d=$('dash');if(d)d.scrollTop=0;},
|
|
||||||
dashSort:({k})=>{if(!['name','asn','type','traffic','cost','lost'].includes(k))return;if(UI.dashSort===k)UI.dashDir=-(UI.dashDir||-1);else{UI.dashSort=k;UI.dashDir=k==='name'||k==='type'||k==='asn'?1:-1;}renderDash();},
|
|
||||||
bank:()=>{if(!S)return;UI.confirm=null;$('dash').hidden=true;const b=$('bankBox');b.hidden=false;UI._bh=null;renderBank();},
|
|
||||||
bankClose:()=>{UI.confirm=null;$('bankBox').hidden=true;},
|
|
||||||
takeLoan:({id})=>{const o=S.loanOffers.find(x=>x.id===id);if(!o)return;S.stats.loans=(S.stats.loans||0)+1;const B=BANKS[o.bank];let got=o.amount,note='';
|
|
||||||
if(B.crypto){const f=0.55+Math.random()*0.8;got=Math.round(o.amount*f);note=' '+(f>=1?tr('TubeCoin moved up {p}% on the way to your account.',{p:Math.round(Math.abs(f-1)*100)}):tr('TubeCoin moved down {p}% on the way to your account.',{p:Math.round(Math.abs(f-1)*100)}));}
|
|
||||||
S.cash+=got;S.loanOffers=S.loanOffers.filter(x=>x!==o);
|
|
||||||
S.loans.push({id:o.id,bank:o.bank,start:S.day,amount:o.amount,got,bal:o.model==='transit'?o.owe:o.amount,apr:o.apr||0,apr0:o.apr||0,pay:o.pay||0,left:o.term||0,term:o.term||0,share:o.share||0,model:o.model,cut:o.cut,covs:o.covs,base:{sub:S.links.filter(x=>x.sub).length}});
|
|
||||||
track('loan_taken');toast(`<b>${tr('{amt} from {bank} has landed.',{amt:fmt$(got),bank:esc(B.name)})}</b><br>${B.equity?tr('They now own {p} of your revenue.',{p:pct(o.share)}):loanSummary(o)}${note}`,'good');sfx('coin');after();renderBank();},
|
|
||||||
declineLoan:({id})=>{S.loanOffers=S.loanOffers.filter(x=>x.id!==id);sfx('click');renderBank();renderHUD();save();},
|
|
||||||
repayLoan:({id})=>{const l=S.loans.find(x=>x.id===id);if(!l)return;const B=BANKS[l.bank];const cost=repayCost(l,B);
|
|
||||||
if(UI.confirm!==id){UI.confirm=id;renderBank();return;}UI.confirm=null;if(!spend(cost)){renderBank();return;}S.loans=S.loans.filter(x=>x!==l);track('loan_repaid');
|
|
||||||
toast(B.equity?tr('<b>You bought out {bank}.</b><br>They flew off to find another startup.',{bank:esc(B.name)}):tr('<b>Loan from {bank} repaid early.</b>',{bank:esc(B.name)}),'good');after();renderBank();},
|
|
||||||
leaseSwap:({a,b,src})=>{if(!S.pops[a]||!S.pops[b]||a===b)return;$('dash').hidden=true;UI.lmode='df';UI.dfSrc=['lease','build','cable'].includes(src)?src:isSub(a,b)?'cable':'build';UI.dfSys=lvl()>=3?'roadm':'lite';openLinkModal(a,b);},
|
|
||||||
dashLink:({id})=>{$('dash').hidden=true;selectLink(id);},
|
|
||||||
animSet:({v})=>{if(!['auto','on','off'].includes(v))return;UI.anim=v;try{localStorage.setItem('sot-anim',v);}catch(e){}applyAnim();refreshSettings();},
|
|
||||||
soundSet:({v})=>{UI.muted=v==='off';try{localStorage.setItem('sot-mute',UI.muted?'1':'0');}catch(e){}renderHUD();refreshSettings();},
|
|
||||||
langSet:({v})=>{if(!Object.hasOwn(LANGS,v)||v===LANG)return;try{localStorage.setItem('sot-lang',v);}catch(e){}save();location.reload();},
|
|
||||||
mute:()=>{UI.muted=!UI.muted;try{localStorage.setItem('sot-mute',UI.muted?'1':'0');}catch(e){}renderHUD();},
|
|
||||||
closePanel:()=>{UI.sel=null;UI.confirm=null;renderPanel();renderLeft();},
|
|
||||||
closeModal:()=>closeModal(),
|
|
||||||
tab:({t})=>{UI.tab=t;UI.confirm=null;renderPanel();},
|
|
||||||
leftTab:({t})=>{UI.left=t;UI.leftOpen=true;renderLeft();},
|
|
||||||
netFocus:({id})=>{if(!NET[id])return;$('dash').hidden=true;UI.netFocus=id;UI.nf='all';UI.left='nets';UI.leftOpen=true;UI.sel=null;renderPanel();renderLeft();const b=$('leftBody');if(b)b.scrollTop=0;},
|
|
||||||
netFilter:({f})=>{UI.nf=f==='out'?'out':'all';UI.netFocus=null;$('dash').hidden=true;UI.left='nets';UI.leftOpen=true;UI.sel=null;renderPanel();renderLeft();const b=$('leftBody');if(b)b.scrollTop=0;},
|
|
||||||
meetGo:({city})=>{if(!isCity(city))return;$('dash').hidden=true;ACT.focusCity({city});if(S.pops[city]){UI.tab='peer';renderPanel();}},
|
|
||||||
toggleLeft:()=>{UI.leftOpen=!UI.leftOpen;renderLeft();},
|
|
||||||
phoneTab:({t})=>{if(!['goals','deals','noc','nets'].includes(t))return;haptic(8);if(UI.leftOpen&&UI.left===t&&!UI.sel){UI.leftOpen=false;}else{UI.left=t;UI.leftOpen=true;UI.sel=null;renderPanel();}$('left').classList.remove('full');renderLeft();},
|
|
||||||
phonePlay:()=>{haptic(10);if(UI.speed){UI.lastSpeed=UI.speed;UI.speed=0;}else UI.speed=UI.lastSpeed||1;renderHUD();},
|
|
||||||
phoneSpeed:()=>{haptic(8);const cur=UI.speed||UI.lastSpeed||1,i=SPEEDS.indexOf(cur),n=SPEEDS[(i+1)%SPEEDS.length];UI.speed=n;UI.lastSpeed=n;renderHUD();},
|
|
||||||
install:()=>{if(installEvt){installEvt.prompt();installEvt.userChoice.finally(()=>{installEvt=null;});return;}
|
|
||||||
openModal(pitchHtml(false));},
|
|
||||||
pitchSkip:()=>{const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;if(p)beginGame(...p);else closeModal();},
|
|
||||||
logOpen:({id})=>{const e=(S.log||[]).find(x=>x.id===id),o=e&&e.o;if(!o)return;$('dash').hidden=true;closeModal();
|
|
||||||
if(o.a==='city'&&isCity(o.v)){ACT.focusCity({city:o.v});return;}
|
|
||||||
if(o.a==='link'){if(S.links.some(l=>l.id===o.v)){ACT.selLink({id:o.v});return;}toast(tr('<b>That link is gone.</b><br>It was removed or decommissioned since.'),'');return;}
|
|
||||||
if(o.a==='cust'){if(S.biz.some(b=>b.id===o.v)){ACT.custGo({id:o.v});return;}toast(tr('<b>That customer is gone.</b><br>The contract ended since.'),'');return;}
|
|
||||||
if(o.a==='bank'){ACT.bank({});return;}if(o.a==='inbox'){ACT.inbox({});return;}if(o.a==='tab'&&LOG_TABS.includes(o.v))ACT.leftTab({t:o.v});},
|
|
||||||
logAll:()=>{UI.logAll=!UI.logAll;renderLeft();},
|
|
||||||
focusCity:({city})=>{selectCity(city);const C=CITY[city];cam.x=C.x;cam.y=C.y;cam.z=Math.max(cam.z,1.2);if(innerWidth<760)UI.leftOpen=false;renderLeft();},
|
|
||||||
selLink:({id})=>selectLink(id),
|
|
||||||
buildPop:({city})=>{if(S.pops[city])return;const flipNote=CITY[city]&&CITY[city].au;if(cnCity(city)&&!cnOk()){toast(tr('<b>You need a license first.</b><br>Foreign networks need a joint venture to build in mainland China.'),'bad');sfx('err');return;}if(!spend(popCost(city)))return;S.pops[city]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};floater(CITY[city].x,CITY[city].y-30,tr('New POP!'),'#FF4F9A');if(flipNote)toast(pick([tr('<b>Router installed in {city}.</b><br>Upside down, as is customary down here. The packets don’t seem to mind.',{city:CITY[city].name}),tr('<b>Router installed in {city}.</b><br>The vendor shipped it the right way up, so the local techs turned it over. Everything else here is upside down too.',{city:CITY[city].name})]),'good',[],{a:'city',v:city});UI.tab='cust';after();},
|
|
||||||
launchBB:({city})=>{const p=S.pops[city];if(!p||p.bb)return;const C=CITY[city];if(!spend(bbCost(city)))return;p.bb={d:bbStart(city)};floater(C.x,C.y-30,tr('Eyeballs online!'),'#16A866');after();},
|
|
||||||
ad:({city})=>{const p=S.pops[city];if(!p||!p.bb)return;if(!spend(8000))return;p.boost=S.day+30;floater(CITY[city].x,CITY[city].y-30,tr('Ad campaign!'),'#FF8A3D');after();},
|
|
||||||
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast(tr('<b>No transit in this scenario.</b><br>Peering, PNIs, caches and your own fiber only.'),'bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!sellsAt(NET[net],city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr("<b>Your router can't take a {port} port.</b><br>Upgrade it in the Infra tab.",{port:PORT[tier].n}),'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.transit.push({id:uid(),city,net,tier,down:0});toast(tr('<b>{net} transit is live in {city}.</b><br>Full table received: ~1,000,000 routes.',{net:esc(NET[net].name),city:CITY[city].name}),'good');after();},
|
|
||||||
lagT:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const t=S.transit.find(x=>x.id===id);if(!t)return;const n=(t.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0){if(!portOk(t.city,t.tier)||!portGate(t.city,PORT_SLOT(t.tier)))return;if(!spend(PORT[t.tier].setup))return;}t.n=n;if(n<2&&t.site==='ab')t.site='a';toast(+d>0?tr('<b>LAG member added.</b><br>{net} in {city} is now {lag}.',{net:esc(NET[t.net].name),city:CITY[t.city].name,lag:lagName(t.tier,n)}):tr(`<b>LAG member removed.</b>`),'good');after();},
|
|
||||||
lagP:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const p=S.pni.find(x=>x.id===id);if(!p)return;const n=(p.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(d>0&&(!pniOn(p)||p.up||msfNope(p.net,p.city)))return;if(+d>0&&(!portGate(p.city,PORT_SLOT(p.tier))||!spend(1500+PORT[p.tier].setup/2)))return;
|
|
||||||
// A LAG member is an augment: the big networks take months for that too.
|
|
||||||
if(d>0){const lead=pniLead(p.net);p.up={tier:p.tier,n,ready:S.day+lead,g1:!!p.g1};toast(tr('<b>Augment ordered with {net}.</b><br>{eta}.',{net:esc(NET[p.net].name),eta:pniWhen(lead)}),'good');after();return;}p.n=n;if(n<2&&p.site==='ab')p.site='a';sfx('build');after();},
|
|
||||||
lagIx:({city,d})=>{d=+d;if(d!==1&&d!==-1)return;if(!isIx(city)||S.ixp[city]===undefined||S.myIx[city]||!S.pops[ixCity(city)])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&(!portGate(ixCity(city),PORT_SLOT(S.ixp[city]))||!spend(ixPortMo(city,S.ixp[city]))))return;S.ixn[city]=n;if(n<2&&S.ixSite&&S.ixSite[city]==='ab')S.ixSite[city]='a';sfx('build');after();},
|
|
||||||
cancelTransit:({id,ok})=>{if(!ok&&UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.transit=S.transit.filter(t=>t.id!==id);UI.confirm=null;after();},
|
|
||||||
buyIx:({city,tier,signed})=>{tier=+tier;if(!PORT[tier]||!ixName(city)||(!S.pops[ixCity(city)]&&(!remoteCities().includes(ixCity(city))||tier>1))||(S.ixp[city]!==undefined&&tier<=S.ixp[city]))return;if(S.pops[ixCity(city)]&&!portOk(ixCity(city),tier)){toast(tr("<b>Your router can't take a {port} port.</b><br>Upgrade it in the Infra tab.",{port:PORT[tier].n}),'bad');sfx('err');return;}{const h0=S.ixp[city]!==undefined;if(!S.myIx[city]&&!portGate(ixCity(city),h0?(PORT_SLOT(tier)-PORT_SLOT(S.ixp[city]))*((S.ixn||{})[city]||1):PORT_SLOT(tier)))return;}
|
|
||||||
if(isDk(city)&&S.ixp[city]===undefined&&!signed){const dk=dkState();if(dk.stall>S.day){toast(tr('<b>DE-KICKS sales is still "aligning".</b><br>They will get back to you in {n} days.',{n:dk.stall-S.day}),'bad');sfx('err');return;}dk.lastQ=dk.lastQ||{};const lq=dk.lastQ[city];dk.q={city,tier,m:lq&&lq.until>S.day?lq.m:dkQuoteMult(),h:lq&&lq.until>S.day?lq.h:0};dk.lastQ[city]={m:dk.q.m,h:dk.q.h,until:S.day+90};dkQuoteModal();return;}const had=S.ixp[city]!==undefined;if(!spend(ixPortMo(city,tier)*(had?((S.ixn||{})[city]||1):1)))return;S.ixp[city]=tier;if(!had)toast(S.pops[ixCity(city)]?tr('<b>Port up at {ix}!</b><br>Now request peering, or join the route server.',{ix:esc(ixName(city))}):tr("<b>Remote port up at {ix}.</b><br>It came through a reseller, so expect a markup, a crowded port and some networks that won't talk to you. The route server is your friend here.",{ix:esc(ixName(city))}),'good',[],{a:'city',v:ixCity(city)});after();},
|
|
||||||
cancelIx:({city,sure,ok})=>{if(!ok&&UI.confirm!=='ix'+city){UI.confirm='ix'+city;renderPanel();return;}
|
|
||||||
if(isDk(city)&&!sure){const dk=dkState();if(!dk.retUsed[city]){openModal(`<div class="eyebrow">${tr('DE-KICKS Group · Customer Success')}</div><h2 style="font-size:26px">${tr('Wait! Before you go…')}</h2><p class="tagline">${tr('We value our partnership too much to let a little thing like price get in the way.')}</p><div class="kv"><span>${tr('Retention offer')}</span><b>${tr('40% off for 6 months')}</b></div><p class="note">${tr('After that, the normal price returns, plus a small loyalty administration fee.')}</p><div class="btns">${btn(tr('Stay, take the discount'),'dkStay',{city},'pink')}${btn(tr('Leave anyway'),'cancelIx',{city,sure:1},'ghost')}</div>`);return;}}
|
|
||||||
closeModal();if(S.dk){if(S.dk.m[city]){S.dk.lastQ=S.dk.lastQ||{};S.dk.lastQ[city]={m:S.dk.m[city],h:3,until:S.day+365};}delete S.dk.m[city];delete S.dk.add[city];delete S.dk.ret[city];}delete S.ixp[city];delete S.rs[city];if(S.ixn)delete S.ixn[city];for(const k in S.peers)if(k.endsWith('@'+city))delete S.peers[k];UI.confirm=null;after();},
|
|
||||||
rs:({city})=>{if(!isIx(city)||S.ixp[city]===undefined)return;S.rs[city]=!S.rs[city];if(S.rs[city])toast(tr('<b>Route server session up.</b><br>You now peer with every open network on this IX, in one go.'),'good');sfx('build');after();},
|
|
||||||
dkAccept:()=>{const dk=dkState(),q=dk.q;if(!q)return;dk.m[q.city]=q.m;dk.q=null;closeModal();ACT.buyIx({city:q.city,tier:q.tier,signed:true});if(S.ixp[q.city]===undefined)delete dk.m[q.city];else toast(tr(`<b>Signed with DE-KICKS.</b><br>Welcome to the family. Please don't tell anyone what you pay.`),'good');},
|
|
||||||
dkHaggle:()=>{const dk=dkState(),q=dk.q;if(!q||q.h>=3)return;q.h++;const r=Math.random();
|
|
||||||
if(r<0.45){S.stats.haggleWin=1;q.m=+(q.m*(0.75+Math.random()*0.15)).toFixed(2);dkQuoteModal();toast(tr('<b>"Just this once."</b><br>Your account manager found a special discount. Do not tell the others.'),'good');}
|
|
||||||
else if(r<0.75){q.m=+(q.m*1.1).toFixed(2);dkQuoteModal();toast(tr('<b>"After consulting with management…"</b><br>The price went up. Management was consulted.'),'bad');}
|
|
||||||
else{dk.stall=S.day+5+Math.floor(Math.random()*6);dk.q=null;closeModal();toast(tr('<b>Haggling paused.</b><br>{why}',{why:esc(pick(DK_STALL))}),'bad');}},
|
|
||||||
dkWalk:()=>{const dk=dkState(),q=dk.q;if(q){dk.lastQ=dk.lastQ||{};dk.lastQ[q.city]={m:q.m,h:q.h,until:S.day+90};if(q.h>0)dk.stall=Math.max(dk.stall||0,S.day+3);}dk.q=null;closeModal();toast(tr('<b>DE-KICKS will "circle back".</b><br>Expect an email titled "Quick question 🙂" within the hour.'),'');},
|
|
||||||
dkOptOut:({city,n})=>{const dk=dkState(),k='dk'+city+n;if(UI.confirm!==k){UI.confirm=k;renderPanel();return;}dk.add[city]=(dk.add[city]||[]).filter(x=>x.n!==n);UI.confirm=null;S.stats.optouts=(S.stats.optouts||0)+1;toast(tr(`<b>Opted out of {name}.</b><br>It took four clicks, a survey and a "we're sad to see you go" page.`,{name:esc(n)}),'good');after();},
|
|
||||||
dkStay:({city})=>{S.stats.retained=1;const dk=dkState();dk.ret[city]=S.day+180;dk.retUsed[city]=true;UI.confirm=null;closeModal();toast(tr('<b>40% off {ix} for 6 months.</b><br>Your account manager is relieved. Read the small print later.',{ix:esc(ixName(city))}),'good');after();},
|
|
||||||
teEdit:()=>{if(!S.te)return;UI.teDraft=undefined;teModal();},
|
|
||||||
teClose:()=>{const t=$('teSrc');if(t)UI.teDraft=t.value;closeModal();},
|
|
||||||
teOpt:()=>{UI.teDraft=teOptimize();teModal();},
|
|
||||||
teExample:()=>{UI.teDraft=TE_EXAMPLE;teModal();},
|
|
||||||
teSlop:()=>{const t0=performance.now(),a=aiSlop(Math.random()<0.02),secs=Math.max(0.1,(performance.now()-t0)/1000);UI.teDraft=UI.slop=a.src;teModal(`<p class="note aisay">🤖 <b>${esc(a.ai)}</b> <small>${tr('thought for {s} seconds',{s:secs.toFixed(1)})}</small><br>${tr(a.say)}</p>`);sfx('build');},
|
|
||||||
teHelp:()=>{const t=$('teSrc');if(t)UI.teDraft=t.value;teHelpModal();},
|
|
||||||
teBack:()=>teModal(),
|
|
||||||
teRecipe:({id})=>{const r=TE_RECIPES.find(x=>x.id===id);if(!r)return;UI.teDraft=r.src().join('\n');teModal(`<p class="note">${tr('Loaded {name}. Check it, then deploy.',{name:tr(r.n)})}</p>`);},
|
|
||||||
teClear:()=>{S.te.script='';UI.teDraft=undefined;TE_CACHE={src:null,p:null};after();teModal(`<p class="note">${tr('Script removed. Plain Auto-TE is back in charge.')}</p>`);},
|
|
||||||
teCheck:()=>{const t=$('teSrc');const src=t?t.value:'';UI.teDraft=src;const p=teParse(src);if(p.errors.length){teModal(`<pre class="term err">${esc(p.errors.join('\n'))}</pre>`);return;}const r=teTrial(src);teModal(`<pre class="term">${esc(trn('✓ {n} rule OK','✓ {n} rules OK',p.n)+'\n'+tr('served {a} → {b}',{a:fmtG(r.before.served),b:fmtG(r.after.served)})+'\n'+tr('transit {a}/mo → {b}/mo',{a:fmt$(r.before.tc),b:fmt$(r.after.tc)})+'\n'+tr('spilled {g} onto alternate paths',{g:fmtG(r.after.moved)})+(r.after.bh?'\n'+tr('blackholed {g}',{g:fmtG(r.after.bh)}):''))}</pre>`);},
|
|
||||||
teDeploy:()=>{const t=$('teSrc');const src=(t?t.value:'').slice(0,4000);UI.teDraft=src;const p=teParse(src);if(p.errors.length){teModal(`<pre class="term err">${esc(tr('commit failed')+'\n'+p.errors.join('\n'))}</pre>`);sfx('err');return;}const r=teTrial(src);S.te.script=src;S.te.on=true;TE_CACHE={src:null,p:null};UI.teDraft=undefined;after();
|
|
||||||
const drop=r.before.served>1?1-r.after.served/r.before.served:0,saved=r.before.tc>0?1-r.after.tc/r.before.tc:0;
|
|
||||||
if(drop>0.1&&UI.slop===src){if(drop>0.3)S.stats.fat=1;toast(tr('<b>Commit complete. Traffic down {p}.</b><br>The AI apologises for the confusion, and remains completely sure the script was right. Fix it from the NOC tab.',{p:pct(drop)}),'bad');sfx('alert');}
|
|
||||||
else if(drop>0.3){S.stats.fat=1;toast(tr('<b>Commit complete. Traffic down {p}.</b><br>You just fat-fingered your own network. Classic. Fix the script from the NOC tab.',{p:pct(drop)}),'bad');sfx('alert');}
|
|
||||||
else{if(saved>0.1&&drop<0.01)S.stats.kiddie=1;toast(`<b>${tr('Commit complete.')}</b><br>${saved>0.01?trn('{n} rule live, transit bill down {p}.','{n} rules live, transit bill down {p}.',p.n,{p:pct(saved)}):trn('{n} rule live.','{n} rules live.',p.n)}`,'good');sfx('build');}closeModal();UI.slop=undefined;checkGoals();},
|
|
||||||
buyTE:()=>{if(S.te)return;if(lvl()<3){toast(tr('<b>Auto-TE unlocks at customer level 3.</b>'),'bad');sfx('err');return;}if(!spend(TE_COST))return;S.te={on:true,day:S.day};toast(tr('<b>Auto-TE is live.</b><br>The controller now pushes overflow onto alternate paths whenever the shortest one is full.'),'good');after();},
|
|
||||||
teToggle:()=>{if(!S.te)return;S.te.on=!S.te.on;after();},
|
|
||||||
trace:({city})=>traceModal(city),
|
|
||||||
traceRun:()=>{const f=$('trFrom'),t=$('trTo');traceModal(f&&f.value,t&&t.value);},
|
|
||||||
traceCopy:()=>{try{navigator.clipboard.writeText(UI.trText||'');toast(tr('<b>Copied.</b> Paste it into your favourite NOC chat.'),'good');}catch(e){}},
|
|
||||||
share:()=>shareModal(),
|
|
||||||
shareDl:()=>shareFile(f=>{if(!f)return;const a=document.createElement('a');a.href=URL.createObjectURL(f);a.download=f.name;document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove();},1000);track('share_download');}),
|
|
||||||
shareGo:()=>shareFile(f=>{const d={title:'Series of Tubes',text:tr('{name} (AS{asn}): {tier}, {peak} peak. Build your own internet at',{name:S.name,asn:S.asn,tier:tierLabel(),peak:fmtG(S.stats.peak||0)}),url:'https://seriesoftub.es/'};try{if(f&&navigator.canShare&&navigator.canShare({files:[f]}))d.files=[f];navigator.share(d).then(()=>track('share_done')).catch(()=>{});}catch(e){}}),
|
|
||||||
confGo:({key})=>{S.confReg=S.confReg||{};if(S.confReg[key])return;const cf=upcomingConfs(75).find(x=>x.key===key);if(!cf||cf.day<=S.day)return;if(!spend(CONF_COST))return;S.confReg[key]=true;toast(tr('<b>Registered.</b><br>Flights booked, badge printed, business cards ordered in the wrong font.'),'good');after();},
|
|
||||||
tutSkip:()=>{S.tut=null;try{localStorage.setItem('sot-tut','1');}catch(e){}renderCoach();},
|
|
||||||
addSite:({city})=>{const p=S.pops[city];if(!p||p.site2)return;if(!spend(SITE2_COST))return;p.site2=true;p.site2Day=S.day;toast(tr('<b>Second site live in {city}.</b><br>{b} is joined to {a} by your own metro ring. Move some uplinks there from the Transit and Peering tabs.',{city:CITY[city].name,b:esc(siteName(city,'b')),a:esc(siteName(city,'a'))}),'good');sfx('build');after();},
|
|
||||||
rmSite:({city})=>{const p=S.pops[city];if(!p||!p.site2)return;if(UI.confirm!=='site'+city){UI.confirm='site'+city;renderPanel();return;}UI.confirm=null;p.site2=0;p.sdown=null;p.ringcut=0;for(const t of S.transit)if(t.city===city)t.site='a';for(const x of S.pni)if(x.city===city)x.site='a';for(const x of S.caches)if(x.city===city)x.site='a';if(S.ixSite)for(const x of ixIdsIn(city))delete S.ixSite[x];after();},
|
|
||||||
siteSet:({k,id,s})=>{if(!['a','b','ab'].includes(s))return;
|
|
||||||
const o=k==='t'?S.transit.find(x=>x.id===id):k==='p'?S.pni.find(x=>x.id===id):null;if(k!=='ix'&&!o)return;if(k==='ix'&&(!isIx(id)||S.ixp[id]===undefined||!S.pops[ixCity(id)]))return;
|
|
||||||
if(k==='ix'&&S.myIx[id]){S.ixSite=S.ixSite||{};S.ixSite[id]=s;after();return;}
|
|
||||||
const n=()=>k==='ix'?((S.ixn||{})[id]||1):(o.n||1);
|
|
||||||
if(s==='ab'&&n()<2){const before=n();if(k==='t')ACT.lagT({id,d:1});else if(k==='p')ACT.lagP({id,d:1});else ACT.lagIx({city:id,d:1});if(n()<2||n()===before)return;toast(tr(`<b>Second LAG member added.</b><br>One member in each building now, so a dark building only takes out half the port.`),'good');}
|
|
||||||
if(k==='ix'){S.ixSite=S.ixSite||{};S.ixSite[id]=s;}else o.site=s;after();},
|
|
||||||
peer:({city,net})=>{if(!isIx(city)||!isNet(net)||S.ixp[city]===undefined||!ixMembers(city).includes(net))return;const r=peerOk(net,'ix',city);if(!r.ok){toast(tr('<b>{net} declined.</b><br>{why}',{net:esc(NET[net].name),why:esc(r.why)}),'bad');sfx('err');return;}S.peers[net+'@'+city]=true;
|
|
||||||
toast(`<b>${tr('{net} accepted!',{net:esc(NET[net].name)})}</b><br>${NET[net].pol==='selective'?tr('They checked your PearingDB page and liked the traffic numbers.'):tr('BGP session established.')}`,'good');sfx('build');after();},
|
|
||||||
unpeer:({city,net})=>{delete S.peers[net+'@'+city];after();},
|
|
||||||
peerAll:({city})=>{if(!isIx(city)||S.ixp[city]===undefined)return;const set=ixSessions(city);let n=0;for(const id of ixMembers(city))if(!set.has(id)&&peerOk(id,'ix',city).ok){S.peers[id+'@'+city]=true;n++;}if(!n)return;toast(trn('<b>{n} new session at {ix}.</b><br>Small networks, but they add up, and they all count towards the club.','<b>{n} new sessions at {ix}.</b><br>Small networks, but they add up, and they all count towards the club.',n,{ix:esc(ixName(city))}),'good',[],{a:'city',v:ixCity(city)});sfx('build');after();},
|
|
||||||
tailTog:()=>{UI.tailOpen=!UI.tailOpen;renderLeft();},
|
|
||||||
pni:({city,net,tier})=>{tier=+tier;const g1=tier===-1;if(g1){if(!pniG1(net))return;tier=0;}if(!S.pops[city]||!NET[net]||!NET[net].pops.includes(city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr("<b>Your router can't take a {port} port.</b><br>Upgrade it in the Infra tab.",{port:PORT[tier].n}),'bad');sfx('err');return;}const r=peerOk(net,'pni',city);if(!r.ok){toast(tr('<b>{net} declined the PNI.</b><br>{why}',{net:esc(NET[net].name),why:esc(r.why)}),'bad');sfx('err');after();return;}
|
|
||||||
if(!g1&&tier<pniMin(net)){toast(tr('<b>{net} does not do {port} PNIs.</b><br>Nothing smaller than 100G. Come back with more traffic, or a bigger optic.',{net:esc(NET[net].name),port:PORT[tier].n}),'bad');sfx('err');return;}
|
|
||||||
const ex=S.pni.find(p=>p.city===city&&p.net===net);if(ex&&(g1||!pniOn(ex)||ex.up))return;if(ex&&!(ex.g1&&tier===0)&&tier<=ex.tier)return;
|
|
||||||
const cost=g1?PNI_G1_COST:(1500+PORT[tier].setup/2)*(ex&&ex.n||1);if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(cost))return;if(S.conf&&S.conf.until>S.day)S.stats.beerPni=1;
|
|
||||||
// Nothing is instant: a cross-connect takes weeks, and the big networks quote months for a new PNI or an augment.
|
|
||||||
const lead=pniLead(net);if(ex)ex.up={tier,n:ex.n||1,ready:S.day+lead,g1:false};else S.pni.push({id:uid(),city,net,tier,g1:g1||undefined,ready:S.day+lead});
|
|
||||||
toast(tr('<b>PNI with {net} ordered.</b><br>{eta}. A cross-connect in {dc}, once somebody finds the LOA.',{net:esc(NET[net].name),eta:pniWhen(lead),dc:esc(siteName(city,'a'))}),'good');after();},
|
|
||||||
pniChase:({id})=>{const p=S.pni.find(x=>x.id===id);if(!p||(pniOn(p)&&!p.up))return;const r=Math.random();
|
|
||||||
if(r<0.15){if(p.up)p.up.ready=Math.max(S.day+1,p.up.ready-30);else p.ready=Math.max(S.day+1,p.ready-30);toast(tr('<b>Your account manager found the order under a desk.</b><br>It is a month closer.'),'good');}
|
|
||||||
else toast(pick([tr('<b>“It is with the provisioning team.”</b><br>Nobody has ever met the provisioning team.'),tr('<b>“We are waiting on the colo for the cross-connect.”</b><br>The colo says it is waiting on them.'),tr('<b>Your ticket was merged into another ticket.</b><br>That ticket was closed as a duplicate of yours.'),tr('<b>“Could you resend the LOA?”</b><br>You have sent it four times.'),tr('<b>Your account manager is on paternity leave.</b><br>His replacement is also on paternity leave.')]));after();},
|
|
||||||
inbox:()=>{inboxModal();},
|
|
||||||
inboxAct:({id,a})=>{if(!['accept','decline','raise','keep'].includes(a))return;ibxAnswer(+id,a);after();inboxModal();},
|
|
||||||
inboxAll:({a})=>{if(a!=='accept'&&a!=='decline')return;const I=ibx();for(const x of I.items.filter(x=>x.k==='req'))ibxAnswer(x.id,a,true);after();inboxModal();},
|
|
||||||
inboxBot:({on})=>{const I=ibx();if(+on){if(I.bot||!spend(AI_MO))return;I.bot=true;ibxLog(N_('Hello! I am Large Peering Model. I have read your inbox and I already have opinions.'),{});toast(tr('<b>Large Peering Model is hired.</b><br>Your inbox is its problem now. {price} a year, billed monthly.',{price:fmt$(20e6)}),'good');}else{I.bot=false;toast(tr('<b>The AI is gone.</b><br>It left a 40-page handover document. It is mostly about itself.'));}after();inboxModal();},
|
|
||||||
cancelPni:({id,ok})=>{if(!ok&&UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.pni=S.pni.filter(p=>p.id!==id);UI.confirm=null;after();},
|
|
||||||
cache:({city,net})=>{const n=NET[net];if(!n||!n.cache||!S.pops[city])return;if((R.demTo[net]||0)<n.cache.min){toast(tr('<b>{net} says not yet.</b><br>Send them {min}+ Gbps first.',{net:esc(n.name),min:n.cache.min}),'bad');sfx('err');return;}if(!portGate(city,1))return;
|
|
||||||
{const hv=S.caches.filter(x=>x.city===city&&x.net===net),nb=hv.filter(x=>x.site==='b').length;S.caches.push({id:uid(),city,net,site:S.pops[city].site2&&nb<hv.length-nb?'b':'a'});}toast(tr('<b>{cache} installed in {city}!</b><br>{net} shipped it for free. You pay {mo}/mo power.',{cache:esc(n.cache.name),city:CITY[city].name,net:esc(n.name),mo:fmt$(CACHE_MO)}),'good');sfx('build');after();},
|
|
||||||
rmCache:({id})=>{S.caches=S.caches.filter(c=>c.id!==id);after();},
|
|
||||||
// Move one of a CDN's boxes to the other building (#69), so a dark building only takes out part of the cache.
|
|
||||||
cacheSite:({city,net,s})=>{if(s!=='a'&&s!=='b'||!S.pops[city]||!S.pops[city].site2)return;const x=S.caches.find(c=>c.city===city&&c.net===net&&(c.site==='b'?'b':'a')!==s);if(!x)return;x.site=s;sfx('click');after();},
|
|
||||||
advertise:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||l.ready>S.day)return;if(S.offers.some(o=>o.link===l.id))return;
|
|
||||||
const t=freeCh(l)>=1?'wwave':pairFree(l)?'dfpair':null;if(!t){toast(tr('<b>Nothing spare to sell on this fiber.</b><br>Every channel is lit or sold, and the trench has no free pair.'),'bad');sfx('err');return;}
|
|
||||||
const T=BIZ_T[t],nm=()=>{const list=T.names.filter(n=>!S.usedNames.includes(n)),n=list.length?pick(list):pick(T.names);S.usedNames.push(n);return n;};
|
|
||||||
// A capacity broker finds a buyer at once and keeps 10% of the monthly price.
|
|
||||||
const o=fiberOffer(t,l,nm,0.9);o.broker=true;S.offers.push(o);toast(tr('<b>Listed with a capacity broker.</b><br>{name} wants {what}. Accept it on the fiber or in Deals.',{name:esc(o.name),what:esc(o.what)}),'good');sfx('click');after();},
|
|
||||||
accept:({id})=>{const o=S.offers.find(x=>x.id===id);if(!o)return;if(!bHas(o)){toast(tr('<b>You need a POP in every city on the contract first.</b>'),'bad');return;}
|
|
||||||
if(o.type==='wwave'){const l=S.links.find(x=>x.id===o.link);if(!l||chMax(l)-(l.ch||[]).length-soldSlots(l)<o.slots){toast(tr('<b>Not enough free channels on that fiber any more.</b>'),'bad');return;}}
|
|
||||||
if(BIZ_T[o.type].event&&S.day>=o.start){toast(tr('<b>Too late: the event has already started.</b>'),'bad');return;}
|
|
||||||
// A carrier renting more alien waves on a fiber it already rents grows its contract, like a real order for extra waves,
|
|
||||||
// instead of a new customer for every few waves (a big fiber business otherwise fills the save with tiny contracts).
|
|
||||||
const more=o.type==='wwave'&&S.biz.find(b=>b.type==='wwave'&&b.link===o.link&&b.name===o.name);
|
|
||||||
if(more){const l=S.links.find(x=>x.id===o.link);S.offers=S.offers.filter(x=>x!==o);more.slots=(more.slots||0)+(o.slots||0);more.rate+=o.rate;if(l)more.what=wwWhat(l,more.slots);
|
|
||||||
floater(CITY[o.city].x,CITY[o.city].y-30,tr('Signed!'),'#16A866');sfx('coin');after();return;}
|
|
||||||
S.offers=S.offers.filter(x=>x!==o);S.biz.push({id:o.id,city:o.city,city2:o.city2||null,reqs:o.reqs||[],latMax:o.latMax||null,route:BIZ_T[o.type].scenic?'scenic':BIZ_T[o.type].lat?'fast':'normal',name:o.name,type:o.type,bw:o.bw,rate:o.rate,mood:100,since:S.day,sites:o.sites||null,start:o.start,dur:o.dur,fee:o.fee,link:o.link,slots:o.slots||0,what:o.what,prov:o.prov});
|
|
||||||
floater(CITY[o.city].x,CITY[o.city].y-30,tr('Signed!'),'#16A866');sfx('coin');after();},
|
|
||||||
decline:({id})=>{S.offers=S.offers.filter(x=>x.id!==id);after();},
|
|
||||||
dropBiz:({id})=>{const b0=S.biz.find(x=>x.id===id);if(!b0)return;if(BIZ_T[b0.type].event&&S.day>=b0.start){toast(tr('<b>The event is already running.</b><br>The organisers will not let you walk out now.'),'bad');sfx('err');return;}if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.biz=S.biz.filter(b=>b.id!==id);UI.confirm=null;after();},
|
|
||||||
upLink:({id,tier})=>{tier=+tier;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='wave'||!LT[tier]||tier<=l.tier)return;{const w=subWaveWhy(tier,l.km,l.sub);if(w){toast(tr('<b>No {wave} waves on this cable.</b><br>{why}',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}if(!waveOk(l.a,l.b,tier)){toast(tr('<b>A {wave} wave needs {need} at both ends.</b>',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;}const nm=Math.round(waveMo(l.km,l.sub,tier)*(l.mult||1));if(!spend(nm))return;l.mo=nm;l.tier=tier;after();},
|
|
||||||
decomOpen:({city})=>{UI.decom=new Set(city&&S.pops[city]?[city]:[]);decomModal();},
|
|
||||||
decomToggle:({city})=>{if(!S.pops[city])return;UI.decom=UI.decom||new Set();if(UI.decom.has(city))UI.decom.delete(city);else UI.decom.add(city);decomModal();},
|
|
||||||
decomGo:()=>{const sel=[...(UI.decom||[])].filter(c=>S.pops[c]);if(!sel.length||sel.length>=Object.keys(S.pops).length)return;closeModal();UI.decom=null;UI.sel=null;decommission(sel);sfx('alert');after();},
|
|
||||||
rmLink:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}{const l=S.links.find(x=>x.id===id),back=cabBack(l);if(back>0){S.cash+=back;toast(tr('<b>{name} is called off.</b><br>The cable factory takes back the glass nobody needs: {price} back.',{name:esc(l.cname||tr('Your cable')),price:fmt$(back)}),'good');}}S.links=S.links.filter(l=>l.id!==id);UI.sel=null;UI.confirm=null;after();},
|
|
||||||
fixInc:({id})=>{const i=S.inc.find(x=>x.id===id);if(!i||!(i.cost>0))return;if(i.slow&&i.rushed)return;if(!spend(i.cost))return;
|
|
||||||
if(i.slow&&i.until>S.day+1){i.rushed=true;i.cost=0;i.until=S.day+1;const p=S.pops[i.ref];if(p)p.down=Math.min(p.down,S.day+1);toast(tr('<b>Power-cycled.</b><br>The router in {city} is booting again. It will be up tomorrow, the {chip} willing.',{city:esc(CITY[i.ref].name),chip:esc(RG[(p&&p.rgen)||0].chip)}),'good');after();return;}clearInc(i);toast(tr('<b>Fixed.</b> {what} resolved early.',{what:incTitle(i.type)}),'good');after();},
|
|
||||||
myIxUp:({city})=>{const m=S.myIx[city];if(!m)return;const f=(m.fab|0)+1,N=MYIX_FAB[f];if(!N)return;if(N.lvl>lvl()){toast(tr('<b>A {fab} fabric unlocks at customer level {lv}.</b>',{fab:N.n,lv:N.lvl}),'bad');sfx('err');return;}if(!spend(N.cost))return;m.fab=f;toast(tr('<b>{ix} now runs a {fab} fabric.</b><br>Room for {max} members. Expect a few more to join.',{ix:esc(m.name),fab:N.n,max:N.max}),'good');m.next=Math.min(m.next,S.day+3);after();},
|
|
||||||
foundIx:({city})=>{if(!S.pops[city]||S.myIx[city]||CITY[city].ix||CITY[city].cn)return;if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name;
|
|
||||||
S.myIx[city]={name:nm,members:[],next:S.day+4};S.ixp[city]=2;toast(tr('<b>You founded {ix}!</b><br>Networks will join over time and pay you for ports. Open members peer with you for free.',{ix:esc(nm)}),'goal');after();},
|
|
||||||
buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p)return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),jn=sib.length?routeJoin(a,b):null,same=!!jn,border=cnCity(a)!==cnCity(b),mult=(sib.length&&!(jn&&jn.k===(landTrenches(a,b)[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1);
|
|
||||||
if((cnCity(a)||cnCity(b))&&!cnOk())return;
|
|
||||||
if(!waveOk(a,b,tier)){toast(tr('<b>A {wave} wave needs {need} at both ends.</b>',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;}
|
|
||||||
const wr=waveRoute(a,b,mult,border);if(!wr){toast(tr('<b>No cable available for that route right now.</b>'),'bad');sfx('err');return;}
|
|
||||||
{const so=soldOut(a,b,tier,wr.cab);if(so){toast(tr('<b>No {wave} capacity on this route right now.</b><br>{why} Try a smaller wave, another route, or ask again in {n} days.',{wave:LT[tier].n,why:tr(so.why),n:Math.max(1,so.until-S.day)}),'bad');sfx('err');return;}}{const w=subWaveWhy(tier,wr.km,wr.sub);if(w){toast(tr('<b>No {wave} waves on this cable.</b><br>{why}',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}const base=Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),cost=base+(S.pops[b]?0:popCost(b));
|
|
||||||
if(!portGate(a,1)||!portGate(b,1))return;if(!spend(cost))return;if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};
|
|
||||||
const id=uid();const l={id,a,b,kind:'wave',border,premium:border&&!!UI.cnPrem&&(a==='hkg'||b==='hkg'),tier,km:wr.km,sub:wr.sub,cable:wr.cab,mo:base,mult:wr.wm,trench:wr.cab?'cab:'+wr.cab:(jn?jn.k:id),cut:0,day:S.day};S.links.push(l);closeModal();
|
|
||||||
if(sib.length){UI.sel={type:'link',id};}else{UI.sel={type:'city',id:b};UI.tab='cust';}
|
|
||||||
floater((CITY[a].x+CITY[a].x+wrapDx(CITY[a].x,CITY[b].x))/2,(CITY[a].y+CITY[b].y)/2-20,tr('{wave} lit!',{wave:LT[tier].n}),'#FF4F9A');after();},
|
|
||||||
buyNni:({city,prov,tier})=>{tier=+tier;if(!NNI[tier]||!isCity(city)||!own(FAB,prov)||!FAB[prov].cities.includes(city)||!S.pops[city])return;const ex=nniPort(city,prov);if(ex&&tier<=ex.tier)return;if(!ex&&!portGate(city,1))return;if(ex&&nniUsed(city,prov)>NNI[tier].g){toast(tr('<b>Too many circuits</b> for a smaller port.'),'bad');return;}if(!spend(NNI[tier].mo))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(tr('<b>{fab} port is up in {city}.</b><br>Now order virtual circuits to other cities on their fabric.',{fab:esc(FAB[prov].name),city:CITY[city].name}),'good');after();},
|
|
||||||
rmNni:({city,prov})=>{if(nniUsed(city,prov)>0){toast(tr('<b>Cancel the circuits on this port first.</b>'),'bad');sfx('err');return;}S.nni=S.nni.filter(x=>!(x.city===city&&x.prov===prov));after();},
|
|
||||||
openVxc:(a)=>openVxcModal(a),
|
|
||||||
buyVxc:({a,b,prov,t})=>{t=+t;const g=VXC[t].g,pa=nniPort(a,prov);if(!pa||nniUsed(a,prov)+g>NNI[pa.tier].g){toast(tr('<b>Not enough room on your fabric port.</b> Upgrade it first.'),'bad');sfx('err');return;}
|
|
||||||
if(S.pops[b]){const pb=nniPort(b,prov);if(!pb||nniUsed(b,prov)+g>NNI[pb.tier].g){toast(tr('<b>Not enough room on your {fab} port in {city}.</b>',{fab:esc(FAB[prov].name),city:CITY[b].name}),'bad');sfx('err');return;}}
|
|
||||||
const km=kmBetween(a,b),sub=isSub(a,b),mo=vxcMo(km,sub,t);if(!spend(mo))return;S.links.push({id:uid(),a,b,kind:'vxc',prov,vt:t,km,sub,mo,cut:0,day:S.day});closeModal();
|
|
||||||
toast(tr('<b>Circuit up in 59 seconds.</b><br>{vxc} over {fab}: {a} → {b}.',{vxc:VXC[t].n,fab:esc(FAB[prov].name),a:CITY[a].name,b:CITY[b].name})+(S.pops[b]?'':' '+tr('Now grab an IX port there for remote peering.')),'good');if(!S.pops[b])selectCity(b);after();},
|
|
||||||
upVxc:({id,t})=>{t=+t;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='vxc'||!VXC[t]||t<=l.vt)return;const extra=VXC[t].g-VXC[l.vt].g;for(const c of [l.a,l.b]){const pt=nniPort(c,l.prov);if(pt&&nniUsed(c,l.prov)+extra>NNI[pt.tier].g){toast(tr('<b>Fabric port in {city} is full.</b>',{city:CITY[c].name}),'bad');sfx('err');return;}}const mo=vxcMo(l.km,l.sub,t);if(!spend(mo))return;l.vt=t;l.mo=mo;after();},
|
|
||||||
cancelVxc:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.links=S.links.filter(l=>l.id!==id);const rem=remoteCities();for(const c in S.ixp){if(!S.pops[ixCity(c)]&&!rem.includes(ixCity(c))){delete S.ixp[c];delete S.rs[c];for(const k in S.peers)if(k.endsWith('@'+c))delete S.peers[k];}}UI.sel=null;UI.confirm=null;after();},
|
|
||||||
setPref:({kind,id,v})=>{if(!own(PREF,v))return;if(kind!=='t'&&kind!=='p'&&!(isIx(id)&&S.ixp[id]!==undefined))return;if(kind==='t'){const t=S.transit.find(x=>x.id===id);if(t)t.pref=v;}else if(kind==='p'){const x=S.pni.find(y=>y.id===id);if(x)x.pref=v;}else{S.ixPref=S.ixPref||{};S.ixPref[id]=v;}sfx('click');after();},
|
|
||||||
setMetric:({id,v})=>{if(!own(MET,v))return;const l=S.links.find(x=>x.id===id);if(!l)return;for(const x of pairLinks(l.a,l.b))x.metric=v;sfx('click');after();},
|
|
||||||
goEgress:({city,k})=>{ACT.focusCity({city});UI.tab=k==='t'?'up':k==='l2'?'cust':k==='nni'?'links':'peer';renderPanel();},
|
|
||||||
custGo:({id})=>{const b=S.biz.find(x=>x.id===id);if(!b)return;$('dash').hidden=true;ACT.focusCity({city:b.city});UI.tab='cust';renderPanel();},
|
|
||||||
listMore:({k})=>{if(k!=='conn'&&k!=='cust')return;UI.listN=UI.listN||{};UI.listN[k]=listN(k)+LIST_PAGE;renderDash();},
|
|
||||||
custF:({v})=>{UI.kf=UI.kf||{};UI.kf.f=v==='sad'?'sad':'';listReset('cust');renderDash();},
|
|
||||||
custCity:({v})=>{UI.kf=UI.kf||{};UI.kf.city=isCity(v)?v:'';listReset('cust');renderDash();},
|
|
||||||
custSort:({k})=>{if(!['mood','mo','name','city'].includes(k))return;listReset('cust');if(UI.custSort===k)UI.custDir=-(UI.custDir||1);else{UI.custSort=k;UI.custDir=k==='mo'?-1:1;}renderDash();},
|
|
||||||
custOpen:({sad}={})=>{if(!S)return;UI.kf=sad?{f:'sad'}:{};listReset('cust');UI.dtab='cust';const d=$('dash');d.hidden=false;renderDash();d.scrollTop=0;},
|
|
||||||
goConn:({city,k})=>{if(!isCity(city)||!own(CONN_K,k))return;$('dash').hidden=true;ACT.goEgress({city,k});},
|
|
||||||
connF:({f,v})=>{const F=UI.cf=UI.cf||{};listReset('conn');if(f==='all'){UI.cf={};}else if(f==='k'){F.k=own(CONN_K,v)?v:'';}renderDash();},
|
|
||||||
connCity:({v})=>{UI.cf=UI.cf||{};listReset('conn');UI.cf.city=isCity(v)?v:'';renderDash();},
|
|
||||||
connNet:({v})=>{UI.cf=UI.cf||{};listReset('conn');UI.cf.net=NET[v]?v:'';renderDash();},
|
|
||||||
connSort:({k})=>{if(!['k','city','name','use','mo'].includes(k))return;listReset('conn');if(UI.connSort===k)UI.connDir=-(UI.connDir||1);else{UI.connSort=k;UI.connDir=k==='use'||k==='mo'?-1:1;}renderDash();},
|
|
||||||
connFor:({net})=>{if(!NET[net])return;UI.cf={net};ACT.connOpen();},
|
|
||||||
connCancel:({k,id})=>{const r=conns().find(x=>x.k===k&&x.id===id);if(!r||r.mine)return;const key='cc:'+k+':'+id;if(UI.confirm!==key){UI.confirm=key;renderDash();return;}UI.confirm=null;
|
|
||||||
if(k==='t')ACT.cancelTransit({id,ok:1});else if(k==='p')ACT.cancelPni({id,ok:1});else if(k==='ix')ACT.cancelIx({city:id,ok:1});else if(k==='c')ACT.rmCache({id});else{const [city,prov]=id.split('|');ACT.rmNni({city,prov});}renderDash();},
|
|
||||||
connOpen:()=>{if(!S)return;UI.dtab='conn';listReset('conn');const d=$('dash');d.hidden=false;renderDash();d.scrollTop=0;},
|
|
||||||
applyCn:()=>{if(S.cnLic.state!=='none')return;if(!spend(CN_LIC))return;S.cnLic={state:'pending',ready:S.day+45};toast(tr('<b>Application filed.</b><br>Your local partner says about 45 days. Probably.'),'goal');after();},
|
|
||||||
togglePrem:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.premium=!t.premium;sfx('click');after();},
|
|
||||||
buildScrub:({city,tier})=>{if(!S.pops[city]||S.scrubs.some(x=>x.city===city))return;const T=SCRUB_TIERS[tier||0];if(!T)return;if((lvl()||1)<T.lvl){toast(tr('<b>{tier} scrubbing unlocks at customer level {lv}.</b>',{tier:T.n,lv:T.lvl}),'bad');sfx('err');return;}if(!spend(T.cost))return;if(!hasScrub())S.scrubMode='always';S.scrubs.push({city,tier:tier||0});toast(tr('<b>{tier} scrubbing center online in {city}.</b><br>Attacks up to {g} are cleaned, and you can sell DDoS protection.',{tier:T.n,city:CITY[city].name,g:fmtG(T.g)}),'good');after();},
|
|
||||||
scrubUp:({city,tier})=>{const x=S.scrubs.find(q=>q.city===city);tier=+tier;if(!x||!SCRUB_TIERS[tier]||tier<=(x.tier||0))return;const T=SCRUB_TIERS[tier];if((lvl()||1)<T.lvl){toast(tr('<b>{tier} scrubbing unlocks at customer level {lv}.</b>',{tier:T.n,lv:T.lvl}),'bad');sfx('err');return;}if(!spend(Math.round(T.cost*0.6)))return;x.tier=tier;toast(tr('<b>Scrubbing upgraded to {tier}.</b>',{tier:T.n}),'good');after();},
|
|
||||||
scrubMode:()=>{if(!hasScrub())return;S.scrubMode=S.scrubMode==='ondemand'?'always':'ondemand';sfx('click');after();},
|
|
||||||
rmScrub:({city})=>{if(!S.scrubs.some(x=>x.city===city))return;if(UI.confirm!=='scrub:'+city){UI.confirm='scrub:'+city;renderAll();return;}S.scrubs=S.scrubs.filter(x=>x.city!==city);if(!hasScrub())S.scrubMode='always';UI.confirm=null;after();},
|
|
||||||
cleanPipe:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.clean=!t.clean;toast(t.clean?tr('<b>Clean-pipe add-on enabled on {net}.</b><br>They scrub a flood before it reaches your port here, for {mo}/mo.',{net:NET[t.net].name,mo:fmt$(cleanMo(t))}):tr('<b>Clean-pipe add-on removed from {net}.</b>',{net:NET[t.net].name}),t.clean?'good':'');after();},
|
|
||||||
sacrif:({id})=>{const p=S.pni.find(x=>x.id===id);if(!p)return;p.sacrif=!p.sacrif;toast(p.sacrif?tr('<b>{net} PNI is now a sacrificial choke point.</b><br>A flood from there dies on the small port instead of inside your network, but legit traffic over it runs at half capacity.',{net:NET[p.net].name}):tr('<b>{net} PNI is back to normal.</b>',{net:NET[p.net].name}),p.sacrif?'good':'');after();},
|
|
||||||
ixbh:()=>{const a=S.ev.ddos;if(!a){toast(tr('<b>No attack to blackhole right now.</b>'),'');return;}if(!hasIxAt(a.city)){toast(tr('<b>No IX in {city} to announce a blackhole to.</b>',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('<b>IX blackhole announced in {city}.</b><br>About half the members honour the /32 and drop the junk. The customer stays up.',{city:CITY[a.city].name}):tr('<b>IX blackhole withdrawn.</b>'),a.ixbh?'good':'');sfx('alert');after();},
|
|
||||||
rtbh:()=>{const a=S.ev.ddos;if(!a){toast(tr('<b>No attack to blackhole right now.</b>'),'');return;}a.bh=true;S.stats.rtbh=(S.stats.rtbh||0)+1;toast(tr('<b>RTBH announced.</b><br>You blackholed the target in {city}. The flood stops, and so does everyone there.',{city:CITY[a.city].name}),'bad');sfx('alert');after();},
|
|
||||||
unrtbh:()=>{const a=S.ev.ddos;if(!a||!a.bh)return;a.bh=false;toast(tr('<b>Blackhole withdrawn.</b><br>{city} is reachable again. Brace for the junk.',{city:CITY[a.city].name}),'');after();},
|
|
||||||
hackback:()=>{const a=S.ev.ddos;if(!a||a.until<=S.day){toast(tr('<b>Nothing to hack back right now.</b>'),'');return;}if(!spend(20000))return;S.stats.hackback=(S.stats.hackback||0)+1;
|
|
||||||
if(Math.random()<0.35){a.until=S.day;a.bh=false;S.stats.hackWin=(S.stats.hackWin||0)+1;toast(tr('<b>HackBack 3000™ strikes back!</b><br>Skynot AI traced the botnet and politely bricked it. The attack on {city} stops cold.',{city:CITY[a.city].name}),'goal');sfx('coin');}
|
|
||||||
else{const fine=15000+Math.floor(Math.random()*35000);S.cash-=fine;S.stats.vigilante=(S.stats.vigilante||0)+1;
|
|
||||||
toast(tr('<b>HackBack 3000™ hit the wrong target.</b><br>{who} A regulator sends you a {fine} fine, and the attack rolls on.',{who:pick([tr("Skynot AI flattened a grandma's internet-connected fridge."),tr('You counter-flooded a hospital in a country you cannot pronounce.'),tr('The botnet was already someone else’s botnet. They are furious.')]),fine:fmt$(fine)}),'bad');sfx('err');}
|
|
||||||
after();},
|
|
||||||
cnPrem:({v})=>{UI.cnPrem=!!+v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
via:({v})=>{UI.via=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;sfx('click');after();}},
|
|
||||||
route:({r})=>{UI.route=r;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
addParallel:({id})=>{const l=S.links.find(x=>x.id===id);if(l)openLinkModal(l.a,l.b);},
|
|
||||||
addRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)>=RMAX)return;if(!spend(routerCost(p.rgen||0)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,tr('Router added'),'#FF4F9A');after();},
|
|
||||||
models:()=>{UI.models=!UI.models;renderPanel();},
|
|
||||||
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(tr('<b>Unplug something first.</b><br>{used} ports are in use, and one router fewer only has {max}.',{used:fmtPorts(portsUsed(city)),max:portsMax(city,undefined,p.routers-1)}),'bad');sfx('err');return;}p.routers--;{const back=tradeIn(p.rgen||0,1);if(back>0){S.cash+=back;toast(tr('<b>Sold a {model} on eBuy.</b><br>{price} back.',{model:esc(RG[p.rgen||0].n),price:fmt$(back)}),'good');}}after();},
|
|
||||||
upRouter:({city,g})=>{const p=S.pops[city];if(!p)return;g=g===undefined?mainRG(RG[p.rgen||0].cls+1):+g;if(!RG[g]||g===(p.rgen||0))return;{const why=modelFits(city,g);if(why){toast(tr("<b>The {model} won't fit.</b><br>{why}",{model:esc(RG[g].n),why:esc(why)}),'bad');sfx('err');return;}}if(RG[g].lvl>lvl()){toast(tr('<b>{model} unlocks at customer level {lv}.</b>',{model:esc(RG[g].n),lv:RG[g].lvl}),'bad');sfx('err');return;}
|
|
||||||
const rt=p.routers||1,old=p.rgen||0;if(p.rupDay===S.day){toast(tr('<b>The new routers in {city} are still being racked.</b><br>One swap a day: try again tomorrow.',{city:CITY[city].name}),'bad');sfx('err');return;}const back=tradeIn(old,rt);if(!spend(swapCost(city,g)))return;p.rgen=g;p.rupDay=S.day;if(back>0)toast(tr('<b>Sold the old {model} on eBuy.</b><br>{price} back toward the new gear.',{model:esc(RG[old].n),price:fmt$(back)}),'good');
|
|
||||||
if(rt===1&&popIdle(city))toast(tr('<b>New router in {city}</b><br>Swapped before anything was plugged in: zero downtime, zero angry customers.',{city:CITY[city].name}),'good');
|
|
||||||
else if(rt===1){const sl=slowBoot(city),dd=sl?3:1;p.down=Math.max(p.down||0,S.day+dd);addInc({type:'maint',ref:city,until:S.day+dd,msg:sl?tr('Swapping the only router in {city} for a {model}. The new one {how}. Back in {n} days.',{city:CITY[city].name,model:RG[g].n,how:pick(SLOW_BOOT),n:dd}):tr('Swapping the only router in {city} for a {model}. Maintenance window: back tomorrow.',{city:CITY[city].name,model:RG[g].n}),cost:0});toast(`<b>${tr('Maintenance window in {city}',{city:CITY[city].name})}</b><br>${sl?tr('One router, and this one takes forever to boot. Back in {n} days.',{n:dd}):tr('One router means downtime during the swap. Back tomorrow.')}`,'bad');}
|
|
||||||
else toast(tr('<b>Rolling upgrade in {city}</b><br>{n} × {model}, swapped one at a time. Zero downtime.',{city:CITY[city].name,n:rt,model:esc(RG[g].n)}),'good');
|
|
||||||
floater(CITY[city].x,CITY[city].y-30,RG[g].n+'!','#FF4F9A');after();},
|
|
||||||
dfMode:({m})=>{UI.lmode=m;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
seaPackage:({k})=>{if(!own(SUB_UPGRADES,k))return;UI['sea'+k]=!UI['sea'+k];if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
subUpgrade:({id,k})=>{const l=S.links.find(l=>l.id===id);if(!l||l.kind!=='df'||!l.own||!l.sub||!own(SUB_UPGRADES,k)||lvl()<4||l['sub'+k]!==undefined)return;if(!spend(subUpgradeCost(l,k)))return;l.paid=(l.paid>0?l.paid:ownCabCost(l.km))+subUpgradeCost(l,k);l['sub'+k]=Math.max(S.day,l.ready||0)+SUB_UPGRADES[k].days;after();},
|
|
||||||
seaDesign:({v})=>{if(!own(SEA_DESIGNS,v))return;UI.seaDesign=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
ownCab:()=>{UI.lmode='df';UI.dfSrc='cable';UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
dfSrc:({v})=>{UI.dfSrc=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
dfSys:({v})=>{UI.dfSys=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
|
||||||
orderCable:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(ownCabWhy(a,b))return;const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',up={terminal:!!UI.seaterminal,engineering:!!UI.seaengineering},q=seaQuote(a,b,design,up),km=q.km,cost=q.cost+(S.pops[b]?0:popCost(b));if(seaLack(km,up).length||!spend(cost))return;
|
|
||||||
if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};
|
|
||||||
const used=new Set(S.links.map(l=>l.cname).filter(Boolean)),cname=OWNCAB_NAMES.find(n=>!used.has(n))||`${pick(OWNCAB_NAMES)} ${used.size+1}`,ship=pick(OWNCAB_SHIPS),id=uid(),days=q.days;
|
|
||||||
S.links.push({id,a,b,kind:'df',own:true,sub:true,seaDesign:design,seaPath:q.pts.map(p=>p.slice()),sys:'roadm',ch:[],km,cable:null,cname,mo:Math.round(km*OWNCAB_OM),trench:'own:'+id,cut:0,day:S.day,ready:S.day+days,spares:false,pairs:1});
|
|
||||||
const laid=S.links[S.links.length-1];laid.paid=q.cost;for(const k of Object.keys(SUB_UPGRADES))if(up[k])laid['sub'+k]=laid.ready;UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false;
|
|
||||||
S.stats.ownCab=(S.stats.ownCab||0)+1;UI.dfSrc='lease';closeModal();UI.sel={type:'link',id};
|
|
||||||
toast(tr('<b>The {ship} sets sail!</b><br>{name}, your own {km} km cable from {a} to {b}. Ready in about {n} days, if the whales cooperate.',{ship,name:cname,km:km.toLocaleString(),a:CITY[a].name,b:CITY[b].name,n:days}),'goal');sfx('build');after();},
|
|
||||||
orderDf:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(!dfAllowed(a,b))return;const sc=isSub(a,b)?subDfCable(a,b):null,km=sc?sc.km:kmBetween(a,b);
|
|
||||||
const own=UI.dfSrc==='build'&&lvl()>=3&&!sc,sys=DF_SYS[UI.dfSys]&&DF_SYS[UI.dfSys].lvl<=lvl()?UI.dfSys:'lite';if(lvl()<2)return;
|
|
||||||
const up=(own?dfBuildCost(km):0)+DF_SYS[sys].cost+ampCount(km)*AMP_COST+(S.pops[b]?0:popCost(b));if(!spend(up))return;
|
|
||||||
if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};
|
|
||||||
const sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),id=uid();
|
|
||||||
const l={id,a,b,kind:'df',own,sys,ch:[],km,sub:!!sc,cable:sc?sc.cid:null,mo:own?Math.round(km*0.15):dfLeaseMo(km),trench:sc?'cab:'+sc.cid:id,cut:0,day:S.day,ready:S.day+(own?dfBuildDays(km):30),spares:false};
|
|
||||||
S.links.push(l);closeModal();UI.sel={type:'link',id};
|
|
||||||
toast(own?tr('<b>Groundbreaking!</b><br>Your own fiber from {a} to {b}. Permits and digging take about {n} days.',{a:CITY[a].name,b:CITY[b].name,n:dfBuildDays(km)}):tr('<b>Dark fiber IRU signed.</b><br>{a}–{b} will be spliced and handed over in about 30 days.',{a:CITY[a].name,b:CITY[b].name}),'goal');after();},
|
|
||||||
regen:({id,d})=>{d=+d;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||l.sub||(d!==1&&d!==-1))return;const n=(l.regen|0)+d;if(n<0||n>REGEN_MAX)return;
|
|
||||||
if(d<0&&(l.ch||[]).some(o=>!optMode(o,{km:l.km,regen:n}))){toast(tr('<b>Those optics need the regen site.</b><br>Remove the long-haul channels first, or keep the site.'),'bad');sfx('err');return;}
|
|
||||||
if(d>0&&!spend(REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH)))return;l.regen=n;toast(d>0?tr('<b>Regen site {n} is up.</b><br>Optical spans on {a}–{b} are now {km} km.',{n,a:CITY[l.a].name,b:CITY[l.b].name,km:spanKm(l).toLocaleString()}):tr('<b>Regen site removed.</b>'),'good');sfx('build');after();},
|
|
||||||
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(tr("<b>Can't add {optic}.</b><br>{why}",{optic:O.n,why:esc(why)}),'bad');sfx('err');return;}if(!portGate(l.a,1)||!portGate(l.b,1))return;const sp=spareN(o)>0;if(!spend(chCost(l,o)))return;if(sp)S.spares[o]--;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();},
|
|
||||||
rmCh:({id,o})=>{const l=S.links.find(x=>x.id===id);if(!l||!OPT[o])return;const i=(l.ch||[]).lastIndexOf(o);if(i<0)return;l.ch.splice(i,1);S.spares=S.spares||{};S.spares[o]=(S.spares[o]||0)+1;floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,tr('{optic} to spares',{optic:OPT[o].n}),'#7B61FF');after();},
|
|
||||||
hwLock:()=>{if(hwLock())return;const c=hwLockCost();if(!spend(c))return;S.hw=S.hw||{};S.hw.lock={until:S.day+HW_LOCK_DAYS,mul:hwTrend(S.day)};toast(tr('<b>Prices locked until {date}.</b><br>Your vendor’s account manager is delighted. He gets a bonus for this.',{date:dateStr(S.hw.lock.until)}),'good');after();},
|
|
||||||
buySpare:({o})=>{if(!OPT[o]||OPT[o].lvl>lvl()||spareN(o)>=64)return;if(!spend(optCost(o)))return;S.spares=S.spares||{};S.spares[o]=(S.spares[o]||0)+1;sfx('build');after();},
|
|
||||||
sellSpare:({o})=>{if(!OPT[o]||spareN(o)<1)return;S.spares[o]--;const v=spareValue(o);S.cash+=v;toast(tr('<b>Sold a spare {optic} on eBuy.</b><br>{price} back, which is {p} of what it cost new.',{optic:OPT[o].n,price:fmt$(v),p:pct(SPARE_RESALE)}),'good');sfx('coin');after();},
|
|
||||||
addPair:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||!isRdm(l.sys)||l.ready>S.day)return;const n=Math.max(1,l.pairs|0);if(n>=pairsMax(l))return;if((l.ch||[]).length+soldSlots(l)<chMax(l)){toast(tr('<b>Fill this pair first.</b><br>Light all {max} channels before you light another fiber pair.',{max:chMax(l)}),'bad');sfx('err');return;}if(!spend(pairCost(l)))return;l.pairs=n+1;toast(tr('<b>Fiber pair {n} is lit: {a}–{b}.</b><br>Another ROADMaster 9000 and a fresh chain of amplifiers. Room for {m} more channels.',{n:n+1,a:CITY[l.a].name,b:CITY[l.b].name,m:DF_SYS[l.sys].max}),'good');sfx('build');after();},
|
|
||||||
upSys:({id})=>{const l=S.links.find(x=>x.id===id),to=l&&sysNext(l);if(!to||DF_SYS[to].lvl>lvl())return;if(!spend(sysUpCost(l)))return;l.sys=to;if(l.ready<=S.day){l.eqDown=S.day+1;toast(tr('<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.'),'bad');}after();},
|
|
||||||
spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();},
|
|
||||||
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.ready<=S.day+1)return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(S.day+1,l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('<b>More crews on site.</b><br>Construction is {n} day ahead.','<b>More crews on site.</b><br>Construction is {n} days ahead.',saved,{n:saved}),'good');after();},
|
|
||||||
addGen:({city})=>{const p=S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('Generator!'),'#FF8A3D');after();},
|
|
||||||
randomName:()=>{const input=$('nmIn');if(input)input.value=UI.nm=randomNetworkName(input.value);},
|
|
||||||
start:()=>{const nm=(($('nmIn')&&$('nmIn').value)||randomNetworkName()).slice(0,24);beginGame(nm,UI.startCity,{mode:UI.mode==='sandbox'?'sandbox':'normal'});},
|
|
||||||
modeSet:({m})=>{UI.mode=m;document.querySelectorAll('.modeb').forEach(b=>b.classList.toggle('pink',b.dataset.m===m));document.querySelectorAll('.modeb').forEach(b=>b.classList.toggle('ghost',b.dataset.m!==m));},
|
|
||||||
scenarios:()=>{UI.nm=(($('nmIn')&&$('nmIn').value)||UI.nm||(S&&S.name)||randomNetworkName()).slice(0,24);scenarioModal();},
|
|
||||||
startScn:({id,sure})=>{const sc=SCN.find(x=>x.id===id);if(!sc)return;if(!sure&&S&&UI.started&&!S.lost&&!(S.scn&&(S.scn.done||S.scn.failed))){openModal(`<h2 style="font-size:26px">${tr('Start {name}?',{name:esc(sc.n)})}</h2><p class="tagline">${tr('{name} will be replaced. Export it from the menu first if you want to keep it.',{name:esc(S.name)})}</p><div class="btns">${btn(tr('Start the scenario'),'startScn',{id,sure:1},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`);return;}beginGame(UI.nm||(S&&S.name)||randomNetworkName(),sc.city,{scn:sc});},
|
|
||||||
startWeekly:({sure}={})=>{if(!sure&&S&&UI.started&&!S.lost&&!(S.scn&&(S.scn.done||S.scn.failed))){openModal(`<h2 style="font-size:26px">${tr('Start the weekly challenge?')}</h2><p class="tagline">${tr('{name} will be replaced. Export it from the menu first if you want to keep it.',{name:esc(S.name)})}</p><div class="btns">${btn(tr('Start the challenge'),'startWeekly',{sure:1},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`);return;}const wk=weekly();beginGame(UI.nm||(S&&S.name)||randomNetworkName(),wk.city,{scn:wk,seed:wk.seed});},
|
|
||||||
pickStart:({city})=>{UI.startCity=city;document.querySelectorAll('.start').forEach(b=>b.classList.toggle('on',b.dataset.city===city));},
|
|
||||||
cont:()=>{migrate(S);track('game_continue',true);UI.started=true;closeModal();renderAll();},
|
|
||||||
newgame:()=>{try{localStorage.removeItem('sot-save-v1');}catch(e){}S=null;UI.started=false;UI.sel=null;UI.nm=null;$('dash').hidden=true;$('bankBox').hidden=true;renderAll();showTitle();},
|
|
||||||
keepPlaying:()=>{closeModal();},
|
|
||||||
exportSave:()=>exportSave(),
|
|
||||||
importPick:()=>{let f=$('importIn');if(!f){f=document.createElement('input');f.type='file';f.accept='.json,application/json';f.id='importIn';f.hidden=true;document.body.appendChild(f);f.addEventListener('change',()=>{importFile(f.files[0]);f.value='';});}f.click();},
|
|
||||||
importGo:()=>{const s0=UI.importing;if(!s0)return;UI.importing=null;const prev=S;try{S=migrate(JSON.parse(JSON.stringify(s0)));compute();checkGoals();renderAll();}catch(e){S=prev;if(S)compute();renderAll();toast(tr('<b>Import failed.</b><br>That save is damaged and could not be loaded. Your current game is untouched.'),'bad');sfx('err');return;}UI.confirm=null;$('bankBox').hidden=true;$('dash').hidden=true;UI.started=true;UI.sel=null;UI.speed=S.uiSpeed===undefined?1:S.uiSpeed;if(S.cam&&isFinite(S.cam.x))Object.assign(cam,S.cam);else{const h=CITY[S.home];if(h){cam.x=h.x;cam.y=h.y;}}closeModal();$('modal').hidden=true;compute();renderAll();save();toast(tr('<b>Welcome back, {name}.</b><br>Imported and saved on this device.',{name:esc(S.name)}),'good');sfx('coin');track('game_import');},
|
|
||||||
menu:()=>{if(!S||!UI.started){showTitle();return;}openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">AS${S.asn} · ${esc(dateStr(S.day))} · ${tierLabel()}</div><h2 style="font-size:28px">${esc(S.name)}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('Close')}">×</button></div>
|
|
||||||
<p class="tagline">${tr('Your game saves itself every few seconds on this device.')}</p>${isPhone()?installRow():''}
|
|
||||||
<div class="menu-list">
|
|
||||||
${btn(tr('Back to the map'),'closeModal',{},'pink big')}
|
|
||||||
${btn(tr('Export save <small>download a file</small>'),'exportSave',{},'')}
|
|
||||||
${btn(tr('Import a save <small>from a file</small>'),'importPick',{},'')}
|
|
||||||
${btn(tr('Share your network <small>image card</small>'),'share',{},'')}
|
|
||||||
${btn(tr('Scenarios & weekly challenge'),'scenarios',{},'ghost')}
|
|
||||||
${btn(tr('How to play'),'help',{},'ghost')}
|
|
||||||
${RELEASE_NOTES.length?btn(tr('What’s new in {v}',{v:esc(APP_VERSION)}),'whatsNewShow',{},'ghost'):''}
|
|
||||||
${btn(tr('Settings'),'settings',{},'ghost')}
|
|
||||||
${btn(tr('Start a new network'),'resetAsk',{},'red')}
|
|
||||||
</div>${chatHtml()}`);},
|
|
||||||
settings:()=>{UI.setOpen=true;openModal(settingsHtml());},
|
|
||||||
settingsClose:()=>{UI.setOpen=false;if(!S||!UI.started)showTitle();else closeModal();},
|
|
||||||
prefSet:({v})=>{const [k,b]=String(v).split(':');if(!own(PREF_DEF,k))return;setPref(k,b==='1');sfx('click');refreshSettings();},
|
|
||||||
vpSet:({v})=>{vpOn(v==='on');refreshSettings();},
|
|
||||||
resetAsk:()=>openModal(`<h2 style="font-size:26px">${tr('Start a new network?')}</h2><p class="tagline">${tr('{name} and everything it owns will be deleted. This cannot be undone.',{name:esc(S?S.name:tr('Your network'))})}</p><div class="btns">${btn(tr('Delete and start over'),'newgame',{},'red big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`),
|
|
||||||
whatsNewShow:()=>whatsNew(true,true),
|
|
||||||
updateNow:()=>{save();location.reload();},
|
|
||||||
updateLater:()=>{$('update').hidden=true;UI.updLater=Date.now();},
|
|
||||||
helpClose:()=>{if(UI.started)closeModal();else showTitle();},
|
|
||||||
};
|
|
||||||
49
src/game/90-actions/10-interface.js
Normal file
49
src/game/90-actions/10-interface.js
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* ================= ACTIONS ================= */
|
||||||
|
function spend(c){if(S.cash<c){toast(tr('<b>Not enough cash.</b><br>Wait for revenue, or speed up time.'),'bad');sfx('err');return false;}S.cash-=c;sfx('build');return true;}
|
||||||
|
const ACT={
|
||||||
|
speed:({v})=>{v=+v;if(![0,0.5,1,2,4,8].includes(v))return;if(v)UI.lastSpeed=v;UI.speed=v;renderHUD();},
|
||||||
|
help:()=>showHelp(),
|
||||||
|
dash:()=>{if(!S)return;const d=$('dash');d.hidden=!d.hidden;if(!d.hidden)renderDash();},
|
||||||
|
dashClose:()=>{$('dash').hidden=true;},
|
||||||
|
dashTab:({k})=>{if(!DTABS.includes(k))return;UI.dtab=k;renderDash();const d=$('dash');if(d)d.scrollTop=0;},
|
||||||
|
dashSort:({k})=>{if(!['name','asn','type','traffic','cost','lost'].includes(k))return;if(UI.dashSort===k)UI.dashDir=-(UI.dashDir||-1);else{UI.dashSort=k;UI.dashDir=k==='name'||k==='type'||k==='asn'?1:-1;}renderDash();},
|
||||||
|
bank:()=>{if(!S)return;UI.confirm=null;$('dash').hidden=true;const b=$('bankBox');b.hidden=false;UI._bh=null;renderBank();},
|
||||||
|
bankClose:()=>{UI.confirm=null;$('bankBox').hidden=true;},
|
||||||
|
takeLoan:({id})=>{const o=S.loanOffers.find(x=>x.id===id);if(!o)return;S.stats.loans=(S.stats.loans||0)+1;const B=BANKS[o.bank];let got=o.amount,note='';
|
||||||
|
if(B.crypto){const f=0.55+Math.random()*0.8;got=Math.round(o.amount*f);note=' '+(f>=1?tr('TubeCoin moved up {p}% on the way to your account.',{p:Math.round(Math.abs(f-1)*100)}):tr('TubeCoin moved down {p}% on the way to your account.',{p:Math.round(Math.abs(f-1)*100)}));}
|
||||||
|
S.cash+=got;S.loanOffers=S.loanOffers.filter(x=>x!==o);
|
||||||
|
S.loans.push({id:o.id,bank:o.bank,start:S.day,amount:o.amount,got,bal:o.model==='transit'?o.owe:o.amount,apr:o.apr||0,apr0:o.apr||0,pay:o.pay||0,left:o.term||0,term:o.term||0,share:o.share||0,model:o.model,cut:o.cut,covs:o.covs,base:{sub:S.links.filter(x=>x.sub).length}});
|
||||||
|
track('loan_taken');toast(`<b>${tr('{amt} from {bank} has landed.',{amt:fmt$(got),bank:esc(B.name)})}</b><br>${B.equity?tr('They now own {p} of your revenue.',{p:pct(o.share)}):loanSummary(o)}${note}`,'good');sfx('coin');after();renderBank();},
|
||||||
|
declineLoan:({id})=>{S.loanOffers=S.loanOffers.filter(x=>x.id!==id);sfx('click');renderBank();renderHUD();save();},
|
||||||
|
repayLoan:({id})=>{const l=S.loans.find(x=>x.id===id);if(!l)return;const B=BANKS[l.bank];const cost=repayCost(l,B);
|
||||||
|
if(UI.confirm!==id){UI.confirm=id;renderBank();return;}UI.confirm=null;if(!spend(cost)){renderBank();return;}S.loans=S.loans.filter(x=>x!==l);track('loan_repaid');
|
||||||
|
toast(B.equity?tr('<b>You bought out {bank}.</b><br>They flew off to find another startup.',{bank:esc(B.name)}):tr('<b>Loan from {bank} repaid early.</b>',{bank:esc(B.name)}),'good');after();renderBank();},
|
||||||
|
leaseSwap:({a,b,src})=>{if(!S.pops[a]||!S.pops[b]||a===b)return;$('dash').hidden=true;UI.lmode='df';UI.dfSrc=['lease','build','cable'].includes(src)?src:isSub(a,b)?'cable':'build';UI.dfSys=lvl()>=3?'roadm':'lite';openLinkModal(a,b);},
|
||||||
|
dashLink:({id})=>{$('dash').hidden=true;selectLink(id);},
|
||||||
|
animSet:({v})=>{if(!['auto','on','off'].includes(v))return;UI.anim=v;try{localStorage.setItem('sot-anim',v);}catch(e){}applyAnim();refreshSettings();},
|
||||||
|
soundSet:({v})=>{UI.muted=v==='off';try{localStorage.setItem('sot-mute',UI.muted?'1':'0');}catch(e){}renderHUD();refreshSettings();},
|
||||||
|
langSet:({v})=>{if(!Object.hasOwn(LANGS,v)||v===LANG)return;try{localStorage.setItem('sot-lang',v);}catch(e){}save();location.reload();},
|
||||||
|
mute:()=>{UI.muted=!UI.muted;try{localStorage.setItem('sot-mute',UI.muted?'1':'0');}catch(e){}renderHUD();},
|
||||||
|
closePanel:()=>{UI.sel=null;UI.confirm=null;renderPanel();renderLeft();},
|
||||||
|
closeModal:()=>closeModal(),
|
||||||
|
tab:({t})=>{UI.tab=t;UI.confirm=null;renderPanel();},
|
||||||
|
leftTab:({t})=>{UI.left=t;UI.leftOpen=true;renderLeft();},
|
||||||
|
netFocus:({id})=>{if(!NET[id])return;$('dash').hidden=true;UI.netFocus=id;UI.nf='all';UI.left='nets';UI.leftOpen=true;UI.sel=null;renderPanel();renderLeft();const b=$('leftBody');if(b)b.scrollTop=0;},
|
||||||
|
netFilter:({f})=>{UI.nf=f==='out'?'out':'all';UI.netFocus=null;$('dash').hidden=true;UI.left='nets';UI.leftOpen=true;UI.sel=null;renderPanel();renderLeft();const b=$('leftBody');if(b)b.scrollTop=0;},
|
||||||
|
meetGo:({city})=>{if(!isCity(city))return;$('dash').hidden=true;ACT.focusCity({city});if(S.pops[city]){UI.tab='peer';renderPanel();}},
|
||||||
|
toggleLeft:()=>{UI.leftOpen=!UI.leftOpen;renderLeft();},
|
||||||
|
phoneTab:({t})=>{if(!['goals','deals','noc','nets'].includes(t))return;haptic(8);if(UI.leftOpen&&UI.left===t&&!UI.sel){UI.leftOpen=false;}else{UI.left=t;UI.leftOpen=true;UI.sel=null;renderPanel();}$('left').classList.remove('full');renderLeft();},
|
||||||
|
phonePlay:()=>{haptic(10);if(UI.speed){UI.lastSpeed=UI.speed;UI.speed=0;}else UI.speed=UI.lastSpeed||1;renderHUD();},
|
||||||
|
phoneSpeed:()=>{haptic(8);const cur=UI.speed||UI.lastSpeed||1,i=SPEEDS.indexOf(cur),n=SPEEDS[(i+1)%SPEEDS.length];UI.speed=n;UI.lastSpeed=n;renderHUD();},
|
||||||
|
install:()=>{if(installEvt){installEvt.prompt();installEvt.userChoice.finally(()=>{installEvt=null;});return;}
|
||||||
|
openModal(pitchHtml(false));},
|
||||||
|
pitchSkip:()=>{const p=UI.pendGame;UI.pendGame=null;UI.pitched=true;if(p)beginGame(...p);else closeModal();},
|
||||||
|
logOpen:({id})=>{const e=(S.log||[]).find(x=>x.id===id),o=e&&e.o;if(!o)return;$('dash').hidden=true;closeModal();
|
||||||
|
if(o.a==='city'&&isCity(o.v)){ACT.focusCity({city:o.v});return;}
|
||||||
|
if(o.a==='link'){if(S.links.some(l=>l.id===o.v)){ACT.selLink({id:o.v});return;}toast(tr('<b>That link is gone.</b><br>It was removed or decommissioned since.'),'');return;}
|
||||||
|
if(o.a==='cust'){if(S.biz.some(b=>b.id===o.v)){ACT.custGo({id:o.v});return;}toast(tr('<b>That customer is gone.</b><br>The contract ended since.'),'');return;}
|
||||||
|
if(o.a==='bank'){ACT.bank({});return;}if(o.a==='inbox'){ACT.inbox({});return;}if(o.a==='tab'&&LOG_TABS.includes(o.v))ACT.leftTab({t:o.v});},
|
||||||
|
logAll:()=>{UI.logAll=!UI.logAll;renderLeft();},
|
||||||
|
focusCity:({city})=>{selectCity(city);const C=CITY[city];cam.x=C.x;cam.y=C.y;cam.z=Math.max(cam.z,1.2);if(innerWidth<760)UI.leftOpen=false;renderLeft();},
|
||||||
|
selLink:({id})=>selectLink(id),
|
||||||
|
};
|
||||||
26
src/game/90-actions/20-pops-transit-ix.js
Normal file
26
src/game/90-actions/20-pops-transit-ix.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
buildPop:({city})=>{if(S.pops[city])return;const flipNote=CITY[city]&&CITY[city].au;if(cnCity(city)&&!cnOk()){toast(tr('<b>You need a license first.</b><br>Foreign networks need a joint venture to build in mainland China.'),'bad');sfx('err');return;}if(!spend(popCost(city)))return;S.pops[city]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};floater(CITY[city].x,CITY[city].y-30,tr('New POP!'),'#FF4F9A');if(flipNote)toast(pick([tr('<b>Router installed in {city}.</b><br>Upside down, as is customary down here. The packets don’t seem to mind.',{city:CITY[city].name}),tr('<b>Router installed in {city}.</b><br>The vendor shipped it the right way up, so the local techs turned it over. Everything else here is upside down too.',{city:CITY[city].name})]),'good',[],{a:'city',v:city});UI.tab='cust';after();},
|
||||||
|
launchBB:({city})=>{const p=S.pops[city];if(!p||p.bb)return;const C=CITY[city];if(!spend(bbCost(city)))return;p.bb={d:bbStart(city)};floater(C.x,C.y-30,tr('Eyeballs online!'),'#16A866');after();},
|
||||||
|
ad:({city})=>{const p=S.pops[city];if(!p||!p.bb)return;if(!spend(8000))return;p.boost=S.day+30;floater(CITY[city].x,CITY[city].y-30,tr('Ad campaign!'),'#FF8A3D');after();},
|
||||||
|
buyTransit:({city,net,tier})=>{tier=+tier;if(scnRule('noTransit')){toast(tr('<b>No transit in this scenario.</b><br>Peering, PNIs, caches and your own fiber only.'),'bad');sfx('err');return;}if(!S.pops[city]||!NET[net]||!sellsAt(NET[net],city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr("<b>Your router can't take a {port} port.</b><br>Upgrade it in the Infra tab.",{port:PORT[tier].n}),'bad');sfx('err');return;}const ex=S.transit.find(t=>t.city===city&&t.net===net);if(ex&&tier<=ex.tier)return;if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(PORT[tier].setup*(ex&&ex.n||1)))return;if(ex)ex.tier=tier;else S.transit.push({id:uid(),city,net,tier,down:0});toast(tr('<b>{net} transit is live in {city}.</b><br>Full table received: ~1,000,000 routes.',{net:esc(NET[net].name),city:CITY[city].name}),'good');after();},
|
||||||
|
lagT:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const t=S.transit.find(x=>x.id===id);if(!t)return;const n=(t.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0){if(!portOk(t.city,t.tier)||!portGate(t.city,PORT_SLOT(t.tier)))return;if(!spend(PORT[t.tier].setup))return;}t.n=n;if(n<2&&t.site==='ab')t.site='a';toast(+d>0?tr('<b>LAG member added.</b><br>{net} in {city} is now {lag}.',{net:esc(NET[t.net].name),city:CITY[t.city].name,lag:lagName(t.tier,n)}):tr(`<b>LAG member removed.</b>`),'good');after();},
|
||||||
|
lagP:({id,d})=>{d=+d;if(d!==1&&d!==-1)return;const p=S.pni.find(x=>x.id===id);if(!p)return;const n=(p.n||1)+(+d);if(n<1||n>LAG_MAX)return;if(d>0&&(!pniOn(p)||p.up||msfNope(p.net,p.city)))return;if(+d>0&&(!portGate(p.city,PORT_SLOT(p.tier))||!spend(1500+PORT[p.tier].setup/2)))return;
|
||||||
|
// A LAG member is an augment: the big networks take months for that too.
|
||||||
|
if(d>0){const lead=pniLead(p.net);p.up={tier:p.tier,n,ready:S.day+lead,g1:!!p.g1};toast(tr('<b>Augment ordered with {net}.</b><br>{eta}.',{net:esc(NET[p.net].name),eta:pniWhen(lead)}),'good');after();return;}p.n=n;if(n<2&&p.site==='ab')p.site='a';sfx('build');after();},
|
||||||
|
lagIx:({city,d})=>{d=+d;if(d!==1&&d!==-1)return;if(!isIx(city)||S.ixp[city]===undefined||S.myIx[city]||!S.pops[ixCity(city)])return;S.ixn=S.ixn||{};const n=(S.ixn[city]||1)+(+d);if(n<1||n>LAG_MAX)return;if(+d>0&&(!portGate(ixCity(city),PORT_SLOT(S.ixp[city]))||!spend(ixPortMo(city,S.ixp[city]))))return;S.ixn[city]=n;if(n<2&&S.ixSite&&S.ixSite[city]==='ab')S.ixSite[city]='a';sfx('build');after();},
|
||||||
|
cancelTransit:({id,ok})=>{if(!ok&&UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.transit=S.transit.filter(t=>t.id!==id);UI.confirm=null;after();},
|
||||||
|
buyIx:({city,tier,signed})=>{tier=+tier;if(!PORT[tier]||!ixName(city)||(!S.pops[ixCity(city)]&&(!remoteCities().includes(ixCity(city))||tier>1))||(S.ixp[city]!==undefined&&tier<=S.ixp[city]))return;if(S.pops[ixCity(city)]&&!portOk(ixCity(city),tier)){toast(tr("<b>Your router can't take a {port} port.</b><br>Upgrade it in the Infra tab.",{port:PORT[tier].n}),'bad');sfx('err');return;}{const h0=S.ixp[city]!==undefined;if(!S.myIx[city]&&!portGate(ixCity(city),h0?(PORT_SLOT(tier)-PORT_SLOT(S.ixp[city]))*((S.ixn||{})[city]||1):PORT_SLOT(tier)))return;}
|
||||||
|
if(isDk(city)&&S.ixp[city]===undefined&&!signed){const dk=dkState();if(dk.stall>S.day){toast(tr('<b>DE-KICKS sales is still "aligning".</b><br>They will get back to you in {n} days.',{n:dk.stall-S.day}),'bad');sfx('err');return;}dk.lastQ=dk.lastQ||{};const lq=dk.lastQ[city];dk.q={city,tier,m:lq&&lq.until>S.day?lq.m:dkQuoteMult(),h:lq&&lq.until>S.day?lq.h:0};dk.lastQ[city]={m:dk.q.m,h:dk.q.h,until:S.day+90};dkQuoteModal();return;}const had=S.ixp[city]!==undefined;if(!spend(ixPortMo(city,tier)*(had?((S.ixn||{})[city]||1):1)))return;S.ixp[city]=tier;if(!had)toast(S.pops[ixCity(city)]?tr('<b>Port up at {ix}!</b><br>Now request peering, or join the route server.',{ix:esc(ixName(city))}):tr("<b>Remote port up at {ix}.</b><br>It came through a reseller, so expect a markup, a crowded port and some networks that won't talk to you. The route server is your friend here.",{ix:esc(ixName(city))}),'good',[],{a:'city',v:ixCity(city)});after();},
|
||||||
|
cancelIx:({city,sure,ok})=>{if(!ok&&UI.confirm!=='ix'+city){UI.confirm='ix'+city;renderPanel();return;}
|
||||||
|
if(isDk(city)&&!sure){const dk=dkState();if(!dk.retUsed[city]){openModal(`<div class="eyebrow">${tr('DE-KICKS Group · Customer Success')}</div><h2 style="font-size:26px">${tr('Wait! Before you go…')}</h2><p class="tagline">${tr('We value our partnership too much to let a little thing like price get in the way.')}</p><div class="kv"><span>${tr('Retention offer')}</span><b>${tr('40% off for 6 months')}</b></div><p class="note">${tr('After that, the normal price returns, plus a small loyalty administration fee.')}</p><div class="btns">${btn(tr('Stay, take the discount'),'dkStay',{city},'pink')}${btn(tr('Leave anyway'),'cancelIx',{city,sure:1},'ghost')}</div>`);return;}}
|
||||||
|
closeModal();if(S.dk){if(S.dk.m[city]){S.dk.lastQ=S.dk.lastQ||{};S.dk.lastQ[city]={m:S.dk.m[city],h:3,until:S.day+365};}delete S.dk.m[city];delete S.dk.add[city];delete S.dk.ret[city];}delete S.ixp[city];delete S.rs[city];if(S.ixn)delete S.ixn[city];for(const k in S.peers)if(k.endsWith('@'+city))delete S.peers[k];UI.confirm=null;after();},
|
||||||
|
rs:({city})=>{if(!isIx(city)||S.ixp[city]===undefined)return;S.rs[city]=!S.rs[city];if(S.rs[city])toast(tr('<b>Route server session up.</b><br>You now peer with every open network on this IX, in one go.'),'good');sfx('build');after();},
|
||||||
|
dkAccept:()=>{const dk=dkState(),q=dk.q;if(!q)return;dk.m[q.city]=q.m;dk.q=null;closeModal();ACT.buyIx({city:q.city,tier:q.tier,signed:true});if(S.ixp[q.city]===undefined)delete dk.m[q.city];else toast(tr(`<b>Signed with DE-KICKS.</b><br>Welcome to the family. Please don't tell anyone what you pay.`),'good');},
|
||||||
|
dkHaggle:()=>{const dk=dkState(),q=dk.q;if(!q||q.h>=3)return;q.h++;const r=Math.random();
|
||||||
|
if(r<0.45){S.stats.haggleWin=1;q.m=+(q.m*(0.75+Math.random()*0.15)).toFixed(2);dkQuoteModal();toast(tr('<b>"Just this once."</b><br>Your account manager found a special discount. Do not tell the others.'),'good');}
|
||||||
|
else if(r<0.75){q.m=+(q.m*1.1).toFixed(2);dkQuoteModal();toast(tr('<b>"After consulting with management…"</b><br>The price went up. Management was consulted.'),'bad');}
|
||||||
|
else{dk.stall=S.day+5+Math.floor(Math.random()*6);dk.q=null;closeModal();toast(tr('<b>Haggling paused.</b><br>{why}',{why:esc(pick(DK_STALL))}),'bad');}},
|
||||||
|
dkWalk:()=>{const dk=dkState(),q=dk.q;if(q){dk.lastQ=dk.lastQ||{};dk.lastQ[q.city]={m:q.m,h:q.h,until:S.day+90};if(q.h>0)dk.stall=Math.max(dk.stall||0,S.day+3);}dk.q=null;closeModal();toast(tr('<b>DE-KICKS will "circle back".</b><br>Expect an email titled "Quick question 🙂" within the hour.'),'');},
|
||||||
|
dkOptOut:({city,n})=>{const dk=dkState(),k='dk'+city+n;if(UI.confirm!==k){UI.confirm=k;renderPanel();return;}dk.add[city]=(dk.add[city]||[]).filter(x=>x.n!==n);UI.confirm=null;S.stats.optouts=(S.stats.optouts||0)+1;toast(tr(`<b>Opted out of {name}.</b><br>It took four clicks, a survey and a "we're sad to see you go" page.`,{name:esc(n)}),'good');after();},
|
||||||
|
dkStay:({city})=>{S.stats.retained=1;const dk=dkState();dk.ret[city]=S.day+180;dk.retUsed[city]=true;UI.confirm=null;closeModal();toast(tr('<b>40% off {ix} for 6 months.</b><br>Your account manager is relieved. Read the small print later.',{ix:esc(ixName(city))}),'good');after();},
|
||||||
|
});
|
||||||
27
src/game/90-actions/30-route-script-and-tools.js
Normal file
27
src/game/90-actions/30-route-script-and-tools.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
teEdit:()=>{if(!S.te)return;UI.teDraft=undefined;teModal();},
|
||||||
|
teClose:()=>{const t=$('teSrc');if(t)UI.teDraft=t.value;closeModal();},
|
||||||
|
teOpt:()=>{UI.teDraft=teOptimize();teModal();},
|
||||||
|
teExample:()=>{UI.teDraft=TE_EXAMPLE;teModal();},
|
||||||
|
teSlop:()=>{const t0=performance.now(),a=aiSlop(Math.random()<0.02),secs=Math.max(0.1,(performance.now()-t0)/1000);UI.teDraft=UI.slop=a.src;teModal(`<p class="note aisay">🤖 <b>${esc(a.ai)}</b> <small>${tr('thought for {s} seconds',{s:secs.toFixed(1)})}</small><br>${tr(a.say)}</p>`);sfx('build');},
|
||||||
|
teHelp:()=>{const t=$('teSrc');if(t)UI.teDraft=t.value;teHelpModal();},
|
||||||
|
teBack:()=>teModal(),
|
||||||
|
teRecipe:({id})=>{const r=TE_RECIPES.find(x=>x.id===id);if(!r)return;UI.teDraft=r.src().join('\n');teModal(`<p class="note">${tr('Loaded {name}. Check it, then deploy.',{name:tr(r.n)})}</p>`);},
|
||||||
|
teClear:()=>{S.te.script='';UI.teDraft=undefined;TE_CACHE={src:null,p:null};after();teModal(`<p class="note">${tr('Script removed. Plain Auto-TE is back in charge.')}</p>`);},
|
||||||
|
teCheck:()=>{const t=$('teSrc');const src=t?t.value:'';UI.teDraft=src;const p=teParse(src);if(p.errors.length){teModal(`<pre class="term err">${esc(p.errors.join('\n'))}</pre>`);return;}const r=teTrial(src);teModal(`<pre class="term">${esc(trn('✓ {n} rule OK','✓ {n} rules OK',p.n)+'\n'+tr('served {a} → {b}',{a:fmtG(r.before.served),b:fmtG(r.after.served)})+'\n'+tr('transit {a}/mo → {b}/mo',{a:fmt$(r.before.tc),b:fmt$(r.after.tc)})+'\n'+tr('spilled {g} onto alternate paths',{g:fmtG(r.after.moved)})+(r.after.bh?'\n'+tr('blackholed {g}',{g:fmtG(r.after.bh)}):''))}</pre>`);},
|
||||||
|
teDeploy:()=>{const t=$('teSrc');const src=(t?t.value:'').slice(0,4000);UI.teDraft=src;const p=teParse(src);if(p.errors.length){teModal(`<pre class="term err">${esc(tr('commit failed')+'\n'+p.errors.join('\n'))}</pre>`);sfx('err');return;}const r=teTrial(src);S.te.script=src;S.te.on=true;TE_CACHE={src:null,p:null};UI.teDraft=undefined;after();
|
||||||
|
const drop=r.before.served>1?1-r.after.served/r.before.served:0,saved=r.before.tc>0?1-r.after.tc/r.before.tc:0;
|
||||||
|
if(drop>0.1&&UI.slop===src){if(drop>0.3)S.stats.fat=1;toast(tr('<b>Commit complete. Traffic down {p}.</b><br>The AI apologises for the confusion, and remains completely sure the script was right. Fix it from the NOC tab.',{p:pct(drop)}),'bad');sfx('alert');}
|
||||||
|
else if(drop>0.3){S.stats.fat=1;toast(tr('<b>Commit complete. Traffic down {p}.</b><br>You just fat-fingered your own network. Classic. Fix the script from the NOC tab.',{p:pct(drop)}),'bad');sfx('alert');}
|
||||||
|
else{if(saved>0.1&&drop<0.01)S.stats.kiddie=1;toast(`<b>${tr('Commit complete.')}</b><br>${saved>0.01?trn('{n} rule live, transit bill down {p}.','{n} rules live, transit bill down {p}.',p.n,{p:pct(saved)}):trn('{n} rule live.','{n} rules live.',p.n)}`,'good');sfx('build');}closeModal();UI.slop=undefined;checkGoals();},
|
||||||
|
buyTE:()=>{if(S.te)return;if(lvl()<3){toast(tr('<b>Auto-TE unlocks at customer level 3.</b>'),'bad');sfx('err');return;}if(!spend(TE_COST))return;S.te={on:true,day:S.day};toast(tr('<b>Auto-TE is live.</b><br>The controller now pushes overflow onto alternate paths whenever the shortest one is full.'),'good');after();},
|
||||||
|
teToggle:()=>{if(!S.te)return;S.te.on=!S.te.on;after();},
|
||||||
|
trace:({city})=>traceModal(city),
|
||||||
|
traceRun:()=>{const f=$('trFrom'),t=$('trTo');traceModal(f&&f.value,t&&t.value);},
|
||||||
|
traceCopy:()=>{try{navigator.clipboard.writeText(UI.trText||'');toast(tr('<b>Copied.</b> Paste it into your favourite NOC chat.'),'good');}catch(e){}},
|
||||||
|
share:()=>shareModal(),
|
||||||
|
shareDl:()=>shareFile(f=>{if(!f)return;const a=document.createElement('a');a.href=URL.createObjectURL(f);a.download=f.name;document.body.appendChild(a);a.click();setTimeout(()=>{URL.revokeObjectURL(a.href);a.remove();},1000);track('share_download');}),
|
||||||
|
shareGo:()=>shareFile(f=>{const d={title:'Series of Tubes',text:tr('{name} (AS{asn}): {tier}, {peak} peak. Build your own internet at',{name:S.name,asn:S.asn,tier:tierLabel(),peak:fmtG(S.stats.peak||0)}),url:'https://seriesoftub.es/'};try{if(f&&navigator.canShare&&navigator.canShare({files:[f]}))d.files=[f];navigator.share(d).then(()=>track('share_done')).catch(()=>{});}catch(e){}}),
|
||||||
|
confGo:({key})=>{S.confReg=S.confReg||{};if(S.confReg[key])return;const cf=upcomingConfs(75).find(x=>x.key===key);if(!cf||cf.day<=S.day)return;if(!spend(CONF_COST))return;S.confReg[key]=true;toast(tr('<b>Registered.</b><br>Flights booked, badge printed, business cards ordered in the wrong font.'),'good');after();},
|
||||||
|
tutSkip:()=>{S.tut=null;try{localStorage.setItem('sot-tut','1');}catch(e){}renderCoach();},
|
||||||
|
});
|
||||||
35
src/game/90-actions/40-sites-peering-caches.js
Normal file
35
src/game/90-actions/40-sites-peering-caches.js
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
addSite:({city})=>{const p=S.pops[city];if(!p||p.site2)return;if(!spend(SITE2_COST))return;p.site2=true;p.site2Day=S.day;toast(tr('<b>Second site live in {city}.</b><br>{b} is joined to {a} by your own metro ring. Move some uplinks there from the Transit and Peering tabs.',{city:CITY[city].name,b:esc(siteName(city,'b')),a:esc(siteName(city,'a'))}),'good');sfx('build');after();},
|
||||||
|
rmSite:({city})=>{const p=S.pops[city];if(!p||!p.site2)return;if(UI.confirm!=='site'+city){UI.confirm='site'+city;renderPanel();return;}UI.confirm=null;p.site2=0;p.sdown=null;p.ringcut=0;for(const t of S.transit)if(t.city===city)t.site='a';for(const x of S.pni)if(x.city===city)x.site='a';for(const x of S.caches)if(x.city===city)x.site='a';if(S.ixSite)for(const x of ixIdsIn(city))delete S.ixSite[x];after();},
|
||||||
|
siteSet:({k,id,s})=>{if(!['a','b','ab'].includes(s))return;
|
||||||
|
const o=k==='t'?S.transit.find(x=>x.id===id):k==='p'?S.pni.find(x=>x.id===id):null;if(k!=='ix'&&!o)return;if(k==='ix'&&(!isIx(id)||S.ixp[id]===undefined||!S.pops[ixCity(id)]))return;
|
||||||
|
if(k==='ix'&&S.myIx[id]){S.ixSite=S.ixSite||{};S.ixSite[id]=s;after();return;}
|
||||||
|
const n=()=>k==='ix'?((S.ixn||{})[id]||1):(o.n||1);
|
||||||
|
if(s==='ab'&&n()<2){const before=n();if(k==='t')ACT.lagT({id,d:1});else if(k==='p')ACT.lagP({id,d:1});else ACT.lagIx({city:id,d:1});if(n()<2||n()===before)return;toast(tr(`<b>Second LAG member added.</b><br>One member in each building now, so a dark building only takes out half the port.`),'good');}
|
||||||
|
if(k==='ix'){S.ixSite=S.ixSite||{};S.ixSite[id]=s;}else o.site=s;after();},
|
||||||
|
peer:({city,net})=>{if(!isIx(city)||!isNet(net)||S.ixp[city]===undefined||!ixMembers(city).includes(net))return;const r=peerOk(net,'ix',city);if(!r.ok){toast(tr('<b>{net} declined.</b><br>{why}',{net:esc(NET[net].name),why:esc(r.why)}),'bad');sfx('err');return;}S.peers[net+'@'+city]=true;
|
||||||
|
toast(`<b>${tr('{net} accepted!',{net:esc(NET[net].name)})}</b><br>${NET[net].pol==='selective'?tr('They checked your PearingDB page and liked the traffic numbers.'):tr('BGP session established.')}`,'good');sfx('build');after();},
|
||||||
|
unpeer:({city,net})=>{delete S.peers[net+'@'+city];after();},
|
||||||
|
peerAll:({city})=>{if(!isIx(city)||S.ixp[city]===undefined)return;const set=ixSessions(city);let n=0;for(const id of ixMembers(city))if(!set.has(id)&&peerOk(id,'ix',city).ok){S.peers[id+'@'+city]=true;n++;}if(!n)return;toast(trn('<b>{n} new session at {ix}.</b><br>Small networks, but they add up, and they all count towards the club.','<b>{n} new sessions at {ix}.</b><br>Small networks, but they add up, and they all count towards the club.',n,{ix:esc(ixName(city))}),'good',[],{a:'city',v:ixCity(city)});sfx('build');after();},
|
||||||
|
tailTog:()=>{UI.tailOpen=!UI.tailOpen;renderLeft();},
|
||||||
|
pni:({city,net,tier})=>{tier=+tier;const g1=tier===-1;if(g1){if(!pniG1(net))return;tier=0;}if(!S.pops[city]||!NET[net]||!NET[net].pops.includes(city)||!PORT[tier])return;if(!portOk(city,tier)){toast(tr("<b>Your router can't take a {port} port.</b><br>Upgrade it in the Infra tab.",{port:PORT[tier].n}),'bad');sfx('err');return;}const r=peerOk(net,'pni',city);if(!r.ok){toast(tr('<b>{net} declined the PNI.</b><br>{why}',{net:esc(NET[net].name),why:esc(r.why)}),'bad');sfx('err');after();return;}
|
||||||
|
if(!g1&&tier<pniMin(net)){toast(tr('<b>{net} does not do {port} PNIs.</b><br>Nothing smaller than 100G. Come back with more traffic, or a bigger optic.',{net:esc(NET[net].name),port:PORT[tier].n}),'bad');sfx('err');return;}
|
||||||
|
const ex=S.pni.find(p=>p.city===city&&p.net===net);if(ex&&(g1||!pniOn(ex)||ex.up))return;if(ex&&!(ex.g1&&tier===0)&&tier<=ex.tier)return;
|
||||||
|
const cost=g1?PNI_G1_COST:(1500+PORT[tier].setup/2)*(ex&&ex.n||1);if(!portGate(city,ex?(PORT_SLOT(tier)-PORT_SLOT(ex.tier))*(ex.n||1):PORT_SLOT(tier)))return;if(!spend(cost))return;if(S.conf&&S.conf.until>S.day)S.stats.beerPni=1;
|
||||||
|
// Nothing is instant: a cross-connect takes weeks, and the big networks quote months for a new PNI or an augment.
|
||||||
|
const lead=pniLead(net);if(ex)ex.up={tier,n:ex.n||1,ready:S.day+lead,g1:false};else S.pni.push({id:uid(),city,net,tier,g1:g1||undefined,ready:S.day+lead});
|
||||||
|
toast(tr('<b>PNI with {net} ordered.</b><br>{eta}. A cross-connect in {dc}, once somebody finds the LOA.',{net:esc(NET[net].name),eta:pniWhen(lead),dc:esc(siteName(city,'a'))}),'good');after();},
|
||||||
|
pniChase:({id})=>{const p=S.pni.find(x=>x.id===id);if(!p||(pniOn(p)&&!p.up))return;const r=Math.random();
|
||||||
|
if(r<0.15){if(p.up)p.up.ready=Math.max(S.day+1,p.up.ready-30);else p.ready=Math.max(S.day+1,p.ready-30);toast(tr('<b>Your account manager found the order under a desk.</b><br>It is a month closer.'),'good');}
|
||||||
|
else toast(pick([tr('<b>“It is with the provisioning team.”</b><br>Nobody has ever met the provisioning team.'),tr('<b>“We are waiting on the colo for the cross-connect.”</b><br>The colo says it is waiting on them.'),tr('<b>Your ticket was merged into another ticket.</b><br>That ticket was closed as a duplicate of yours.'),tr('<b>“Could you resend the LOA?”</b><br>You have sent it four times.'),tr('<b>Your account manager is on paternity leave.</b><br>His replacement is also on paternity leave.')]));after();},
|
||||||
|
inbox:()=>{inboxModal();},
|
||||||
|
inboxAct:({id,a})=>{if(!['accept','decline','raise','keep'].includes(a))return;ibxAnswer(+id,a);after();inboxModal();},
|
||||||
|
inboxAll:({a})=>{if(a!=='accept'&&a!=='decline')return;const I=ibx();for(const x of I.items.filter(x=>x.k==='req'))ibxAnswer(x.id,a,true);after();inboxModal();},
|
||||||
|
inboxBot:({on})=>{const I=ibx();if(+on){if(I.bot||!spend(AI_MO))return;I.bot=true;ibxLog(N_('Hello! I am Large Peering Model. I have read your inbox and I already have opinions.'),{});toast(tr('<b>Large Peering Model is hired.</b><br>Your inbox is its problem now. {price} a year, billed monthly.',{price:fmt$(20e6)}),'good');}else{I.bot=false;toast(tr('<b>The AI is gone.</b><br>It left a 40-page handover document. It is mostly about itself.'));}after();inboxModal();},
|
||||||
|
cancelPni:({id,ok})=>{if(!ok&&UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.pni=S.pni.filter(p=>p.id!==id);UI.confirm=null;after();},
|
||||||
|
cache:({city,net})=>{const n=NET[net];if(!n||!n.cache||!S.pops[city])return;if((R.demTo[net]||0)<n.cache.min){toast(tr('<b>{net} says not yet.</b><br>Send them {min}+ Gbps first.',{net:esc(n.name),min:n.cache.min}),'bad');sfx('err');return;}if(!portGate(city,1))return;
|
||||||
|
{const hv=S.caches.filter(x=>x.city===city&&x.net===net),nb=hv.filter(x=>x.site==='b').length;S.caches.push({id:uid(),city,net,site:S.pops[city].site2&&nb<hv.length-nb?'b':'a'});}toast(tr('<b>{cache} installed in {city}!</b><br>{net} shipped it for free. You pay {mo}/mo power.',{cache:esc(n.cache.name),city:CITY[city].name,net:esc(n.name),mo:fmt$(CACHE_MO)}),'good');sfx('build');after();},
|
||||||
|
rmCache:({id})=>{S.caches=S.caches.filter(c=>c.id!==id);after();},
|
||||||
|
// Move one of a CDN's boxes to the other building (#69), so a dark building only takes out part of the cache.
|
||||||
|
cacheSite:({city,net,s})=>{if(s!=='a'&&s!=='b'||!S.pops[city]||!S.pops[city].site2)return;const x=S.caches.find(c=>c.city===city&&c.net===net&&(c.site==='b'?'b':'a')!==s);if(!x)return;x.site=s;sfx('click');after();},
|
||||||
|
});
|
||||||
19
src/game/90-actions/50-customers.js
Normal file
19
src/game/90-actions/50-customers.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
advertise:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||l.ready>S.day)return;if(S.offers.some(o=>o.link===l.id))return;
|
||||||
|
const t=freeCh(l)>=1?'wwave':pairFree(l)?'dfpair':null;if(!t){toast(tr('<b>Nothing spare to sell on this fiber.</b><br>Every channel is lit or sold, and the trench has no free pair.'),'bad');sfx('err');return;}
|
||||||
|
const T=BIZ_T[t],nm=()=>{const list=T.names.filter(n=>!S.usedNames.includes(n)),n=list.length?pick(list):pick(T.names);S.usedNames.push(n);return n;};
|
||||||
|
// A capacity broker finds a buyer at once and keeps 10% of the monthly price.
|
||||||
|
const o=fiberOffer(t,l,nm,0.9);o.broker=true;S.offers.push(o);toast(tr('<b>Listed with a capacity broker.</b><br>{name} wants {what}. Accept it on the fiber or in Deals.',{name:esc(o.name),what:esc(o.what)}),'good');sfx('click');after();},
|
||||||
|
accept:({id})=>{const o=S.offers.find(x=>x.id===id);if(!o)return;if(!bHas(o)){toast(tr('<b>You need a POP in every city on the contract first.</b>'),'bad');return;}
|
||||||
|
if(o.type==='wwave'){const l=S.links.find(x=>x.id===o.link);if(!l||chMax(l)-(l.ch||[]).length-soldSlots(l)<o.slots){toast(tr('<b>Not enough free channels on that fiber any more.</b>'),'bad');return;}}
|
||||||
|
if(BIZ_T[o.type].event&&S.day>=o.start){toast(tr('<b>Too late: the event has already started.</b>'),'bad');return;}
|
||||||
|
// A carrier renting more alien waves on a fiber it already rents grows its contract, like a real order for extra waves,
|
||||||
|
// instead of a new customer for every few waves (a big fiber business otherwise fills the save with tiny contracts).
|
||||||
|
const more=o.type==='wwave'&&S.biz.find(b=>b.type==='wwave'&&b.link===o.link&&b.name===o.name);
|
||||||
|
if(more){const l=S.links.find(x=>x.id===o.link);S.offers=S.offers.filter(x=>x!==o);more.slots=(more.slots||0)+(o.slots||0);more.rate+=o.rate;if(l)more.what=wwWhat(l,more.slots);
|
||||||
|
floater(CITY[o.city].x,CITY[o.city].y-30,tr('Signed!'),'#16A866');sfx('coin');after();return;}
|
||||||
|
S.offers=S.offers.filter(x=>x!==o);S.biz.push({id:o.id,city:o.city,city2:o.city2||null,reqs:o.reqs||[],latMax:o.latMax||null,route:BIZ_T[o.type].scenic?'scenic':BIZ_T[o.type].lat?'fast':'normal',name:o.name,type:o.type,bw:o.bw,rate:o.rate,mood:100,since:S.day,sites:o.sites||null,start:o.start,dur:o.dur,fee:o.fee,link:o.link,slots:o.slots||0,what:o.what,prov:o.prov});
|
||||||
|
floater(CITY[o.city].x,CITY[o.city].y-30,tr('Signed!'),'#16A866');sfx('coin');after();},
|
||||||
|
decline:({id})=>{S.offers=S.offers.filter(x=>x.id!==id);after();},
|
||||||
|
dropBiz:({id})=>{const b0=S.biz.find(x=>x.id===id);if(!b0)return;if(BIZ_T[b0.type].event&&S.day>=b0.start){toast(tr('<b>The event is already running.</b><br>The organisers will not let you walk out now.'),'bad');sfx('err');return;}if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.biz=S.biz.filter(b=>b.id!==id);UI.confirm=null;after();},
|
||||||
|
});
|
||||||
33
src/game/90-actions/60-links.js
Normal file
33
src/game/90-actions/60-links.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
upLink:({id,tier})=>{tier=+tier;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='wave'||!LT[tier]||tier<=l.tier)return;{const w=subWaveWhy(tier,l.km,l.sub);if(w){toast(tr('<b>No {wave} waves on this cable.</b><br>{why}',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}if(!waveOk(l.a,l.b,tier)){toast(tr('<b>A {wave} wave needs {need} at both ends.</b>',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;}const nm=Math.round(waveMo(l.km,l.sub,tier)*(l.mult||1));if(!spend(nm))return;l.mo=nm;l.tier=tier;after();},
|
||||||
|
decomOpen:({city})=>{UI.decom=new Set(city&&S.pops[city]?[city]:[]);decomModal();},
|
||||||
|
decomToggle:({city})=>{if(!S.pops[city])return;UI.decom=UI.decom||new Set();if(UI.decom.has(city))UI.decom.delete(city);else UI.decom.add(city);decomModal();},
|
||||||
|
decomGo:()=>{const sel=[...(UI.decom||[])].filter(c=>S.pops[c]);if(!sel.length||sel.length>=Object.keys(S.pops).length)return;closeModal();UI.decom=null;UI.sel=null;decommission(sel);sfx('alert');after();},
|
||||||
|
rmLink:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}{const l=S.links.find(x=>x.id===id),back=cabBack(l);if(back>0){S.cash+=back;toast(tr('<b>{name} is called off.</b><br>The cable factory takes back the glass nobody needs: {price} back.',{name:esc(l.cname||tr('Your cable')),price:fmt$(back)}),'good');}}S.links=S.links.filter(l=>l.id!==id);UI.sel=null;UI.confirm=null;after();},
|
||||||
|
fixInc:({id})=>{const i=S.inc.find(x=>x.id===id);if(!i||!(i.cost>0))return;if(i.slow&&i.rushed)return;if(!spend(i.cost))return;
|
||||||
|
if(i.slow&&i.until>S.day+1){i.rushed=true;i.cost=0;i.until=S.day+1;const p=S.pops[i.ref];if(p)p.down=Math.min(p.down,S.day+1);toast(tr('<b>Power-cycled.</b><br>The router in {city} is booting again. It will be up tomorrow, the {chip} willing.',{city:esc(CITY[i.ref].name),chip:esc(RG[(p&&p.rgen)||0].chip)}),'good');after();return;}clearInc(i);toast(tr('<b>Fixed.</b> {what} resolved early.',{what:incTitle(i.type)}),'good');after();},
|
||||||
|
myIxUp:({city})=>{const m=S.myIx[city];if(!m)return;const f=(m.fab|0)+1,N=MYIX_FAB[f];if(!N)return;if(N.lvl>lvl()){toast(tr('<b>A {fab} fabric unlocks at customer level {lv}.</b>',{fab:N.n,lv:N.lvl}),'bad');sfx('err');return;}if(!spend(N.cost))return;m.fab=f;toast(tr('<b>{ix} now runs a {fab} fabric.</b><br>Room for {max} members. Expect a few more to join.',{ix:esc(m.name),fab:N.n,max:N.max}),'good');m.next=Math.min(m.next,S.day+3);after();},
|
||||||
|
foundIx:({city})=>{if(!S.pops[city]||S.myIx[city]||CITY[city].ix||CITY[city].cn)return;if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name;
|
||||||
|
S.myIx[city]={name:nm,members:[],next:S.day+4};S.ixp[city]=2;toast(tr('<b>You founded {ix}!</b><br>Networks will join over time and pay you for ports. Open members peer with you for free.',{ix:esc(nm)}),'goal');after();},
|
||||||
|
buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p)return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),jn=sib.length?routeJoin(a,b):null,same=!!jn,border=cnCity(a)!==cnCity(b),mult=(sib.length&&!(jn&&jn.k===(landTrenches(a,b)[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1);
|
||||||
|
if((cnCity(a)||cnCity(b))&&!cnOk())return;
|
||||||
|
if(!waveOk(a,b,tier)){toast(tr('<b>A {wave} wave needs {need} at both ends.</b>',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;}
|
||||||
|
const wr=waveRoute(a,b,mult,border);if(!wr){toast(tr('<b>No cable available for that route right now.</b>'),'bad');sfx('err');return;}
|
||||||
|
{const so=soldOut(a,b,tier,wr.cab);if(so){toast(tr('<b>No {wave} capacity on this route right now.</b><br>{why} Try a smaller wave, another route, or ask again in {n} days.',{wave:LT[tier].n,why:tr(so.why),n:Math.max(1,so.until-S.day)}),'bad');sfx('err');return;}}{const w=subWaveWhy(tier,wr.km,wr.sub);if(w){toast(tr('<b>No {wave} waves on this cable.</b><br>{why}',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}const base=Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),cost=base+(S.pops[b]?0:popCost(b));
|
||||||
|
if(!portGate(a,1)||!portGate(b,1))return;if(!spend(cost))return;if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false};
|
||||||
|
const id=uid();const l={id,a,b,kind:'wave',border,premium:border&&!!UI.cnPrem&&(a==='hkg'||b==='hkg'),tier,km:wr.km,sub:wr.sub,cable:wr.cab,mo:base,mult:wr.wm,trench:wr.cab?'cab:'+wr.cab:(jn?jn.k:id),cut:0,day:S.day};S.links.push(l);closeModal();
|
||||||
|
if(sib.length){UI.sel={type:'link',id};}else{UI.sel={type:'city',id:b};UI.tab='cust';}
|
||||||
|
floater((CITY[a].x+CITY[a].x+wrapDx(CITY[a].x,CITY[b].x))/2,(CITY[a].y+CITY[b].y)/2-20,tr('{wave} lit!',{wave:LT[tier].n}),'#FF4F9A');after();},
|
||||||
|
buyNni:({city,prov,tier})=>{tier=+tier;if(!NNI[tier]||!isCity(city)||!own(FAB,prov)||!FAB[prov].cities.includes(city)||!S.pops[city])return;const ex=nniPort(city,prov);if(ex&&tier<=ex.tier)return;if(!ex&&!portGate(city,1))return;if(ex&&nniUsed(city,prov)>NNI[tier].g){toast(tr('<b>Too many circuits</b> for a smaller port.'),'bad');return;}if(!spend(NNI[tier].mo))return;if(ex)ex.tier=tier;else S.nni.push({id:uid(),city,prov,tier});toast(tr('<b>{fab} port is up in {city}.</b><br>Now order virtual circuits to other cities on their fabric.',{fab:esc(FAB[prov].name),city:CITY[city].name}),'good');after();},
|
||||||
|
rmNni:({city,prov})=>{if(nniUsed(city,prov)>0){toast(tr('<b>Cancel the circuits on this port first.</b>'),'bad');sfx('err');return;}S.nni=S.nni.filter(x=>!(x.city===city&&x.prov===prov));after();},
|
||||||
|
openVxc:(a)=>openVxcModal(a),
|
||||||
|
buyVxc:({a,b,prov,t})=>{t=+t;const g=VXC[t].g,pa=nniPort(a,prov);if(!pa||nniUsed(a,prov)+g>NNI[pa.tier].g){toast(tr('<b>Not enough room on your fabric port.</b> Upgrade it first.'),'bad');sfx('err');return;}
|
||||||
|
if(S.pops[b]){const pb=nniPort(b,prov);if(!pb||nniUsed(b,prov)+g>NNI[pb.tier].g){toast(tr('<b>Not enough room on your {fab} port in {city}.</b>',{fab:esc(FAB[prov].name),city:CITY[b].name}),'bad');sfx('err');return;}}
|
||||||
|
const km=kmBetween(a,b),sub=isSub(a,b),mo=vxcMo(km,sub,t);if(!spend(mo))return;S.links.push({id:uid(),a,b,kind:'vxc',prov,vt:t,km,sub,mo,cut:0,day:S.day});closeModal();
|
||||||
|
toast(tr('<b>Circuit up in 59 seconds.</b><br>{vxc} over {fab}: {a} → {b}.',{vxc:VXC[t].n,fab:esc(FAB[prov].name),a:CITY[a].name,b:CITY[b].name})+(S.pops[b]?'':' '+tr('Now grab an IX port there for remote peering.')),'good');if(!S.pops[b])selectCity(b);after();},
|
||||||
|
upVxc:({id,t})=>{t=+t;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='vxc'||!VXC[t]||t<=l.vt)return;const extra=VXC[t].g-VXC[l.vt].g;for(const c of [l.a,l.b]){const pt=nniPort(c,l.prov);if(pt&&nniUsed(c,l.prov)+extra>NNI[pt.tier].g){toast(tr('<b>Fabric port in {city} is full.</b>',{city:CITY[c].name}),'bad');sfx('err');return;}}const mo=vxcMo(l.km,l.sub,t);if(!spend(mo))return;l.vt=t;l.mo=mo;after();},
|
||||||
|
cancelVxc:({id})=>{if(UI.confirm!==id){UI.confirm=id;renderPanel();return;}S.links=S.links.filter(l=>l.id!==id);const rem=remoteCities();for(const c in S.ixp){if(!S.pops[ixCity(c)]&&!rem.includes(ixCity(c))){delete S.ixp[c];delete S.rs[c];for(const k in S.peers)if(k.endsWith('@'+c))delete S.peers[k];}}UI.sel=null;UI.confirm=null;after();},
|
||||||
|
setPref:({kind,id,v})=>{if(!own(PREF,v))return;if(kind!=='t'&&kind!=='p'&&!(isIx(id)&&S.ixp[id]!==undefined))return;if(kind==='t'){const t=S.transit.find(x=>x.id===id);if(t)t.pref=v;}else if(kind==='p'){const x=S.pni.find(y=>y.id===id);if(x)x.pref=v;}else{S.ixPref=S.ixPref||{};S.ixPref[id]=v;}sfx('click');after();},
|
||||||
|
setMetric:({id,v})=>{if(!own(MET,v))return;const l=S.links.find(x=>x.id===id);if(!l)return;for(const x of pairLinks(l.a,l.b))x.metric=v;sfx('click');after();},
|
||||||
|
goEgress:({city,k})=>{ACT.focusCity({city});UI.tab=k==='t'?'up':k==='l2'?'cust':k==='nni'?'links':'peer';renderPanel();},
|
||||||
|
});
|
||||||
17
src/game/90-actions/70-dashboard-lists.js
Normal file
17
src/game/90-actions/70-dashboard-lists.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
custGo:({id})=>{const b=S.biz.find(x=>x.id===id);if(!b)return;$('dash').hidden=true;ACT.focusCity({city:b.city});UI.tab='cust';renderPanel();},
|
||||||
|
listMore:({k})=>{if(k!=='conn'&&k!=='cust')return;UI.listN=UI.listN||{};UI.listN[k]=listN(k)+LIST_PAGE;renderDash();},
|
||||||
|
custF:({v})=>{UI.kf=UI.kf||{};UI.kf.f=v==='sad'?'sad':'';listReset('cust');renderDash();},
|
||||||
|
custCity:({v})=>{UI.kf=UI.kf||{};UI.kf.city=isCity(v)?v:'';listReset('cust');renderDash();},
|
||||||
|
custSort:({k})=>{if(!['mood','mo','name','city'].includes(k))return;listReset('cust');if(UI.custSort===k)UI.custDir=-(UI.custDir||1);else{UI.custSort=k;UI.custDir=k==='mo'?-1:1;}renderDash();},
|
||||||
|
custOpen:({sad}={})=>{if(!S)return;UI.kf=sad?{f:'sad'}:{};listReset('cust');UI.dtab='cust';const d=$('dash');d.hidden=false;renderDash();d.scrollTop=0;},
|
||||||
|
goConn:({city,k})=>{if(!isCity(city)||!own(CONN_K,k))return;$('dash').hidden=true;ACT.goEgress({city,k});},
|
||||||
|
connF:({f,v})=>{const F=UI.cf=UI.cf||{};listReset('conn');if(f==='all'){UI.cf={};}else if(f==='k'){F.k=own(CONN_K,v)?v:'';}renderDash();},
|
||||||
|
connCity:({v})=>{UI.cf=UI.cf||{};listReset('conn');UI.cf.city=isCity(v)?v:'';renderDash();},
|
||||||
|
connNet:({v})=>{UI.cf=UI.cf||{};listReset('conn');UI.cf.net=NET[v]?v:'';renderDash();},
|
||||||
|
connSort:({k})=>{if(!['k','city','name','use','mo'].includes(k))return;listReset('conn');if(UI.connSort===k)UI.connDir=-(UI.connDir||1);else{UI.connSort=k;UI.connDir=k==='use'||k==='mo'?-1:1;}renderDash();},
|
||||||
|
connFor:({net})=>{if(!NET[net])return;UI.cf={net};ACT.connOpen();},
|
||||||
|
connCancel:({k,id})=>{const r=conns().find(x=>x.k===k&&x.id===id);if(!r||r.mine)return;const key='cc:'+k+':'+id;if(UI.confirm!==key){UI.confirm=key;renderDash();return;}UI.confirm=null;
|
||||||
|
if(k==='t')ACT.cancelTransit({id,ok:1});else if(k==='p')ACT.cancelPni({id,ok:1});else if(k==='ix')ACT.cancelIx({city:id,ok:1});else if(k==='c')ACT.rmCache({id});else{const [city,prov]=id.split('|');ACT.rmNni({city,prov});}renderDash();},
|
||||||
|
connOpen:()=>{if(!S)return;UI.dtab='conn';listReset('conn');const d=$('dash');d.hidden=false;renderDash();d.scrollTop=0;},
|
||||||
|
});
|
||||||
19
src/game/90-actions/80-security-and-china.js
Normal file
19
src/game/90-actions/80-security-and-china.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
applyCn:()=>{if(S.cnLic.state!=='none')return;if(!spend(CN_LIC))return;S.cnLic={state:'pending',ready:S.day+45};toast(tr('<b>Application filed.</b><br>Your local partner says about 45 days. Probably.'),'goal');after();},
|
||||||
|
togglePrem:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.premium=!t.premium;sfx('click');after();},
|
||||||
|
buildScrub:({city,tier})=>{if(!S.pops[city]||S.scrubs.some(x=>x.city===city))return;const T=SCRUB_TIERS[tier||0];if(!T)return;if((lvl()||1)<T.lvl){toast(tr('<b>{tier} scrubbing unlocks at customer level {lv}.</b>',{tier:T.n,lv:T.lvl}),'bad');sfx('err');return;}if(!spend(T.cost))return;if(!hasScrub())S.scrubMode='always';S.scrubs.push({city,tier:tier||0});toast(tr('<b>{tier} scrubbing center online in {city}.</b><br>Attacks up to {g} are cleaned, and you can sell DDoS protection.',{tier:T.n,city:CITY[city].name,g:fmtG(T.g)}),'good');after();},
|
||||||
|
scrubUp:({city,tier})=>{const x=S.scrubs.find(q=>q.city===city);tier=+tier;if(!x||!SCRUB_TIERS[tier]||tier<=(x.tier||0))return;const T=SCRUB_TIERS[tier];if((lvl()||1)<T.lvl){toast(tr('<b>{tier} scrubbing unlocks at customer level {lv}.</b>',{tier:T.n,lv:T.lvl}),'bad');sfx('err');return;}if(!spend(Math.round(T.cost*0.6)))return;x.tier=tier;toast(tr('<b>Scrubbing upgraded to {tier}.</b>',{tier:T.n}),'good');after();},
|
||||||
|
scrubMode:()=>{if(!hasScrub())return;S.scrubMode=S.scrubMode==='ondemand'?'always':'ondemand';sfx('click');after();},
|
||||||
|
rmScrub:({city})=>{if(!S.scrubs.some(x=>x.city===city))return;if(UI.confirm!=='scrub:'+city){UI.confirm='scrub:'+city;renderAll();return;}S.scrubs=S.scrubs.filter(x=>x.city!==city);if(!hasScrub())S.scrubMode='always';UI.confirm=null;after();},
|
||||||
|
cleanPipe:({id})=>{const t=S.transit.find(x=>x.id===id);if(!t)return;t.clean=!t.clean;toast(t.clean?tr('<b>Clean-pipe add-on enabled on {net}.</b><br>They scrub a flood before it reaches your port here, for {mo}/mo.',{net:NET[t.net].name,mo:fmt$(cleanMo(t))}):tr('<b>Clean-pipe add-on removed from {net}.</b>',{net:NET[t.net].name}),t.clean?'good':'');after();},
|
||||||
|
sacrif:({id})=>{const p=S.pni.find(x=>x.id===id);if(!p)return;p.sacrif=!p.sacrif;toast(p.sacrif?tr('<b>{net} PNI is now a sacrificial choke point.</b><br>A flood from there dies on the small port instead of inside your network, but legit traffic over it runs at half capacity.',{net:NET[p.net].name}):tr('<b>{net} PNI is back to normal.</b>',{net:NET[p.net].name}),p.sacrif?'good':'');after();},
|
||||||
|
ixbh:()=>{const a=S.ev.ddos;if(!a){toast(tr('<b>No attack to blackhole right now.</b>'),'');return;}if(!hasIxAt(a.city)){toast(tr('<b>No IX in {city} to announce a blackhole to.</b>',{city:CITY[a.city].name}),'bad');sfx('err');return;}a.ixbh=!a.ixbh;toast(a.ixbh?tr('<b>IX blackhole announced in {city}.</b><br>About half the members honour the /32 and drop the junk. The customer stays up.',{city:CITY[a.city].name}):tr('<b>IX blackhole withdrawn.</b>'),a.ixbh?'good':'');sfx('alert');after();},
|
||||||
|
rtbh:()=>{const a=S.ev.ddos;if(!a){toast(tr('<b>No attack to blackhole right now.</b>'),'');return;}a.bh=true;S.stats.rtbh=(S.stats.rtbh||0)+1;toast(tr('<b>RTBH announced.</b><br>You blackholed the target in {city}. The flood stops, and so does everyone there.',{city:CITY[a.city].name}),'bad');sfx('alert');after();},
|
||||||
|
unrtbh:()=>{const a=S.ev.ddos;if(!a||!a.bh)return;a.bh=false;toast(tr('<b>Blackhole withdrawn.</b><br>{city} is reachable again. Brace for the junk.',{city:CITY[a.city].name}),'');after();},
|
||||||
|
hackback:()=>{const a=S.ev.ddos;if(!a||a.until<=S.day){toast(tr('<b>Nothing to hack back right now.</b>'),'');return;}if(!spend(20000))return;S.stats.hackback=(S.stats.hackback||0)+1;
|
||||||
|
if(Math.random()<0.35){a.until=S.day;a.bh=false;S.stats.hackWin=(S.stats.hackWin||0)+1;toast(tr('<b>HackBack 3000™ strikes back!</b><br>Skynot AI traced the botnet and politely bricked it. The attack on {city} stops cold.',{city:CITY[a.city].name}),'goal');sfx('coin');}
|
||||||
|
else{const fine=15000+Math.floor(Math.random()*35000);S.cash-=fine;S.stats.vigilante=(S.stats.vigilante||0)+1;
|
||||||
|
toast(tr('<b>HackBack 3000™ hit the wrong target.</b><br>{who} A regulator sends you a {fine} fine, and the attack rolls on.',{who:pick([tr("Skynot AI flattened a grandma's internet-connected fridge."),tr('You counter-flooded a hospital in a country you cannot pronounce.'),tr('The botnet was already someone else’s botnet. They are furious.')]),fine:fmt$(fine)}),'bad');sfx('err');}
|
||||||
|
after();},
|
||||||
|
cnPrem:({v})=>{UI.cnPrem=!!+v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
});
|
||||||
15
src/game/90-actions/85-routing-and-routers.js
Normal file
15
src/game/90-actions/85-routing-and-routers.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
via:({v})=>{UI.via=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;sfx('click');after();}},
|
||||||
|
route:({r})=>{UI.route=r;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
addParallel:({id})=>{const l=S.links.find(x=>x.id===id);if(l)openLinkModal(l.a,l.b);},
|
||||||
|
addRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)>=RMAX)return;if(!spend(routerCost(p.rgen||0)))return;p.routers=(p.routers||1)+1;floater(CITY[city].x,CITY[city].y-30,tr('Router added'),'#FF4F9A');after();},
|
||||||
|
models:()=>{UI.models=!UI.models;renderPanel();},
|
||||||
|
rmRouter:({city})=>{const p=S.pops[city];if(!p||(p.routers||1)<=1)return;if(portsUsed(city)>portsMax(city,undefined,p.routers-1)){toast(tr('<b>Unplug something first.</b><br>{used} ports are in use, and one router fewer only has {max}.',{used:fmtPorts(portsUsed(city)),max:portsMax(city,undefined,p.routers-1)}),'bad');sfx('err');return;}p.routers--;{const back=tradeIn(p.rgen||0,1);if(back>0){S.cash+=back;toast(tr('<b>Sold a {model} on eBuy.</b><br>{price} back.',{model:esc(RG[p.rgen||0].n),price:fmt$(back)}),'good');}}after();},
|
||||||
|
upRouter:({city,g})=>{const p=S.pops[city];if(!p)return;g=g===undefined?mainRG(RG[p.rgen||0].cls+1):+g;if(!RG[g]||g===(p.rgen||0))return;{const why=modelFits(city,g);if(why){toast(tr("<b>The {model} won't fit.</b><br>{why}",{model:esc(RG[g].n),why:esc(why)}),'bad');sfx('err');return;}}if(RG[g].lvl>lvl()){toast(tr('<b>{model} unlocks at customer level {lv}.</b>',{model:esc(RG[g].n),lv:RG[g].lvl}),'bad');sfx('err');return;}
|
||||||
|
const rt=p.routers||1,old=p.rgen||0;if(p.rupDay===S.day){toast(tr('<b>The new routers in {city} are still being racked.</b><br>One swap a day: try again tomorrow.',{city:CITY[city].name}),'bad');sfx('err');return;}const back=tradeIn(old,rt);if(!spend(swapCost(city,g)))return;p.rgen=g;p.rupDay=S.day;if(back>0)toast(tr('<b>Sold the old {model} on eBuy.</b><br>{price} back toward the new gear.',{model:esc(RG[old].n),price:fmt$(back)}),'good');
|
||||||
|
if(rt===1&&popIdle(city))toast(tr('<b>New router in {city}</b><br>Swapped before anything was plugged in: zero downtime, zero angry customers.',{city:CITY[city].name}),'good');
|
||||||
|
else if(rt===1){const sl=slowBoot(city),dd=sl?3:1;p.down=Math.max(p.down||0,S.day+dd);addInc({type:'maint',ref:city,until:S.day+dd,msg:sl?tr('Swapping the only router in {city} for a {model}. The new one {how}. Back in {n} days.',{city:CITY[city].name,model:RG[g].n,how:pick(SLOW_BOOT),n:dd}):tr('Swapping the only router in {city} for a {model}. Maintenance window: back tomorrow.',{city:CITY[city].name,model:RG[g].n}),cost:0});toast(`<b>${tr('Maintenance window in {city}',{city:CITY[city].name})}</b><br>${sl?tr('One router, and this one takes forever to boot. Back in {n} days.',{n:dd}):tr('One router means downtime during the swap. Back tomorrow.')}`,'bad');}
|
||||||
|
else toast(tr('<b>Rolling upgrade in {city}</b><br>{n} × {model}, swapped one at a time. Zero downtime.',{city:CITY[city].name,n:rt,model:esc(RG[g].n)}),'good');
|
||||||
|
floater(CITY[city].x,CITY[city].y-30,RG[g].n+'!','#FF4F9A');after();},
|
||||||
|
});
|
||||||
37
src/game/90-actions/87-fiber-and-hardware.js
Normal file
37
src/game/90-actions/87-fiber-and-hardware.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
dfMode:({m})=>{UI.lmode=m;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
seaPackage:({k})=>{if(!own(SUB_UPGRADES,k))return;UI['sea'+k]=!UI['sea'+k];if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
subUpgrade:({id,k})=>{const l=S.links.find(l=>l.id===id);if(!l||l.kind!=='df'||!l.own||!l.sub||!own(SUB_UPGRADES,k)||lvl()<4||l['sub'+k]!==undefined)return;if(!spend(subUpgradeCost(l,k)))return;l.paid=(l.paid>0?l.paid:ownCabCost(l.km))+subUpgradeCost(l,k);l['sub'+k]=Math.max(S.day,l.ready||0)+SUB_UPGRADES[k].days;after();},
|
||||||
|
seaDesign:({v})=>{if(!own(SEA_DESIGNS,v))return;UI.seaDesign=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
ownCab:()=>{UI.lmode='df';UI.dfSrc='cable';UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
dfSrc:({v})=>{UI.dfSrc=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
dfSys:({v})=>{UI.dfSys=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);},
|
||||||
|
orderCable:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(ownCabWhy(a,b))return;const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',up={terminal:!!UI.seaterminal,engineering:!!UI.seaengineering},q=seaQuote(a,b,design,up),km=q.km,cost=q.cost+(S.pops[b]?0:popCost(b));if(seaLack(km,up).length||!spend(cost))return;
|
||||||
|
if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};
|
||||||
|
const used=new Set(S.links.map(l=>l.cname).filter(Boolean)),cname=OWNCAB_NAMES.find(n=>!used.has(n))||`${pick(OWNCAB_NAMES)} ${used.size+1}`,ship=pick(OWNCAB_SHIPS),id=uid(),days=q.days;
|
||||||
|
S.links.push({id,a,b,kind:'df',own:true,sub:true,seaDesign:design,seaPath:q.pts.map(p=>p.slice()),sys:'roadm',ch:[],km,cable:null,cname,mo:Math.round(km*OWNCAB_OM),trench:'own:'+id,cut:0,day:S.day,ready:S.day+days,spares:false,pairs:1});
|
||||||
|
const laid=S.links[S.links.length-1];laid.paid=q.cost;for(const k of Object.keys(SUB_UPGRADES))if(up[k])laid['sub'+k]=laid.ready;UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false;
|
||||||
|
S.stats.ownCab=(S.stats.ownCab||0)+1;UI.dfSrc='lease';closeModal();UI.sel={type:'link',id};
|
||||||
|
toast(tr('<b>The {ship} sets sail!</b><br>{name}, your own {km} km cable from {a} to {b}. Ready in about {n} days, if the whales cooperate.',{ship,name:cname,km:km.toLocaleString(),a:CITY[a].name,b:CITY[b].name,n:days}),'goal');sfx('build');after();},
|
||||||
|
orderDf:()=>{const p=UI.pending;if(!p)return;const {a,b}=p;if(!dfAllowed(a,b))return;const sc=isSub(a,b)?subDfCable(a,b):null,km=sc?sc.km:kmBetween(a,b);
|
||||||
|
const own=UI.dfSrc==='build'&&lvl()>=3&&!sc,sys=DF_SYS[UI.dfSys]&&DF_SYS[UI.dfSys].lvl<=lvl()?UI.dfSys:'lite';if(lvl()<2)return;
|
||||||
|
const up=(own?dfBuildCost(km):0)+DF_SYS[sys].cost+ampCount(km)*AMP_COST+(S.pops[b]?0:popCost(b));if(!spend(up))return;
|
||||||
|
if(!S.pops[b])S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};
|
||||||
|
const sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),id=uid();
|
||||||
|
const l={id,a,b,kind:'df',own,sys,ch:[],km,sub:!!sc,cable:sc?sc.cid:null,mo:own?Math.round(km*0.15):dfLeaseMo(km),trench:sc?'cab:'+sc.cid:id,cut:0,day:S.day,ready:S.day+(own?dfBuildDays(km):30),spares:false};
|
||||||
|
S.links.push(l);closeModal();UI.sel={type:'link',id};
|
||||||
|
toast(own?tr('<b>Groundbreaking!</b><br>Your own fiber from {a} to {b}. Permits and digging take about {n} days.',{a:CITY[a].name,b:CITY[b].name,n:dfBuildDays(km)}):tr('<b>Dark fiber IRU signed.</b><br>{a}–{b} will be spliced and handed over in about 30 days.',{a:CITY[a].name,b:CITY[b].name}),'goal');after();},
|
||||||
|
regen:({id,d})=>{d=+d;const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||l.sub||(d!==1&&d!==-1))return;const n=(l.regen|0)+d;if(n<0||n>REGEN_MAX)return;
|
||||||
|
if(d<0&&(l.ch||[]).some(o=>!optMode(o,{km:l.km,regen:n}))){toast(tr('<b>Those optics need the regen site.</b><br>Remove the long-haul channels first, or keep the site.'),'bad');sfx('err');return;}
|
||||||
|
if(d>0&&!spend(REGEN_COST+Math.round((l.ch||[]).reduce((a,c)=>a+optCost(c),0)*REGEN_CH)))return;l.regen=n;toast(d>0?tr('<b>Regen site {n} is up.</b><br>Optical spans on {a}–{b} are now {km} km.',{n,a:CITY[l.a].name,b:CITY[l.b].name,km:spanKm(l).toLocaleString()}):tr('<b>Regen site removed.</b>'),'good');sfx('build');after();},
|
||||||
|
addCh:({id,o})=>{const l=S.links.find(x=>x.id===id),O=OPT[o];if(!l||!O||l.kind!=='df')return;const why=chWhy(l,o);if(why){toast(tr("<b>Can't add {optic}.</b><br>{why}",{optic:O.n,why:esc(why)}),'bad');sfx('err');return;}if(!portGate(l.a,1)||!portGate(l.b,1))return;const sp=spareN(o)>0;if(!spend(chCost(l,o)))return;if(sp)S.spares[o]--;(l.ch=l.ch||[]).push(o);floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,`+${O.n}`,'#FF4F9A');after();},
|
||||||
|
rmCh:({id,o})=>{const l=S.links.find(x=>x.id===id);if(!l||!OPT[o])return;const i=(l.ch||[]).lastIndexOf(o);if(i<0)return;l.ch.splice(i,1);S.spares=S.spares||{};S.spares[o]=(S.spares[o]||0)+1;floater((CITY[l.a].x+CITY[l.b].x)/2,(CITY[l.a].y+CITY[l.b].y)/2-20,tr('{optic} to spares',{optic:OPT[o].n}),'#7B61FF');after();},
|
||||||
|
hwLock:()=>{if(hwLock())return;const c=hwLockCost();if(!spend(c))return;S.hw=S.hw||{};S.hw.lock={until:S.day+HW_LOCK_DAYS,mul:hwTrend(S.day)};toast(tr('<b>Prices locked until {date}.</b><br>Your vendor’s account manager is delighted. He gets a bonus for this.',{date:dateStr(S.hw.lock.until)}),'good');after();},
|
||||||
|
buySpare:({o})=>{if(!OPT[o]||OPT[o].lvl>lvl()||spareN(o)>=64)return;if(!spend(optCost(o)))return;S.spares=S.spares||{};S.spares[o]=(S.spares[o]||0)+1;sfx('build');after();},
|
||||||
|
sellSpare:({o})=>{if(!OPT[o]||spareN(o)<1)return;S.spares[o]--;const v=spareValue(o);S.cash+=v;toast(tr('<b>Sold a spare {optic} on eBuy.</b><br>{price} back, which is {p} of what it cost new.',{optic:OPT[o].n,price:fmt$(v),p:pct(SPARE_RESALE)}),'good');sfx('coin');after();},
|
||||||
|
addPair:({id})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||!isRdm(l.sys)||l.ready>S.day)return;const n=Math.max(1,l.pairs|0);if(n>=pairsMax(l))return;if((l.ch||[]).length+soldSlots(l)<chMax(l)){toast(tr('<b>Fill this pair first.</b><br>Light all {max} channels before you light another fiber pair.',{max:chMax(l)}),'bad');sfx('err');return;}if(!spend(pairCost(l)))return;l.pairs=n+1;toast(tr('<b>Fiber pair {n} is lit: {a}–{b}.</b><br>Another ROADMaster 9000 and a fresh chain of amplifiers. Room for {m} more channels.',{n:n+1,a:CITY[l.a].name,b:CITY[l.b].name,m:DF_SYS[l.sys].max}),'good');sfx('build');after();},
|
||||||
|
upSys:({id})=>{const l=S.links.find(x=>x.id===id),to=l&&sysNext(l);if(!to||DF_SYS[to].lvl>lvl())return;if(!spend(sysUpCost(l)))return;l.sys=to;if(l.ready<=S.day){l.eqDown=S.day+1;toast(tr('<b>Line system swap</b><br>All channels are dark for a day while the ROADMs go in.'),'bad');}after();},
|
||||||
|
spares:({id})=>{const l=S.links.find(x=>x.id===id);if(!l)return;l.spares=!l.spares;sfx('click');after();},
|
||||||
|
crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.ready<=S.day+1)return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(S.day+1,l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('<b>More crews on site.</b><br>Construction is {n} day ahead.','<b>More crews on site.</b><br>Construction is {n} days ahead.',saved,{n:saved}),'good');after();},
|
||||||
|
addGen:({city})=>{const p=S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('Generator!'),'#FF8A3D');after();},
|
||||||
|
});
|
||||||
37
src/game/90-actions/89-game-and-settings.js
Normal file
37
src/game/90-actions/89-game-and-settings.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
Object.assign(ACT,{
|
||||||
|
randomName:()=>{const input=$('nmIn');if(input)input.value=UI.nm=randomNetworkName(input.value);},
|
||||||
|
start:()=>{const nm=(($('nmIn')&&$('nmIn').value)||randomNetworkName()).slice(0,24);beginGame(nm,UI.startCity,{mode:UI.mode==='sandbox'?'sandbox':'normal'});},
|
||||||
|
modeSet:({m})=>{UI.mode=m;document.querySelectorAll('.modeb').forEach(b=>b.classList.toggle('pink',b.dataset.m===m));document.querySelectorAll('.modeb').forEach(b=>b.classList.toggle('ghost',b.dataset.m!==m));},
|
||||||
|
scenarios:()=>{UI.nm=(($('nmIn')&&$('nmIn').value)||UI.nm||(S&&S.name)||randomNetworkName()).slice(0,24);scenarioModal();},
|
||||||
|
startScn:({id,sure})=>{const sc=SCN.find(x=>x.id===id);if(!sc)return;if(!sure&&S&&UI.started&&!S.lost&&!(S.scn&&(S.scn.done||S.scn.failed))){openModal(`<h2 style="font-size:26px">${tr('Start {name}?',{name:esc(sc.n)})}</h2><p class="tagline">${tr('{name} will be replaced. Export it from the menu first if you want to keep it.',{name:esc(S.name)})}</p><div class="btns">${btn(tr('Start the scenario'),'startScn',{id,sure:1},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`);return;}beginGame(UI.nm||(S&&S.name)||randomNetworkName(),sc.city,{scn:sc});},
|
||||||
|
startWeekly:({sure}={})=>{if(!sure&&S&&UI.started&&!S.lost&&!(S.scn&&(S.scn.done||S.scn.failed))){openModal(`<h2 style="font-size:26px">${tr('Start the weekly challenge?')}</h2><p class="tagline">${tr('{name} will be replaced. Export it from the menu first if you want to keep it.',{name:esc(S.name)})}</p><div class="btns">${btn(tr('Start the challenge'),'startWeekly',{sure:1},'pink big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`);return;}const wk=weekly();beginGame(UI.nm||(S&&S.name)||randomNetworkName(),wk.city,{scn:wk,seed:wk.seed});},
|
||||||
|
pickStart:({city})=>{UI.startCity=city;document.querySelectorAll('.start').forEach(b=>b.classList.toggle('on',b.dataset.city===city));},
|
||||||
|
cont:()=>{migrate(S);track('game_continue',true);UI.started=true;closeModal();renderAll();},
|
||||||
|
newgame:()=>{try{localStorage.removeItem('sot-save-v1');}catch(e){}S=null;UI.started=false;UI.sel=null;UI.nm=null;$('dash').hidden=true;$('bankBox').hidden=true;renderAll();showTitle();},
|
||||||
|
keepPlaying:()=>{closeModal();},
|
||||||
|
exportSave:()=>exportSave(),
|
||||||
|
importPick:()=>{let f=$('importIn');if(!f){f=document.createElement('input');f.type='file';f.accept='.json,application/json';f.id='importIn';f.hidden=true;document.body.appendChild(f);f.addEventListener('change',()=>{importFile(f.files[0]);f.value='';});}f.click();},
|
||||||
|
importGo:()=>{const s0=UI.importing;if(!s0)return;UI.importing=null;const prev=S;try{S=migrate(JSON.parse(JSON.stringify(s0)));compute();checkGoals();renderAll();}catch(e){S=prev;if(S)compute();renderAll();toast(tr('<b>Import failed.</b><br>That save is damaged and could not be loaded. Your current game is untouched.'),'bad');sfx('err');return;}UI.confirm=null;$('bankBox').hidden=true;$('dash').hidden=true;UI.started=true;UI.sel=null;UI.speed=S.uiSpeed===undefined?1:S.uiSpeed;if(S.cam&&isFinite(S.cam.x))Object.assign(cam,S.cam);else{const h=CITY[S.home];if(h){cam.x=h.x;cam.y=h.y;}}closeModal();$('modal').hidden=true;compute();renderAll();save();toast(tr('<b>Welcome back, {name}.</b><br>Imported and saved on this device.',{name:esc(S.name)}),'good');sfx('coin');track('game_import');},
|
||||||
|
menu:()=>{if(!S||!UI.started){showTitle();return;}openModal(`<div style="display:flex;align-items:center"><div><div class="eyebrow">AS${S.asn} · ${esc(dateStr(S.day))} · ${tierLabel()}</div><h2 style="font-size:28px">${esc(S.name)}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('Close')}">×</button></div>
|
||||||
|
<p class="tagline">${tr('Your game saves itself every few seconds on this device.')}</p>${isPhone()?installRow():''}
|
||||||
|
<div class="menu-list">
|
||||||
|
${btn(tr('Back to the map'),'closeModal',{},'pink big')}
|
||||||
|
${btn(tr('Export save <small>download a file</small>'),'exportSave',{},'')}
|
||||||
|
${btn(tr('Import a save <small>from a file</small>'),'importPick',{},'')}
|
||||||
|
${btn(tr('Share your network <small>image card</small>'),'share',{},'')}
|
||||||
|
${btn(tr('Scenarios & weekly challenge'),'scenarios',{},'ghost')}
|
||||||
|
${btn(tr('How to play'),'help',{},'ghost')}
|
||||||
|
${RELEASE_NOTES.length?btn(tr('What’s new in {v}',{v:esc(APP_VERSION)}),'whatsNewShow',{},'ghost'):''}
|
||||||
|
${btn(tr('Settings'),'settings',{},'ghost')}
|
||||||
|
${btn(tr('Start a new network'),'resetAsk',{},'red')}
|
||||||
|
</div>${chatHtml()}`);},
|
||||||
|
settings:()=>{UI.setOpen=true;openModal(settingsHtml());},
|
||||||
|
settingsClose:()=>{UI.setOpen=false;if(!S||!UI.started)showTitle();else closeModal();},
|
||||||
|
prefSet:({v})=>{const [k,b]=String(v).split(':');if(!own(PREF_DEF,k))return;setPref(k,b==='1');sfx('click');refreshSettings();},
|
||||||
|
vpSet:({v})=>{vpOn(v==='on');refreshSettings();},
|
||||||
|
resetAsk:()=>openModal(`<h2 style="font-size:26px">${tr('Start a new network?')}</h2><p class="tagline">${tr('{name} and everything it owns will be deleted. This cannot be undone.',{name:esc(S?S.name:tr('Your network'))})}</p><div class="btns">${btn(tr('Delete and start over'),'newgame',{},'red big')}${btn(tr('Keep playing'),'closeModal',{},'ghost big')}</div>`),
|
||||||
|
whatsNewShow:()=>whatsNew(true,true),
|
||||||
|
updateNow:()=>{save();location.reload();},
|
||||||
|
updateLater:()=>{$('update').hidden=true;UI.updLater=Date.now();},
|
||||||
|
helpClose:()=>{if(UI.started)closeModal();else showTitle();},
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue