mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Mark pinned shapes in statistics dialog
This commit is contained in:
parent
e6b5f8d2ed
commit
8ba6517591
@ -18,9 +18,19 @@
|
|||||||
@include S(min-width, 30px);
|
@include S(min-width, 30px);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
opacity: 0.25;
|
opacity: 0.25;
|
||||||
@include S(margin-left, 1px);
|
|
||||||
@include S(border-radius, $globalBorderRadius);
|
@include S(border-radius, $globalBorderRadius);
|
||||||
|
|
||||||
|
border-radius: 0;
|
||||||
|
&:first-child {
|
||||||
|
@include S(border-top-left-radius, $globalBorderRadius);
|
||||||
|
@include S(border-bottom-left-radius, $globalBorderRadius);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
@include S(border-top-right-radius, $globalBorderRadius);
|
||||||
|
@include S(border-bottom-right-radius, $globalBorderRadius);
|
||||||
|
}
|
||||||
|
|
||||||
&.displayIcons,
|
&.displayIcons,
|
||||||
&.displayDetailed,
|
&.displayDetailed,
|
||||||
&.displaySorted {
|
&.displaySorted {
|
||||||
@ -32,7 +42,7 @@
|
|||||||
&.displaySorted {
|
&.displaySorted {
|
||||||
background-image: uiResource("icons/display_sorted.png");
|
background-image: uiResource("icons/display_sorted.png");
|
||||||
background-size: #{D(11.5px)};
|
background-size: #{D(11.5px)};
|
||||||
margin-right: 20px;
|
margin-right: 4px;
|
||||||
@include S(padding, 1px, 0);
|
@include S(padding, 1px, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,16 +99,24 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
@include S(border-radius, $globalBorderRadius);
|
@include S(border-radius, $globalBorderRadius);
|
||||||
|
|
||||||
@include DarkThemeOverride {
|
|
||||||
background: #222428;
|
|
||||||
}
|
|
||||||
|
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
@include S(padding, 5px);
|
@include S(padding, 5px);
|
||||||
&:last-child {
|
&:last-child {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.pinned {
|
||||||
|
background: #e3e5e9;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include DarkThemeOverride {
|
||||||
|
background: #222428;
|
||||||
|
|
||||||
|
&.pinned {
|
||||||
|
background: darken(#222428, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
canvas.icon {
|
canvas.icon {
|
||||||
grid-column: 1 / 2;
|
grid-column: 1 / 2;
|
||||||
grid-row: 1 / 2;
|
grid-row: 1 / 2;
|
||||||
@ -108,7 +126,6 @@
|
|||||||
|
|
||||||
.counter {
|
.counter {
|
||||||
@include SuperSmallText;
|
@include SuperSmallText;
|
||||||
|
|
||||||
@include S(padding, 0, 3px);
|
@include S(padding, 0, 3px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +158,6 @@
|
|||||||
.counter {
|
.counter {
|
||||||
grid-column: 1 / 2;
|
grid-column: 1 / 2;
|
||||||
grid-row: 2 / 3;
|
grid-row: 2 / 3;
|
||||||
background: rgba(0, 10, 20, 0.05);
|
|
||||||
justify-self: end;
|
justify-self: end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,492 +1,492 @@
|
|||||||
/* typehints:start */
|
/* typehints:start */
|
||||||
import { Application } from "../application";
|
import { Application } from "../application";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
import { BufferMaintainer } from "../core/buffer_maintainer";
|
import { BufferMaintainer } from "../core/buffer_maintainer";
|
||||||
import { disableImageSmoothing, enableImageSmoothing, registerCanvas } from "../core/buffer_utils";
|
import { disableImageSmoothing, enableImageSmoothing, registerCanvas } from "../core/buffer_utils";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { getDeviceDPI, resizeHighDPICanvas } from "../core/dpi_manager";
|
import { getDeviceDPI, resizeHighDPICanvas } from "../core/dpi_manager";
|
||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { gMetaBuildingRegistry } from "../core/global_registries";
|
import { gMetaBuildingRegistry } from "../core/global_registries";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { Rectangle } from "../core/rectangle";
|
import { Rectangle } from "../core/rectangle";
|
||||||
import { randomInt, round2Digits, round3Digits } from "../core/utils";
|
import { randomInt, round2Digits, round3Digits } from "../core/utils";
|
||||||
import { Vector } from "../core/vector";
|
import { Vector } from "../core/vector";
|
||||||
import { Savegame } from "../savegame/savegame";
|
import { Savegame } from "../savegame/savegame";
|
||||||
import { SavegameSerializer } from "../savegame/savegame_serializer";
|
import { SavegameSerializer } from "../savegame/savegame_serializer";
|
||||||
import { AutomaticSave } from "./automatic_save";
|
import { AutomaticSave } from "./automatic_save";
|
||||||
import { MetaHubBuilding } from "./buildings/hub";
|
import { MetaHubBuilding } from "./buildings/hub";
|
||||||
import { Camera } from "./camera";
|
import { Camera } from "./camera";
|
||||||
import { DynamicTickrate } from "./dynamic_tickrate";
|
import { DynamicTickrate } from "./dynamic_tickrate";
|
||||||
import { EntityManager } from "./entity_manager";
|
import { EntityManager } from "./entity_manager";
|
||||||
import { GameSystemManager } from "./game_system_manager";
|
import { GameSystemManager } from "./game_system_manager";
|
||||||
import { HubGoals } from "./hub_goals";
|
import { HubGoals } from "./hub_goals";
|
||||||
import { GameHUD } from "./hud/hud";
|
import { GameHUD } from "./hud/hud";
|
||||||
import { KeyActionMapper } from "./key_action_mapper";
|
import { KeyActionMapper } from "./key_action_mapper";
|
||||||
import { GameLogic } from "./logic";
|
import { GameLogic } from "./logic";
|
||||||
import { MapView } from "./map_view";
|
import { MapView } from "./map_view";
|
||||||
import { defaultBuildingVariant } from "./meta_building";
|
import { defaultBuildingVariant } from "./meta_building";
|
||||||
import { ProductionAnalytics } from "./production_analytics";
|
import { ProductionAnalytics } from "./production_analytics";
|
||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { ShapeDefinitionManager } from "./shape_definition_manager";
|
import { ShapeDefinitionManager } from "./shape_definition_manager";
|
||||||
import { SoundProxy } from "./sound_proxy";
|
import { SoundProxy } from "./sound_proxy";
|
||||||
import { GameTime } from "./time/game_time";
|
import { GameTime } from "./time/game_time";
|
||||||
import { ORIGINAL_SPRITE_SCALE } from "../core/sprites";
|
import { ORIGINAL_SPRITE_SCALE } from "../core/sprites";
|
||||||
|
|
||||||
const logger = createLogger("ingame/core");
|
const logger = createLogger("ingame/core");
|
||||||
|
|
||||||
// Store the canvas so we can reuse it later
|
// Store the canvas so we can reuse it later
|
||||||
/** @type {HTMLCanvasElement} */
|
/** @type {HTMLCanvasElement} */
|
||||||
let lastCanvas = null;
|
let lastCanvas = null;
|
||||||
/** @type {CanvasRenderingContext2D} */
|
/** @type {CanvasRenderingContext2D} */
|
||||||
let lastContext = null;
|
let lastContext = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The core manages the root and represents the whole game. It wraps the root, since
|
* The core manages the root and represents the whole game. It wraps the root, since
|
||||||
* the root class is just a data holder.
|
* the root class is just a data holder.
|
||||||
*/
|
*/
|
||||||
export class GameCore {
|
export class GameCore {
|
||||||
/** @param {Application} app */
|
/** @param {Application} app */
|
||||||
constructor(app) {
|
constructor(app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
/** @type {GameRoot} */
|
/** @type {GameRoot} */
|
||||||
this.root = null;
|
this.root = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to true at the beginning of a logic update and cleared when its finished.
|
* Set to true at the beginning of a logic update and cleared when its finished.
|
||||||
* This is to prevent doing a recursive logic update which can lead to unexpected
|
* This is to prevent doing a recursive logic update which can lead to unexpected
|
||||||
* behaviour.
|
* behaviour.
|
||||||
*/
|
*/
|
||||||
this.duringLogicUpdate = false;
|
this.duringLogicUpdate = false;
|
||||||
|
|
||||||
// Cached
|
// Cached
|
||||||
this.boundInternalTick = this.updateLogic.bind(this);
|
this.boundInternalTick = this.updateLogic.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the root object which stores all game related data. The state
|
* Initializes the root object which stores all game related data. The state
|
||||||
* is required as a back reference (used sometimes)
|
* is required as a back reference (used sometimes)
|
||||||
* @param {import("../states/ingame").InGameState} parentState
|
* @param {import("../states/ingame").InGameState} parentState
|
||||||
* @param {Savegame} savegame
|
* @param {Savegame} savegame
|
||||||
*/
|
*/
|
||||||
initializeRoot(parentState, savegame) {
|
initializeRoot(parentState, savegame) {
|
||||||
// Construct the root element, this is the data representation of the game
|
// Construct the root element, this is the data representation of the game
|
||||||
this.root = new GameRoot(this.app);
|
this.root = new GameRoot(this.app);
|
||||||
this.root.gameState = parentState;
|
this.root.gameState = parentState;
|
||||||
this.root.keyMapper = parentState.keyActionMapper;
|
this.root.keyMapper = parentState.keyActionMapper;
|
||||||
this.root.savegame = savegame;
|
this.root.savegame = savegame;
|
||||||
this.root.gameWidth = this.app.screenWidth;
|
this.root.gameWidth = this.app.screenWidth;
|
||||||
this.root.gameHeight = this.app.screenHeight;
|
this.root.gameHeight = this.app.screenHeight;
|
||||||
|
|
||||||
// Initialize canvas element & context
|
// Initialize canvas element & context
|
||||||
this.internalInitCanvas();
|
this.internalInitCanvas();
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
const root = this.root;
|
const root = this.root;
|
||||||
|
|
||||||
// This isn't nice, but we need it right here
|
// This isn't nice, but we need it right here
|
||||||
root.keyMapper = new KeyActionMapper(root, this.root.gameState.inputReciever);
|
root.keyMapper = new KeyActionMapper(root, this.root.gameState.inputReciever);
|
||||||
|
|
||||||
// Needs to come first
|
// Needs to come first
|
||||||
root.dynamicTickrate = new DynamicTickrate(root);
|
root.dynamicTickrate = new DynamicTickrate(root);
|
||||||
|
|
||||||
// Init classes
|
// Init classes
|
||||||
root.camera = new Camera(root);
|
root.camera = new Camera(root);
|
||||||
root.map = new MapView(root);
|
root.map = new MapView(root);
|
||||||
root.logic = new GameLogic(root);
|
root.logic = new GameLogic(root);
|
||||||
root.hud = new GameHUD(root);
|
root.hud = new GameHUD(root);
|
||||||
root.time = new GameTime(root);
|
root.time = new GameTime(root);
|
||||||
root.automaticSave = new AutomaticSave(root);
|
root.automaticSave = new AutomaticSave(root);
|
||||||
root.soundProxy = new SoundProxy(root);
|
root.soundProxy = new SoundProxy(root);
|
||||||
|
|
||||||
// Init managers
|
// Init managers
|
||||||
root.entityMgr = new EntityManager(root);
|
root.entityMgr = new EntityManager(root);
|
||||||
root.systemMgr = new GameSystemManager(root);
|
root.systemMgr = new GameSystemManager(root);
|
||||||
root.shapeDefinitionMgr = new ShapeDefinitionManager(root);
|
root.shapeDefinitionMgr = new ShapeDefinitionManager(root);
|
||||||
root.hubGoals = new HubGoals(root);
|
root.hubGoals = new HubGoals(root);
|
||||||
root.productionAnalytics = new ProductionAnalytics(root);
|
root.productionAnalytics = new ProductionAnalytics(root);
|
||||||
root.buffers = new BufferMaintainer(root);
|
root.buffers = new BufferMaintainer(root);
|
||||||
|
|
||||||
// Initialize the hud once everything is loaded
|
// Initialize the hud once everything is loaded
|
||||||
this.root.hud.initialize();
|
this.root.hud.initialize();
|
||||||
|
|
||||||
// Initial resize event, it might be possible that the screen
|
// Initial resize event, it might be possible that the screen
|
||||||
// resized later during init tho, which is why will emit it later
|
// resized later during init tho, which is why will emit it later
|
||||||
// again anyways
|
// again anyways
|
||||||
this.resize(this.app.screenWidth, this.app.screenHeight);
|
this.resize(this.app.screenWidth, this.app.screenHeight);
|
||||||
|
|
||||||
if (G_IS_DEV) {
|
if (G_IS_DEV) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.globalRoot = root;
|
window.globalRoot = root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new game, this means creating a new map and centering on the
|
* Initializes a new game, this means creating a new map and centering on the
|
||||||
* playerbase
|
* playerbase
|
||||||
* */
|
* */
|
||||||
initNewGame() {
|
initNewGame() {
|
||||||
logger.log("Initializing new game");
|
logger.log("Initializing new game");
|
||||||
this.root.gameIsFresh = true;
|
this.root.gameIsFresh = true;
|
||||||
this.root.map.seed = randomInt(0, 100000);
|
this.root.map.seed = randomInt(0, 100000);
|
||||||
|
|
||||||
// Place the hub
|
// Place the hub
|
||||||
const hub = gMetaBuildingRegistry.findByClass(MetaHubBuilding).createEntity({
|
const hub = gMetaBuildingRegistry.findByClass(MetaHubBuilding).createEntity({
|
||||||
root: this.root,
|
root: this.root,
|
||||||
origin: new Vector(-2, -2),
|
origin: new Vector(-2, -2),
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
originalRotation: 0,
|
originalRotation: 0,
|
||||||
rotationVariant: 0,
|
rotationVariant: 0,
|
||||||
variant: defaultBuildingVariant,
|
variant: defaultBuildingVariant,
|
||||||
});
|
});
|
||||||
this.root.map.placeStaticEntity(hub);
|
this.root.map.placeStaticEntity(hub);
|
||||||
this.root.entityMgr.registerEntity(hub);
|
this.root.entityMgr.registerEntity(hub);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inits an existing game by loading the raw savegame data and deserializing it.
|
* Inits an existing game by loading the raw savegame data and deserializing it.
|
||||||
* Also runs basic validity checks.
|
* Also runs basic validity checks.
|
||||||
*/
|
*/
|
||||||
initExistingGame() {
|
initExistingGame() {
|
||||||
logger.log("Initializing existing game");
|
logger.log("Initializing existing game");
|
||||||
const serializer = new SavegameSerializer();
|
const serializer = new SavegameSerializer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const status = serializer.deserialize(this.root.savegame.getCurrentDump(), this.root);
|
const status = serializer.deserialize(this.root.savegame.getCurrentDump(), this.root);
|
||||||
if (!status.isGood()) {
|
if (!status.isGood()) {
|
||||||
logger.error("savegame-deserialize-failed:" + status.reason);
|
logger.error("savegame-deserialize-failed:" + status.reason);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
logger.error("Exception during deserialization:", ex);
|
logger.error("Exception during deserialization:", ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.root.gameIsFresh = false;
|
this.root.gameIsFresh = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the render canvas
|
* Initializes the render canvas
|
||||||
*/
|
*/
|
||||||
internalInitCanvas() {
|
internalInitCanvas() {
|
||||||
let canvas, context;
|
let canvas, context;
|
||||||
if (!lastCanvas) {
|
if (!lastCanvas) {
|
||||||
logger.log("Creating new canvas");
|
logger.log("Creating new canvas");
|
||||||
canvas = document.createElement("canvas");
|
canvas = document.createElement("canvas");
|
||||||
canvas.id = "ingame_Canvas";
|
canvas.id = "ingame_Canvas";
|
||||||
canvas.setAttribute("opaque", "true");
|
canvas.setAttribute("opaque", "true");
|
||||||
canvas.setAttribute("webkitOpaque", "true");
|
canvas.setAttribute("webkitOpaque", "true");
|
||||||
canvas.setAttribute("mozOpaque", "true");
|
canvas.setAttribute("mozOpaque", "true");
|
||||||
this.root.gameState.getDivElement().appendChild(canvas);
|
this.root.gameState.getDivElement().appendChild(canvas);
|
||||||
context = canvas.getContext("2d", { alpha: false });
|
context = canvas.getContext("2d", { alpha: false });
|
||||||
|
|
||||||
lastCanvas = canvas;
|
lastCanvas = canvas;
|
||||||
lastContext = context;
|
lastContext = context;
|
||||||
} else {
|
} else {
|
||||||
logger.log("Reusing canvas");
|
logger.log("Reusing canvas");
|
||||||
if (lastCanvas.parentElement) {
|
if (lastCanvas.parentElement) {
|
||||||
lastCanvas.parentElement.removeChild(lastCanvas);
|
lastCanvas.parentElement.removeChild(lastCanvas);
|
||||||
}
|
}
|
||||||
this.root.gameState.getDivElement().appendChild(lastCanvas);
|
this.root.gameState.getDivElement().appendChild(lastCanvas);
|
||||||
|
|
||||||
canvas = lastCanvas;
|
canvas = lastCanvas;
|
||||||
context = lastContext;
|
context = lastContext;
|
||||||
|
|
||||||
lastContext.clearRect(0, 0, lastCanvas.width, lastCanvas.height);
|
lastContext.clearRect(0, 0, lastCanvas.width, lastCanvas.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// globalConfig.smoothing.smoothMainCanvas = getDeviceDPI() < 1.5;
|
// globalConfig.smoothing.smoothMainCanvas = getDeviceDPI() < 1.5;
|
||||||
// globalConfig.smoothing.smoothMainCanvas = true;
|
// globalConfig.smoothing.smoothMainCanvas = true;
|
||||||
|
|
||||||
canvas.classList.toggle("smoothed", globalConfig.smoothing.smoothMainCanvas);
|
canvas.classList.toggle("smoothed", globalConfig.smoothing.smoothMainCanvas);
|
||||||
|
|
||||||
// Oof, use :not() instead
|
// Oof, use :not() instead
|
||||||
canvas.classList.toggle("unsmoothed", !globalConfig.smoothing.smoothMainCanvas);
|
canvas.classList.toggle("unsmoothed", !globalConfig.smoothing.smoothMainCanvas);
|
||||||
|
|
||||||
if (globalConfig.smoothing.smoothMainCanvas) {
|
if (globalConfig.smoothing.smoothMainCanvas) {
|
||||||
enableImageSmoothing(context);
|
enableImageSmoothing(context);
|
||||||
} else {
|
} else {
|
||||||
disableImageSmoothing(context);
|
disableImageSmoothing(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.canvas = canvas;
|
this.root.canvas = canvas;
|
||||||
this.root.context = context;
|
this.root.context = context;
|
||||||
|
|
||||||
registerCanvas(canvas, context);
|
registerCanvas(canvas, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructs the root, freeing all resources
|
* Destructs the root, freeing all resources
|
||||||
*/
|
*/
|
||||||
destruct() {
|
destruct() {
|
||||||
if (lastCanvas && lastCanvas.parentElement) {
|
if (lastCanvas && lastCanvas.parentElement) {
|
||||||
lastCanvas.parentElement.removeChild(lastCanvas);
|
lastCanvas.parentElement.removeChild(lastCanvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.destruct();
|
this.root.destruct();
|
||||||
delete this.root;
|
delete this.root;
|
||||||
this.root = null;
|
this.root = null;
|
||||||
this.app = null;
|
this.app = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
tick(deltaMs) {
|
tick(deltaMs) {
|
||||||
const root = this.root;
|
const root = this.root;
|
||||||
|
|
||||||
// Extract current real time
|
// Extract current real time
|
||||||
root.time.updateRealtimeNow();
|
root.time.updateRealtimeNow();
|
||||||
|
|
||||||
// Camera is always updated, no matter what
|
// Camera is always updated, no matter what
|
||||||
root.camera.update(deltaMs);
|
root.camera.update(deltaMs);
|
||||||
|
|
||||||
// Perform logic ticks
|
// Perform logic ticks
|
||||||
this.root.time.performTicks(deltaMs, this.boundInternalTick);
|
this.root.time.performTicks(deltaMs, this.boundInternalTick);
|
||||||
|
|
||||||
// Update analytics
|
// Update analytics
|
||||||
root.productionAnalytics.update();
|
root.productionAnalytics.update();
|
||||||
|
|
||||||
// Update automatic save after everything finished
|
// Update automatic save after everything finished
|
||||||
root.automaticSave.update();
|
root.automaticSave.update();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldRender() {
|
shouldRender() {
|
||||||
if (this.root.queue.requireRedraw) {
|
if (this.root.queue.requireRedraw) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this.root.hud.shouldPauseRendering()) {
|
if (this.root.hud.shouldPauseRendering()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not render
|
// Do not render
|
||||||
if (!this.app.isRenderable()) {
|
if (!this.app.isRenderable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLogic() {
|
updateLogic() {
|
||||||
const root = this.root;
|
const root = this.root;
|
||||||
|
|
||||||
root.dynamicTickrate.beginTick();
|
root.dynamicTickrate.beginTick();
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.disableLogicTicks) {
|
if (G_IS_DEV && globalConfig.debug.disableLogicTicks) {
|
||||||
root.dynamicTickrate.endTick();
|
root.dynamicTickrate.endTick();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.duringLogicUpdate = true;
|
this.duringLogicUpdate = true;
|
||||||
|
|
||||||
// Update entities, this removes destroyed entities
|
// Update entities, this removes destroyed entities
|
||||||
root.entityMgr.update();
|
root.entityMgr.update();
|
||||||
|
|
||||||
// IMPORTANT: At this point, the game might be game over. Stop if this is the case
|
// IMPORTANT: At this point, the game might be game over. Stop if this is the case
|
||||||
if (!this.root) {
|
if (!this.root) {
|
||||||
logger.log("Root destructed, returning false");
|
logger.log("Root destructed, returning false");
|
||||||
root.dynamicTickrate.endTick();
|
root.dynamicTickrate.endTick();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
root.systemMgr.update();
|
root.systemMgr.update();
|
||||||
// root.particleMgr.update();
|
// root.particleMgr.update();
|
||||||
|
|
||||||
this.duringLogicUpdate = false;
|
this.duringLogicUpdate = false;
|
||||||
root.dynamicTickrate.endTick();
|
root.dynamicTickrate.endTick();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
resize(w, h) {
|
resize(w, h) {
|
||||||
this.root.gameWidth = w;
|
this.root.gameWidth = w;
|
||||||
this.root.gameHeight = h;
|
this.root.gameHeight = h;
|
||||||
resizeHighDPICanvas(this.root.canvas, w, h, globalConfig.smoothing.smoothMainCanvas);
|
resizeHighDPICanvas(this.root.canvas, w, h, globalConfig.smoothing.smoothMainCanvas);
|
||||||
this.root.signals.resized.dispatch(w, h);
|
this.root.signals.resized.dispatch(w, h);
|
||||||
this.root.queue.requireRedraw = true;
|
this.root.queue.requireRedraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
postLoadHook() {
|
postLoadHook() {
|
||||||
logger.log("Dispatching post load hook");
|
logger.log("Dispatching post load hook");
|
||||||
this.root.signals.postLoadHook.dispatch();
|
this.root.signals.postLoadHook.dispatch();
|
||||||
|
|
||||||
if (!this.root.gameIsFresh) {
|
if (!this.root.gameIsFresh) {
|
||||||
// Also dispatch game restored hook on restored savegames
|
// Also dispatch game restored hook on restored savegames
|
||||||
this.root.signals.gameRestored.dispatch();
|
this.root.signals.gameRestored.dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.gameInitialized = true;
|
this.root.gameInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
const root = this.root;
|
const root = this.root;
|
||||||
const systems = root.systemMgr.systems;
|
const systems = root.systemMgr.systems;
|
||||||
|
|
||||||
this.root.dynamicTickrate.onFrameRendered();
|
this.root.dynamicTickrate.onFrameRendered();
|
||||||
|
|
||||||
if (!this.shouldRender()) {
|
if (!this.shouldRender()) {
|
||||||
// Always update hud tho
|
// Always update hud tho
|
||||||
root.hud.update();
|
root.hud.update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.signals.gameFrameStarted.dispatch();
|
this.root.signals.gameFrameStarted.dispatch();
|
||||||
|
|
||||||
root.queue.requireRedraw = false;
|
root.queue.requireRedraw = false;
|
||||||
|
|
||||||
// Gather context and save all state
|
// Gather context and save all state
|
||||||
const context = root.context;
|
const context = root.context;
|
||||||
context.save();
|
context.save();
|
||||||
if (G_IS_DEV) {
|
if (G_IS_DEV) {
|
||||||
context.fillStyle = "#a10000";
|
context.fillStyle = "#a10000";
|
||||||
context.fillRect(0, 0, window.innerWidth * 3, window.innerHeight * 3);
|
context.fillRect(0, 0, window.innerWidth * 3, window.innerHeight * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute optimal zoom level and atlas scale
|
// Compute optimal zoom level and atlas scale
|
||||||
const zoomLevel = root.camera.zoomLevel;
|
const zoomLevel = root.camera.zoomLevel;
|
||||||
const lowQuality = root.app.settings.getAllSettings().lowQualityTextures;
|
const lowQuality = root.app.settings.getAllSettings().lowQualityTextures;
|
||||||
const effectiveZoomLevel =
|
const effectiveZoomLevel =
|
||||||
(zoomLevel / globalConfig.assetsDpi) * getDeviceDPI() * globalConfig.assetsSharpness;
|
(zoomLevel / globalConfig.assetsDpi) * getDeviceDPI() * globalConfig.assetsSharpness;
|
||||||
|
|
||||||
let desiredAtlasScale = "0.25";
|
let desiredAtlasScale = "0.25";
|
||||||
if (effectiveZoomLevel > 0.8 && !lowQuality) {
|
if (effectiveZoomLevel > 0.8 && !lowQuality) {
|
||||||
desiredAtlasScale = ORIGINAL_SPRITE_SCALE;
|
desiredAtlasScale = ORIGINAL_SPRITE_SCALE;
|
||||||
} else if (effectiveZoomLevel > 0.4 && !lowQuality) {
|
} else if (effectiveZoomLevel > 0.4 && !lowQuality) {
|
||||||
desiredAtlasScale = "0.5";
|
desiredAtlasScale = "0.5";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct parameters required for drawing
|
// Construct parameters required for drawing
|
||||||
const params = new DrawParameters({
|
const params = new DrawParameters({
|
||||||
context: context,
|
context: context,
|
||||||
visibleRect: root.camera.getVisibleRect(),
|
visibleRect: root.camera.getVisibleRect(),
|
||||||
desiredAtlasScale,
|
desiredAtlasScale,
|
||||||
zoomLevel,
|
zoomLevel,
|
||||||
root: root,
|
root: root,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.testCulling) {
|
if (G_IS_DEV && globalConfig.debug.testCulling) {
|
||||||
context.clearRect(0, 0, root.gameWidth, root.gameHeight);
|
context.clearRect(0, 0, root.gameWidth, root.gameHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform to world space
|
// Transform to world space
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.testClipping) {
|
if (G_IS_DEV && globalConfig.debug.testClipping) {
|
||||||
params.visibleRect = params.visibleRect.expandedInAllDirections(
|
params.visibleRect = params.visibleRect.expandedInAllDirections(
|
||||||
-200 / this.root.camera.zoomLevel
|
-200 / this.root.camera.zoomLevel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
root.camera.transform(context);
|
root.camera.transform(context);
|
||||||
|
|
||||||
assert(context.globalAlpha === 1.0, "Global alpha not 1 on frame start");
|
assert(context.globalAlpha === 1.0, "Global alpha not 1 on frame start");
|
||||||
|
|
||||||
// Update hud
|
// Update hud
|
||||||
root.hud.update();
|
root.hud.update();
|
||||||
|
|
||||||
// Main rendering order
|
// Main rendering order
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
if (this.root.camera.getIsMapOverlayActive()) {
|
if (this.root.camera.getIsMapOverlayActive()) {
|
||||||
// Map overview
|
// Map overview
|
||||||
root.map.drawOverlay(params);
|
root.map.drawOverlay(params);
|
||||||
} else {
|
} else {
|
||||||
// Background (grid, resources, etc)
|
// Background (grid, resources, etc)
|
||||||
root.map.drawBackground(params);
|
root.map.drawBackground(params);
|
||||||
|
|
||||||
// Belt items
|
// Belt items
|
||||||
systems.belt.drawBeltItems(params);
|
systems.belt.drawBeltItems(params);
|
||||||
|
|
||||||
// Miner & Static map entities etc.
|
// Miner & Static map entities etc.
|
||||||
root.map.drawForeground(params);
|
root.map.drawForeground(params);
|
||||||
|
|
||||||
// HUB Overlay
|
// HUB Overlay
|
||||||
systems.hub.draw(params);
|
systems.hub.draw(params);
|
||||||
|
|
||||||
// Green wires overlay
|
// Green wires overlay
|
||||||
root.hud.parts.wiresOverlay.draw(params);
|
root.hud.parts.wiresOverlay.draw(params);
|
||||||
|
|
||||||
if (this.root.currentLayer === "wires") {
|
if (this.root.currentLayer === "wires") {
|
||||||
// Static map entities
|
// Static map entities
|
||||||
root.map.drawWiresForegroundLayer(params);
|
root.map.drawWiresForegroundLayer(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_IS_DEV) {
|
if (G_IS_DEV) {
|
||||||
root.map.drawStaticEntityDebugOverlays(params);
|
root.map.drawStaticEntityDebugOverlays(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.renderBeltPaths) {
|
if (G_IS_DEV && globalConfig.debug.renderBeltPaths) {
|
||||||
systems.belt.drawBeltPathDebug(params);
|
systems.belt.drawBeltPathDebug(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// END OF GAME CONTENT
|
// END OF GAME CONTENT
|
||||||
// -----
|
// -----
|
||||||
|
|
||||||
// Finally, draw the hud. Nothing should come after that
|
// Finally, draw the hud. Nothing should come after that
|
||||||
root.hud.draw(params);
|
root.hud.draw(params);
|
||||||
|
|
||||||
assert(context.globalAlpha === 1.0, "Global alpha not 1 on frame end before restore");
|
assert(context.globalAlpha === 1.0, "Global alpha not 1 on frame end before restore");
|
||||||
|
|
||||||
// Restore to screen space
|
// Restore to screen space
|
||||||
context.restore();
|
context.restore();
|
||||||
|
|
||||||
// Restore parameters
|
// Restore parameters
|
||||||
params.zoomLevel = 1;
|
params.zoomLevel = 1;
|
||||||
params.desiredAtlasScale = ORIGINAL_SPRITE_SCALE;
|
params.desiredAtlasScale = ORIGINAL_SPRITE_SCALE;
|
||||||
params.visibleRect = new Rectangle(0, 0, this.root.gameWidth, this.root.gameHeight);
|
params.visibleRect = new Rectangle(0, 0, this.root.gameWidth, this.root.gameHeight);
|
||||||
if (G_IS_DEV && globalConfig.debug.testClipping) {
|
if (G_IS_DEV && globalConfig.debug.testClipping) {
|
||||||
params.visibleRect = params.visibleRect.expandedInAllDirections(-200);
|
params.visibleRect = params.visibleRect.expandedInAllDirections(-200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw overlays, those are screen space
|
// Draw overlays, those are screen space
|
||||||
root.hud.drawOverlays(params);
|
root.hud.drawOverlays(params);
|
||||||
|
|
||||||
assert(context.globalAlpha === 1.0, "context.globalAlpha not 1 on frame end");
|
assert(context.globalAlpha === 1.0, "context.globalAlpha not 1 on frame end");
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.simulateSlowRendering) {
|
if (G_IS_DEV && globalConfig.debug.simulateSlowRendering) {
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
for (let i = 0; i < 1e8; ++i) {
|
for (let i = 0; i < 1e8; ++i) {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
if (Math.random() > 0.95) {
|
if (Math.random() > 0.95) {
|
||||||
console.log(sum);
|
console.log(sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.showAtlasInfo) {
|
if (G_IS_DEV && globalConfig.debug.showAtlasInfo) {
|
||||||
context.font = "13px GameFont";
|
context.font = "13px GameFont";
|
||||||
context.fillStyle = "blue";
|
context.fillStyle = "blue";
|
||||||
context.fillText(
|
context.fillText(
|
||||||
"Atlas: " +
|
"Atlas: " +
|
||||||
desiredAtlasScale +
|
desiredAtlasScale +
|
||||||
" / Zoom: " +
|
" / Zoom: " +
|
||||||
round2Digits(zoomLevel) +
|
round2Digits(zoomLevel) +
|
||||||
" / Effective Zoom: " +
|
" / Effective Zoom: " +
|
||||||
round2Digits(effectiveZoomLevel),
|
round2Digits(effectiveZoomLevel),
|
||||||
20,
|
20,
|
||||||
600
|
600
|
||||||
);
|
);
|
||||||
|
|
||||||
const stats = this.root.buffers.getStats();
|
const stats = this.root.buffers.getStats();
|
||||||
context.fillText(
|
context.fillText(
|
||||||
"Buffers: " +
|
"Buffers: " +
|
||||||
stats.rootKeys +
|
stats.rootKeys +
|
||||||
" root keys, " +
|
" root keys, " +
|
||||||
stats.subKeys +
|
stats.subKeys +
|
||||||
" sub keys / buffers / VRAM: " +
|
" sub keys / buffers / VRAM: " +
|
||||||
round2Digits(stats.vramBytes / (1024 * 1024)) +
|
round2Digits(stats.vramBytes / (1024 * 1024)) +
|
||||||
" MB",
|
" MB",
|
||||||
|
|
||||||
20,
|
20,
|
||||||
620
|
620
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.testClipping) {
|
if (G_IS_DEV && globalConfig.debug.testClipping) {
|
||||||
context.strokeStyle = "red";
|
context.strokeStyle = "red";
|
||||||
context.lineWidth = 1;
|
context.lineWidth = 1;
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.rect(200, 200, this.root.gameWidth - 400, this.root.gameHeight - 400);
|
context.rect(200, 200, this.root.gameWidth - 400, this.root.gameHeight - 400);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ export class HUDStatistics extends BaseHUDPart {
|
|||||||
*/
|
*/
|
||||||
setSorted(sorted) {
|
setSorted(sorted) {
|
||||||
this.sorted = sorted;
|
this.sorted = sorted;
|
||||||
this.dialogInner.setAttribute("data-sorted", sorted);
|
this.dialogInner.setAttribute("data-sorted", String(sorted));
|
||||||
if (this.visible) {
|
if (this.visible) {
|
||||||
this.rerenderFull();
|
this.rerenderFull();
|
||||||
}
|
}
|
||||||
@ -201,7 +201,16 @@ export class HUDStatistics extends BaseHUDPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pinnedShapes = this.root.hud.parts.pinnedShapes;
|
||||||
|
|
||||||
entries.sort((a, b) => {
|
entries.sort((a, b) => {
|
||||||
|
const aPinned = pinnedShapes.isShapePinned(a[0]);
|
||||||
|
const bPinned = pinnedShapes.isShapePinned(b[0]);
|
||||||
|
|
||||||
|
if (aPinned !== bPinned) {
|
||||||
|
return aPinned ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Sort by shape key for some consistency
|
// Sort by shape key for some consistency
|
||||||
if (!this.sorted || b[1] == a[1]) {
|
if (!this.sorted || b[1] == a[1]) {
|
||||||
return b[0].localeCompare(a[0]);
|
return b[0].localeCompare(a[0]);
|
||||||
|
@ -74,6 +74,11 @@ export class HUDShapeStatisticsHandle {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.element.classList.toggle(
|
||||||
|
"pinned",
|
||||||
|
this.root.hud.parts.pinnedShapes.isShapePinned(this.definition.getHash())
|
||||||
|
);
|
||||||
|
|
||||||
switch (dataSource) {
|
switch (dataSource) {
|
||||||
case enumAnalyticsDataSource.stored: {
|
case enumAnalyticsDataSource.stored: {
|
||||||
this.counter.innerText = formatBigNumber(
|
this.counter.innerText = formatBigNumber(
|
||||||
|
Loading…
Reference in New Issue
Block a user