This commit is contained in:
2025-12-13 06:40:14 -05:00
parent 5c2ed523b9
commit 432005bf22

View File

@@ -15,33 +15,36 @@ module.exports = {
const data = await torn.faction.upgrades(); const data = await torn.faction.upgrades();
const lines = []; // Build lines with group metadata (core / peace / war)
lines.push("Core Upgrades:"); const lines = []; // { text: string, group: 'core'|'peace'|'war'|null }
lines.push({ text: 'Core Upgrades:', group: 'core' });
let armoryNames = []; let armoryNames = [];
for (const upgrade of data.upgrades.core.upgrades) { for (const upgrade of data.upgrades.core.upgrades) {
if (upgrade.name && String(upgrade.name).toLowerCase().includes('armory')) { if (upgrade.name && String(upgrade.name).toLowerCase().includes('armory')) {
armoryNames.push(upgrade.name.replace(/\s+armory$/i, '')); armoryNames.push(upgrade.name.replace(/\s+armory$/i, ''));
} else { } else {
lines.push(` ${upgrade.name} - ${upgrade.ability}`); lines.push({ text: ` ${upgrade.name} - ${upgrade.ability}`, group: 'core' });
} }
} }
if (armoryNames.length) { if (armoryNames.length) {
lines.push(` Armory: ${armoryNames.join(', ')}`); lines.push({ text: ` Armory: ${armoryNames.join(', ')}`, group: 'core' });
} }
lines.push(""); lines.push({ text: '', group: null });
lines.push("Peace Upgrades:");
lines.push({ text: 'Peace Upgrades:', group: 'peace' });
for (const branch of data.upgrades.peace) { for (const branch of data.upgrades.peace) {
lines.push(` ${branch.name}`); lines.push({ text: ` ${branch.name}`, group: 'peace' });
for (const upgrade of branch.upgrades) { for (const upgrade of branch.upgrades) {
lines.push(` ${upgrade.name} - ${upgrade.ability}`); lines.push({ text: ` ${upgrade.name} - ${upgrade.ability}`, group: 'peace' });
} }
} }
lines.push(""); lines.push({ text: '', group: null });
lines.push("War Upgrades:");
lines.push({ text: 'War Upgrades:', group: 'war' });
for (const branch of data.upgrades.war) { for (const branch of data.upgrades.war) {
lines.push(` ${branch.name}`); lines.push({ text: ` ${branch.name}`, group: 'war' });
for (const upgrade of branch.upgrades) { for (const upgrade of branch.upgrades) {
lines.push(` ${upgrade.name} - ${upgrade.ability}`); lines.push({ text: ` ${upgrade.name} - ${upgrade.ability}`, group: 'war' });
} }
} }
@@ -76,17 +79,51 @@ module.exports = {
return wrapped; return wrapped;
} }
let visualLines = []; const baseColors = {
core: '#FFFFFF',
peace: '#FFFFFF',
peaceDim: '#AAAAAA',
war: '#FFFFFF',
warDim: '#AAAAAA'
};
const state = (data.state || '').toLowerCase();
let dimMode = 'desaturate';
let inactiveGroup = null;
if (state === 'peace') {
dimMode = 'opacity';
inactiveGroup = 'war';
} else if (state === 'war') {
dimMode = 'opacity';
inactiveGroup = 'peace';
}
function colorForGroup(group) {
if (!group) return '#ffffff';
if (group === 'core') return baseColors.core;
if (dimMode === 'opacity') {
if (group === inactiveGroup) return group === 'peace' ? baseColors.peaceDim : baseColors.warDim;
return group === 'peace' ? baseColors.peace : baseColors.war;
} else {
// fallback darker variants when state is unknown
return group === 'peace' ? baseColors.peaceDim : baseColors.warDim;
}
}
// Wrap and measure lines while preserving group
let visualLines = []; // { text, group }
let measuredMaxWidth = 0; let measuredMaxWidth = 0;
const textMaxWidth = maxWidth - padding * 2; const textMaxWidth = maxWidth - padding * 2;
for (const ln of lines) { for (const ln of lines) {
if (!ln) { if (!ln.text) {
visualLines.push(''); visualLines.push({ text: '', group: null });
continue; continue;
} }
const wrapped = wrapLine(measureCtx, ln, textMaxWidth); const wrapped = wrapLine(measureCtx, ln.text, textMaxWidth);
for (const wln of wrapped) { for (const wln of wrapped) {
visualLines.push(wln); visualLines.push({ text: wln, group: ln.group });
measuredMaxWidth = Math.max(measuredMaxWidth, Math.ceil(measureCtx.measureText(wln).width)); measuredMaxWidth = Math.max(measuredMaxWidth, Math.ceil(measureCtx.measureText(wln).width));
} }
} }
@@ -101,12 +138,12 @@ module.exports = {
ctx.fillRect(0, 0, canvasWidth, canvasHeight); ctx.fillRect(0, 0, canvasWidth, canvasHeight);
ctx.font = fontSpec; ctx.font = fontSpec;
ctx.fillStyle = '#ffffff';
ctx.textBaseline = 'top'; ctx.textBaseline = 'top';
let y = padding; let y = padding;
for (const vln of visualLines) { for (const vln of visualLines) {
ctx.fillText(vln, padding, y); ctx.fillStyle = colorForGroup(vln.group);
ctx.fillText(vln.text, padding, y);
y += lineHeight; y += lineHeight;
} }