tarinai/js/world.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2026-06-20 20:29:44 +09:00
"use strict";
2026-06-19 14:00:48 +09:00
2026-06-21 14:09:35 +09:00
class World { constructor() {
2026-06-19 14:00:48 +09:00
this.w = 1000;
this.h = 720;
this.viewportW = 1000;
this.viewportH = 720;
this.time = 0;
this.day = 1;
this.paused = false;
this.speed = 1;
this.tool = "observe";
this.toolSize = "medium";
this.toolSizes = {};
this.tarinai = [];
this.items = [];
2026-06-20 21:41:15 +09:00
this.ants = [];
2026-06-19 14:00:48 +09:00
this.effects = [];
this.logs = [];
2026-06-21 14:09:35 +09:00
this.events = window.TarinaiEvents || null;
2026-06-19 14:00:48 +09:00
this.eventCounters = {};
this.countsTimer = 0;
this.compactTimer = 0;
this.drawSortTimer = 0;
this.drawListDirty = true;
2026-06-21 14:09:35 +09:00
this.antUpdatePhase = 0;
2026-06-19 14:00:48 +09:00
this.selected = null;
this.deadCount = 0;
2026-06-20 23:27:39 +09:00
this.liveIdNext = 1;
this.liveIdFree = [];
this.liveIdSerial = 0;
this.liveTarinai = new Map();
2026-06-19 23:22:15 +09:00
this.lastBirthAt = -999;
2026-06-19 14:00:48 +09:00
this.maxGeneration = 1;
this.family = {};
this.familyVersion = 0;
2026-06-20 15:55:52 +09:00
this.familyTreeDirty = true;
this.familyTreeDirtyReason = "init";
2026-06-19 14:00:48 +09:00
this.relationNotices = {};
this.resolvedFightIds = {};
2026-06-19 20:52:40 +09:00
this.pointer = { x: 0, y: 0, inside: false, motion: 0, movedAt: 0 };
2026-06-19 14:00:48 +09:00
this.lastPhase = "";
this.weather = "sunny";
this.fieldType = "garden";
this.fieldZoom = 1;
this.cameraX = 0;
this.cameraY = 0;
2026-06-21 14:09:35 +09:00
this.shakeTimer = 0;
this.shakeDuration = 0;
this.shakeStrength = 0;
2026-06-19 14:00:48 +09:00
this.nextWeatherChange = rand(CONFIG.weatherChangeMin, CONFIG.weatherChangeMax);
this.spatial = new SpatialGrid(96);
2026-06-20 23:27:39 +09:00
this.spatialItemScratch = [];
this.spatialTarinaiScratch = [];
2026-06-21 14:09:35 +09:00
this.spatialAntScratch = [];
this.spatialObstacleScratch = [];
this.spatialFoodScratch = [];
this.spatialHazardScratch = [];
this.spatialVersion = 0;
this.spatialDirty = true;
this.terrainDirty = true;
this.terrainVersion = 1;
this.terrainDirtyReason = "init";
this.terrainLastDirtyAt = 0;
this.lastTerrainSignature = "";
2026-06-19 14:00:48 +09:00
this.drawList = [];
this.itemCounts = {};
this.effectCounts = {};
2026-06-21 14:09:35 +09:00
this.foodSpoilagePenalty = 0;
this.foodSpoilageEvents = 0;
2026-06-19 14:00:48 +09:00
this.updateItemCounts();
this.updateEffectCounts();
2026-06-21 14:09:35 +09:00
this.markTerrainDirty?.("reset");
this.rebuildSpatial(true);
2026-06-19 14:00:48 +09:00
}
}
2026-06-21 14:09:35 +09:00
if (typeof window !== "undefined") window.World = World;
if (typeof globalThis !== "undefined") globalThis.World = World;