50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import {
|
|
getEconScores,
|
|
getElementBonus,
|
|
getMilitaryDeductions,
|
|
getActivePlayerCounts,
|
|
getActivePlayerNames,
|
|
getVictoryPoints,
|
|
getGridCells,
|
|
} from "./db/gameDb.js";
|
|
import { getConfig } from "./configLoader.js";
|
|
import { computeTeamIncome, computeTeamMilitaryPower } from "./helpers/economy.js";
|
|
|
|
export async function buildRealtimeSnapshot(worldSeed) {
|
|
const [scores, elementBonus, militaryDeductions, activePlayers, playerNames, victoryPoints, rows] = await Promise.all([
|
|
getEconScores(worldSeed),
|
|
getElementBonus(worldSeed),
|
|
getMilitaryDeductions(worldSeed),
|
|
getActivePlayerCounts(worldSeed),
|
|
getActivePlayerNames(worldSeed),
|
|
getVictoryPoints(),
|
|
getGridCells(worldSeed),
|
|
]);
|
|
|
|
const cfg = getConfig();
|
|
const resourceWorth = cfg.resourceWorth ?? { common: {}, rare: {} };
|
|
const militaryPowerCfg = cfg.militaryPower ?? {};
|
|
|
|
const incomePerSecond = {
|
|
blue: computeTeamIncome("blue", rows, resourceWorth),
|
|
red: computeTeamIncome("red", rows, resourceWorth),
|
|
};
|
|
|
|
const militaryPowerGross = {
|
|
blue: computeTeamMilitaryPower("blue", rows, militaryPowerCfg),
|
|
red: computeTeamMilitaryPower("red", rows, militaryPowerCfg),
|
|
};
|
|
|
|
return {
|
|
worldSeed,
|
|
scores,
|
|
elementBonus,
|
|
militaryDeductions,
|
|
activePlayers,
|
|
playerNames,
|
|
victoryPoints,
|
|
incomePerSecond,
|
|
militaryPowerGross,
|
|
};
|
|
}
|