mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Make shapes truthy
This commit is contained in:
@@ -104,5 +104,8 @@ export default {
|
||||
// Renders information about wire networks
|
||||
// renderWireNetworkInfos: true,
|
||||
// -----------------------------------------------------------------------------------
|
||||
// Disables ejector animations and processing
|
||||
// disableEjectorProcessing: true,
|
||||
// -----------------------------------------------------------------------------------
|
||||
/* dev:end */
|
||||
};
|
||||
|
||||
@@ -62,9 +62,27 @@ export const BOOL_FALSE_SINGLETON = new BooleanItem(0);
|
||||
export const BOOL_TRUE_SINGLETON = new BooleanItem(1);
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns whether the item is Boolean and TRUE
|
||||
* @param {BaseItem} item
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isTrueItem(item) {
|
||||
return item && item.getItemType() === "boolean" && /** @type {BooleanItem} */ (item).value;
|
||||
return item && item.getItemType() === "boolean" && !!(/** @type {BooleanItem} */ (item).value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the item is truthy
|
||||
* @param {BaseItem} item
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isTruthyItem(item) {
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item.getItemType() === "boolean") {
|
||||
return !!(/** @type {BooleanItem} */ (item).value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,9 +31,24 @@ export class BeltReaderSystem extends GameSystemWithFilter {
|
||||
: BOOL_FALSE_SINGLETON;
|
||||
|
||||
if (now - readerComp.lastThroughputComputation > 0.5) {
|
||||
// Compute throughput
|
||||
readerComp.lastThroughputComputation = now;
|
||||
readerComp.lastThroughput =
|
||||
readerComp.lastItemTimes.length / globalConfig.readerAnalyzeIntervalSeconds;
|
||||
|
||||
let throughput = 0;
|
||||
if (readerComp.lastItemTimes.length < 2) {
|
||||
throughput = 0;
|
||||
} else {
|
||||
let averageSpacing = 0;
|
||||
let averageSpacingNum = 0;
|
||||
for (let i = 0; i < readerComp.lastItemTimes.length - 1; ++i) {
|
||||
averageSpacing += readerComp.lastItemTimes[i + 1] - readerComp.lastItemTimes[i];
|
||||
++averageSpacingNum;
|
||||
}
|
||||
|
||||
throughput = 1 / (averageSpacing / averageSpacingNum);
|
||||
}
|
||||
|
||||
readerComp.lastThroughput = throughput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +222,10 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
||||
globalConfig.itemSpacingOnBelts
|
||||
);
|
||||
|
||||
if (G_IS_DEV && globalConfig.debug.disableEjectorProcessing) {
|
||||
sourceSlot.progress = 1.0;
|
||||
}
|
||||
|
||||
// Check if we are still in the process of ejecting, can't proceed then
|
||||
if (sourceSlot.progress < 1.0) {
|
||||
continue;
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "../components/item_processor";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { BOOL_TRUE_SINGLETON, isTrueItem, BooleanItem } from "../items/boolean_item";
|
||||
import { BOOL_TRUE_SINGLETON, isTruthyItem } from "../items/boolean_item";
|
||||
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
|
||||
@@ -103,7 +103,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
|
||||
// Check the network value at the given slot
|
||||
const network = pinsComp.slots[slotIndex - 1].linkedNetwork;
|
||||
const slotIsEnabled = network && isTrueItem(network.currentValue);
|
||||
const slotIsEnabled = network && isTruthyItem(network.currentValue);
|
||||
if (!slotIsEnabled) {
|
||||
return false;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
: null;
|
||||
|
||||
// If there is no "1" on that slot, don't paint there
|
||||
if (!isTrueItem(networkValue)) {
|
||||
if (!isTruthyItem(networkValue)) {
|
||||
slotStatus.push(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { globalConfig } from "../../core/config";
|
||||
import { Loader } from "../../core/loader";
|
||||
import { smoothPulse } from "../../core/utils";
|
||||
import { smoothPulse, round4Digits } from "../../core/utils";
|
||||
import { enumItemProcessorRequirements, enumItemProcessorTypes } from "../components/item_processor";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystem } from "../game_system";
|
||||
import { isTrueItem } from "../items/boolean_item";
|
||||
import { isTruthyItem } from "../items/boolean_item";
|
||||
import { MapChunkView } from "../map_chunk_view";
|
||||
|
||||
export class ItemProcessorOverlaysSystem extends GameSystem {
|
||||
@@ -88,7 +88,10 @@ export class ItemProcessorOverlaysSystem extends GameSystem {
|
||||
parameters.context.textAlign = "center";
|
||||
parameters.context.font = "bold 10px GameFont";
|
||||
parameters.context.fillText(
|
||||
"" + Math.round(readerComp.lastThroughput * 10) / 10,
|
||||
"" +
|
||||
(G_IS_DEV
|
||||
? round4Digits(readerComp.lastThroughput)
|
||||
: Math.round(readerComp.lastThroughput * 10) / 10),
|
||||
(staticComp.origin.x + 0.5) * globalConfig.tileSize,
|
||||
(staticComp.origin.y + 0.62) * globalConfig.tileSize
|
||||
);
|
||||
@@ -116,7 +119,7 @@ export class ItemProcessorOverlaysSystem extends GameSystem {
|
||||
if (network && network.currentValue) {
|
||||
anySlotConnected = true;
|
||||
|
||||
if (isTrueItem(network.currentValue) || !drawIfFalse) {
|
||||
if (isTruthyItem(network.currentValue) || !drawIfFalse) {
|
||||
// No need to draw anything
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { enumColors } from "../colors";
|
||||
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
|
||||
import { enumPinSlotType } from "../components/wired_pins";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTrueItem } from "../items/boolean_item";
|
||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON, isTrueItem, isTruthyItem } from "../items/boolean_item";
|
||||
import { COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
@@ -76,7 +76,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
*/
|
||||
compute_AND(parameters) {
|
||||
assert(parameters.length === 2, "bad parameter count for AND");
|
||||
return isTrueItem(parameters[0]) && isTrueItem(parameters[1])
|
||||
return isTruthyItem(parameters[0]) && isTruthyItem(parameters[1])
|
||||
? BOOL_TRUE_SINGLETON
|
||||
: BOOL_FALSE_SINGLETON;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
* @returns {BaseItem}
|
||||
*/
|
||||
compute_NOT(parameters) {
|
||||
return isTrueItem(parameters[0]) ? BOOL_FALSE_SINGLETON : BOOL_TRUE_SINGLETON;
|
||||
return isTruthyItem(parameters[0]) ? BOOL_FALSE_SINGLETON : BOOL_TRUE_SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
*/
|
||||
compute_XOR(parameters) {
|
||||
assert(parameters.length === 2, "bad parameter count for XOR");
|
||||
return isTrueItem(parameters[0]) ^ isTrueItem(parameters[1])
|
||||
return isTruthyItem(parameters[0]) ^ isTruthyItem(parameters[1])
|
||||
? BOOL_TRUE_SINGLETON
|
||||
: BOOL_FALSE_SINGLETON;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
*/
|
||||
compute_OR(parameters) {
|
||||
assert(parameters.length === 2, "bad parameter count for OR");
|
||||
return isTrueItem(parameters[0]) || isTrueItem(parameters[1])
|
||||
return isTruthyItem(parameters[0]) || isTruthyItem(parameters[1])
|
||||
? BOOL_TRUE_SINGLETON
|
||||
: BOOL_FALSE_SINGLETON;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ export class LogicGateSystem extends GameSystemWithFilter {
|
||||
const value = parameters[1];
|
||||
|
||||
// pass through item
|
||||
if (isTrueItem(flag)) {
|
||||
if (isTruthyItem(flag)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user