Files
WT-Offline/apps/server/src/profiles-setup.ts
T
N0VAN0M4LY dcc67ec148 docs(repo): use local server in remaining comments and titles
Comments where "local" and "service" fell on two lines, and the Chinese
titles of five patch definitions, still named the local service.

Checked with the root typecheck, check-patches and check-gui.
2026-11-29 03:28:56 +08:00

76 lines
3.9 KiB
TypeScript

/**
* Assemble the players' profiles with the rules they depend on, the same way for the local
* server and for the save editor (save-cli.ts): static data from the dataset cache, the
* save store with its format upgrades, and clan membership, research, and modification state
* (with the modifications the mission support planes' presets need) and the free repair over time (repair/repair-over-time.ts) kept up to date and persisted on
* every read or write.
*/
import type { AccountStore } from './accounts/account-store.ts';
import type { ClanStore } from './clans/clan-store.ts';
import type { DatasetCache } from './game-data/datasets/dataset-cache.ts';
import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts';
import { shopBranches } from './game-data/datasets/shop-branches.ts';
import { vehicleCatalogue, type CatalogueVehicle } from './game-data/datasets/vehicle-catalogue.ts';
import { vehicleEquipment } from './game-data/datasets/vehicle-equipment.ts';
import { vehicleRepair } from './game-data/datasets/vehicle-repair.ts';
import type { GameFiles } from './game-data/game-files.ts';
import { removeExpiredItems } from './items/item-expiry.ts';
import { EquipmentCatalogue } from './modifications/equipment-catalogue.ts';
import { refreshModuleState } from './modifications/module-state.ts';
import { grantSupportPlaneModifications, supportPlaneModifications } from './modifications/support-plane-modifications.ts';
import { battleSpawnRules } from './game-data/datasets/battle-spawn-rules.ts';
import { trimUserLogs } from './profile/profile-trophies-log.ts';
import { PlayerProfiles } from './profile/player-profiles.ts';
import { profileUpgrades } from './profile/profile-upgrades.ts';
import { serverTimeNow } from './profile/server-time.ts';
import type { StartingContent } from './profile/starting-content.ts';
import { repairVehiclesOverTime } from './repair/repair-over-time.ts';
import { RepairRules } from './repair/repair-rules.ts';
import { loadResearchRules, type ResearchRules } from './research/research-rules.ts';
import { refreshResearchState } from './research/research-state.ts';
import { SaveStore } from './saves/save-store.ts';
import type { Tuning } from './tuning/tuning.ts';
export interface ProfileServices {
readonly profiles: PlayerProfiles;
readonly research: ResearchRules;
readonly equipment: EquipmentCatalogue;
readonly repair: RepairRules;
}
export interface ProfileSyncContext {
readonly accounts: AccountStore;
readonly clans: ClanStore;
}
export function setUpProfiles(
dataFolder: string,
gameFiles: GameFiles,
datasets: DatasetCache,
tuning: Tuning,
sync?: ProfileSyncContext,
vehicles: readonly CatalogueVehicle[] = datasets.load(vehicleCatalogue),
): ProfileServices {
const startingContent: StartingContent = {
reserveVehicles: datasets.load(reserveVehicles),
branches: datasets.load(shopBranches),
startingBalance: tuning.newProfile.startingBalance,
};
const research = loadResearchRules(datasets, tuning.research, vehicles);
const equipment = new EquipmentCatalogue(datasets.load(vehicleEquipment));
const repair = new RepairRules(datasets.load(vehicleRepair), research.techTree);
const supportPlaneGrants = supportPlaneModifications(datasets.load(battleSpawnRules), equipment);
const saves = new SaveStore(dataFolder, profileUpgrades(startingContent));
const profiles = new PlayerProfiles(saves, gameFiles, startingContent, (profile, userId) => {
const account = sync?.accounts.byUserId(userId);
if (account && sync) sync.clans.syncProfile(profile, account);
refreshResearchState(profile, research);
refreshModuleState(profile, equipment);
grantSupportPlaneModifications(profile, supportPlaneGrants);
removeExpiredItems(profile, serverTimeNow());
repairVehiclesOverTime(profile, repair, serverTimeNow());
trimUserLogs(profile, tuning.limits.userLogsKept);
});
return { profiles, research, equipment, repair };
}