mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
97 lines
3.0 KiB
JavaScript
97 lines
3.0 KiB
JavaScript
import { GameSystemWithFilter } from "../game_system_with_filter";
|
|
import { HubComponent } from "../components/hub";
|
|
import { DrawParameters } from "../../core/draw_parameters";
|
|
import { Entity } from "../entity";
|
|
import { formatBigNumber } from "../../core/utils";
|
|
import { enumHubGoalRewardToString } from "../tutorial_goals";
|
|
import { Loader } from "../../core/loader";
|
|
|
|
export class HubSystem extends GameSystemWithFilter {
|
|
constructor(root) {
|
|
super(root, [HubComponent]);
|
|
|
|
this.hubSprite = Loader.getSprite("sprites/buildings/hub.png");
|
|
}
|
|
|
|
draw(parameters) {
|
|
this.forEachMatchingEntityOnScreen(parameters, this.drawEntity.bind(this));
|
|
}
|
|
|
|
update() {
|
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
|
const entity = this.allEntities[i];
|
|
|
|
const hubComponent = entity.components.Hub;
|
|
|
|
const queue = hubComponent.definitionsToAnalyze;
|
|
for (let k = 0; k < queue.length; ++k) {
|
|
const definition = queue[k];
|
|
this.root.hubGoals.handleDefinitionDelivered(definition);
|
|
}
|
|
|
|
hubComponent.definitionsToAnalyze = [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {DrawParameters} parameters
|
|
* @param {Entity} entity
|
|
*/
|
|
drawEntity(parameters, entity) {
|
|
const context = parameters.context;
|
|
const staticComp = entity.components.StaticMapEntity;
|
|
|
|
const pos = staticComp.getTileSpaceBounds().getCenter().toWorldSpace();
|
|
|
|
// Background
|
|
staticComp.drawSpriteOnFullEntityBounds(parameters, this.hubSprite, 2.2);
|
|
|
|
const definition = this.root.hubGoals.currentGoal.definition;
|
|
|
|
definition.draw(pos.x - 25, pos.y - 10, parameters, 40);
|
|
|
|
const goals = this.root.hubGoals.currentGoal;
|
|
|
|
const textOffsetX = 2;
|
|
const textOffsetY = -6;
|
|
|
|
// Deliver count
|
|
const delivered = this.root.hubGoals.getCurrentGoalDelivered();
|
|
|
|
if (delivered > 9999) {
|
|
context.font = "bold 16px GameFont";
|
|
} else if (delivered > 999) {
|
|
context.font = "bold 20px GameFont";
|
|
} else {
|
|
context.font = "bold 25px GameFont";
|
|
}
|
|
context.fillStyle = "#64666e";
|
|
context.textAlign = "left";
|
|
context.fillText("" + formatBigNumber(delivered), pos.x + textOffsetX, pos.y + textOffsetY);
|
|
|
|
// Required
|
|
|
|
context.font = "13px GameFont";
|
|
|
|
context.fillStyle = "#a4a6b0";
|
|
context.fillText(
|
|
"/ " + formatBigNumber(goals.required),
|
|
pos.x + textOffsetX,
|
|
pos.y + textOffsetY + 13
|
|
);
|
|
|
|
// Reward
|
|
context.font = "bold 11px GameFont";
|
|
context.fillStyle = "#fd0752";
|
|
context.textAlign = "center";
|
|
context.fillText(enumHubGoalRewardToString[goals.reward].toUpperCase(), pos.x, pos.y + 46);
|
|
|
|
// Level
|
|
context.font = "bold 11px GameFont";
|
|
context.fillStyle = "#fff";
|
|
context.fillText("" + this.root.hubGoals.level, pos.x - 42, pos.y - 36);
|
|
|
|
context.textAlign = "left";
|
|
}
|
|
}
|