1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
This commit is contained in:
Emerald Block 2022-06-01 15:10:17 +02:00 committed by GitHub
commit 33e84c6053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 812 additions and 792 deletions

View File

@ -334,7 +334,7 @@ export function waitNextFrame() {
* @returns {number} * @returns {number}
*/ */
export function round1Digit(n) { export function round1Digit(n) {
return Math.floor(n * 10.0) / 10.0; return Math.round(n * 10.0) / 10.0;
} }
/** /**
@ -343,7 +343,7 @@ export function round1Digit(n) {
* @returns {number} * @returns {number}
*/ */
export function round2Digits(n) { export function round2Digits(n) {
return Math.floor(n * 100.0) / 100.0; return Math.round(n * 100.0) / 100.0;
} }
/** /**
@ -352,7 +352,7 @@ export function round2Digits(n) {
* @returns {number} * @returns {number}
*/ */
export function round3Digits(n) { export function round3Digits(n) {
return Math.floor(n * 1000.0) / 1000.0; return Math.round(n * 1000.0) / 1000.0;
} }
/** /**
@ -361,7 +361,7 @@ export function round3Digits(n) {
* @returns {number} * @returns {number}
*/ */
export function round4Digits(n) { export function round4Digits(n) {
return Math.floor(n * 10000.0) / 10000.0; return Math.round(n * 10000.0) / 10000.0;
} }
/** /**
@ -542,6 +542,15 @@ export function formatSeconds(secs) {
} }
} }
/**
* Formats a number like 2.51 to "2.51"
* @param {number} speed
* @param {string=} separator The decimal separator for numbers like 50.1 (separator='.')
*/
export function formatNumber(speed, separator = T.global.decimalSeparator) {
return speed.toString().replace(".", separator);
}
/** /**
* Formats a number like 2.51 to "2.5" * Formats a number like 2.51 to "2.5"
* @param {number} speed * @param {number} speed
@ -563,7 +572,7 @@ export function formatItemsPerSecond(speed, double = false, separator = T.global
? T.ingame.buildingPlacement.infoTexts.oneItemPerSecond ? T.ingame.buildingPlacement.infoTexts.oneItemPerSecond
: T.ingame.buildingPlacement.infoTexts.itemsPerSecond.replace( : T.ingame.buildingPlacement.infoTexts.itemsPerSecond.replace(
"<x>", "<x>",
round2Digits(speed).toString().replace(".", separator) speed.toString().replace(".", separator)
)) + (double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "") )) + (double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "")
); );
} }

View File

@ -55,11 +55,12 @@ export class HubGoals extends BasicSerializableObject {
for (const upgradeId in upgrades) { for (const upgradeId in upgrades) {
const tiers = upgrades[upgradeId]; const tiers = upgrades[upgradeId];
const level = this.upgradeLevels[upgradeId] || 0; const level = this.upgradeLevels[upgradeId] || 0;
let totalImprovement = 1; let totalImprovement = 10;
for (let i = 0; i < level; ++i) { for (let i = 0; i < level; ++i) {
totalImprovement += tiers[i].improvement; totalImprovement += tiers[i].improvement;
} }
this.upgradeImprovements[upgradeId] = totalImprovement; this.upgradeImprovements[upgradeId] =
(this.upgradeImprovementsExact[upgradeId] = totalImprovement) / 10;
} }
// Compute current goal // Compute current goal
@ -100,11 +101,18 @@ export class HubGoals extends BasicSerializableObject {
*/ */
this.upgradeImprovements = {}; this.upgradeImprovements = {};
/**
* Stores 10x the improvements for all upgrades, to be exact
* @type {Object<string, number>}
*/
this.upgradeImprovementsExact = {};
// Reset levels first // Reset levels first
const upgrades = this.root.gameMode.getUpgrades(); const upgrades = this.root.gameMode.getUpgrades();
for (const key in upgrades) { for (const key in upgrades) {
this.upgradeLevels[key] = 0; this.upgradeLevels[key] = 0;
this.upgradeImprovements[key] = 1; this.upgradeImprovements[key] = 1;
this.upgradeImprovementsExact[key] = 10;
} }
this.computeNextGoal(); this.computeNextGoal();
@ -347,7 +355,8 @@ export class HubGoals extends BasicSerializableObject {
} }
this.upgradeLevels[upgradeId] = (this.upgradeLevels[upgradeId] || 0) + 1; this.upgradeLevels[upgradeId] = (this.upgradeLevels[upgradeId] || 0) + 1;
this.upgradeImprovements[upgradeId] += tierData.improvement; this.upgradeImprovements[upgradeId] =
(this.upgradeImprovementsExact[upgradeId] += tierData.improvement) / 10;
this.root.signals.upgradePurchased.dispatch(upgradeId); this.root.signals.upgradePurchased.dispatch(upgradeId);

View File

@ -1,5 +1,5 @@
import { globalConfig } from "../../../core/config"; import { globalConfig } from "../../../core/config";
import { formatItemsPerSecond, round2Digits } from "../../../core/utils"; import { formatItemsPerSecond, round4Digits } from "../../../core/utils";
import { Vector } from "../../../core/vector"; import { Vector } from "../../../core/vector";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { Entity } from "../../entity"; import { Entity } from "../../entity";
@ -69,7 +69,7 @@ export class HUDMinerHighlight extends BaseHUDPart {
parameters.context.fill(); parameters.context.fill();
} }
const throughput = round2Digits(connectedEntities.length * this.root.hubGoals.getMinerBaseSpeed()); const throughput = round4Digits(connectedEntities.length * this.root.hubGoals.getMinerBaseSpeed());
const maxThroughput = this.root.hubGoals.getBeltBaseSpeed(); const maxThroughput = this.root.hubGoals.getBeltBaseSpeed();
@ -84,7 +84,7 @@ export class HUDMinerHighlight extends BaseHUDPart {
parameters.context.beginRoundedRect( parameters.context.beginRoundedRect(
tooltipLocation.x + 5 * scale, tooltipLocation.x + 5 * scale,
tooltipLocation.y - 3 * scale, tooltipLocation.y - 3 * scale,
(isCapped ? 100 : 65) * scale, (isCapped ? 100 : 75) * scale,
(isCapped ? 45 : 30) * scale, (isCapped ? 45 : 30) * scale,
2 2
); );

View File

@ -98,11 +98,12 @@ export class HUDSandboxController extends BaseHUDPart {
); );
// Compute improvement // Compute improvement
let improvement = 1; let improvement = 10;
for (let i = 0; i < this.root.hubGoals.upgradeLevels[id]; ++i) { for (let i = 0; i < this.root.hubGoals.upgradeLevels[id]; ++i) {
improvement += upgradeTiers[i].improvement; improvement += upgradeTiers[i].improvement;
} }
this.root.hubGoals.upgradeImprovements[id] = improvement; this.root.hubGoals.upgradeImprovements[id] =
(this.root.hubGoals.upgradeImprovementsExact[id] = improvement) / 10;
this.root.signals.upgradePurchased.dispatch(id); this.root.signals.upgradePurchased.dispatch(id);
this.root.hud.signals.notification.dispatch( this.root.hud.signals.notification.dispatch(
"Upgrade '" + id + "' is now at tier " + (this.root.hubGoals.upgradeLevels[id] + 1), "Upgrade '" + id + "' is now at tier " + (this.root.hubGoals.upgradeLevels[id] + 1),

View File

@ -1,6 +1,6 @@
import { ClickDetector } from "../../../core/click_detector"; import { ClickDetector } from "../../../core/click_detector";
import { InputReceiver } from "../../../core/input_receiver"; import { InputReceiver } from "../../../core/input_receiver";
import { formatBigNumber, getRomanNumber, makeDiv } from "../../../core/utils"; import { formatBigNumber, formatNumber, getRomanNumber, makeDiv } from "../../../core/utils";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper"; import { KeyActionMapper, KEYMAPPINGS } from "../../key_action_mapper";
import { BaseHUDPart } from "../base_hud_part"; import { BaseHUDPart } from "../base_hud_part";
@ -91,15 +91,15 @@ export class HUDShop extends BaseHUDPart {
// Max level // Max level
handle.elemDescription.innerText = T.ingame.shop.maximumLevel.replace( handle.elemDescription.innerText = T.ingame.shop.maximumLevel.replace(
"<currentMult>", "<currentMult>",
formatBigNumber(currentTierMultiplier) formatNumber(currentTierMultiplier)
); );
continue; continue;
} }
// Set description // Set description
handle.elemDescription.innerText = T.shopUpgrades[upgradeId].description handle.elemDescription.innerText = T.shopUpgrades[upgradeId].description
.replace("<currentMult>", formatBigNumber(currentTierMultiplier)) .replace("<currentMult>", formatNumber(currentTierMultiplier))
.replace("<newMult>", formatBigNumber(currentTierMultiplier + tierHandle.improvement)); .replace("<newMult>", formatNumber(currentTierMultiplier + tierHandle.improvement / 10));
tierHandle.required.forEach(({ shape, amount }) => { tierHandle.required.forEach(({ shape, amount }) => {
const container = makeDiv(handle.elemRequirements, null, ["requirement"]); const container = makeDiv(handle.elemRequirements, null, ["requirement"]);

View File

@ -79,7 +79,8 @@ function generateUpgrades(limitedVersion = false) {
return upgradesCache[limitedVersion]; return upgradesCache[limitedVersion];
} }
const fixedImprovements = [0.5, 0.5, 1, 1, 2, 1, 1]; // 10x actual amount so all numbers are exact
const fixedImprovements = [5, 5, 10, 10, 20, 10, 10];
const numEndgameUpgrades = limitedVersion ? 0 : 1000 - fixedImprovements.length - 1; const numEndgameUpgrades = limitedVersion ? 0 : 1000 - fixedImprovements.length - 1;
function generateInfiniteUnlocks() { function generateInfiniteUnlocks() {
@ -96,13 +97,13 @@ function generateUpgrades(limitedVersion = false) {
// Fill in endgame upgrades // Fill in endgame upgrades
for (let i = 0; i < numEndgameUpgrades; ++i) { for (let i = 0; i < numEndgameUpgrades; ++i) {
if (i < 20) { if (i < 20) {
fixedImprovements.push(0.1); fixedImprovements.push(1);
} else if (i < 50) { } else if (i < 50) {
fixedImprovements.push(0.05); fixedImprovements.push(0.5);
} else if (i < 100) { } else if (i < 100) {
fixedImprovements.push(0.025); fixedImprovements.push(0.25);
} else { } else {
fixedImprovements.push(0.0125); fixedImprovements.push(0.125);
} }
} }