refactor: don'r store events globally

This commit is contained in:
Azgaar 2022-09-05 21:14:35 +03:00
parent 37826f1c2d
commit 0d1b52e538
5 changed files with 8 additions and 7 deletions

View file

@ -5,7 +5,6 @@ let grid = {}; // initial graph based on jittered square grid and data
let pack = {}; // packed graph and data
let notes = [];
let events = {};
let seed;
let mapId;

View file

@ -53,14 +53,13 @@ async function generate(options?: IGenerationOptions) {
window.mapCoordinates = calculateMapCoordinates();
const newGrid = await createGrid(grid, precreatedGraph);
const {pack: newPack, conflicts} = createPack(newGrid);
const newPack = createPack(newGrid);
// TODO: draw default ruler
// redefine global grid and pack
grid = newGrid;
pack = newPack;
events = {conflicts};
// temp rendering for debug
// renderLayer("cells");

View file

@ -18,7 +18,7 @@ import {generateReligions} from "./religions/generateReligions";
const {LAND_COAST, WATER_COAST, DEEPER_WATER} = DISTANCE_FIELD;
const {Biomes} = window;
export function createPack(grid: IGrid): {pack: IPack; conflicts: IConflict[]} {
export function createPack(grid: IGrid): IPack {
const {temp, prec} = grid.cells;
const {vertices, cells} = repackGrid(grid);
@ -168,6 +168,8 @@ export function createPack(grid: IGrid): {pack: IPack; conflicts: IConflict[]} {
// drawScaleBar(window.scale);
// Names.getMapName();
const events: IEvents = {conflicts};
const pack: IPack = {
vertices,
cells: {
@ -196,10 +198,11 @@ export function createPack(grid: IGrid): {pack: IPack; conflicts: IConflict[]} {
states,
burgs,
routes,
religions
religions,
events
};
return {pack, conflicts};
return pack;
}
// repack grid cells: discart deep water cells, add land cells along the coast

View file

@ -2,7 +2,6 @@ declare let grid: IGrid;
declare let pack: IPack;
declare let notes: INote[];
declare let events: IEvents;
declare let seed: string;
declare let mapId: number;

View file

@ -8,6 +8,7 @@ interface IPack extends IGraph {
rivers: TRivers;
religions: TReligions;
routes: TRoutes;
events: IEvents;
}
interface IPackCells {