2020-08-29 07:35:14 +00:00
|
|
|
import { globalConfig } from "../../core/config";
|
|
|
|
|
import { DrawParameters } from "../../core/draw_parameters";
|
|
|
|
|
import { createLogger } from "../../core/logging";
|
|
|
|
|
import { Rectangle } from "../../core/rectangle";
|
2020-09-18 16:32:53 +00:00
|
|
|
import { StaleAreaDetector } from "../../core/stale_area_detector";
|
2020-08-29 08:45:38 +00:00
|
|
|
import { enumDirection, enumDirectionToVector } from "../../core/vector";
|
2020-08-29 07:35:14 +00:00
|
|
|
import { BaseItem } from "../base_item";
|
2020-09-18 16:32:53 +00:00
|
|
|
import { BeltComponent } from "../components/belt";
|
|
|
|
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
2020-08-29 07:35:14 +00:00
|
|
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
|
|
|
|
import { Entity } from "../entity";
|
|
|
|
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
|
|
|
|
import { MapChunkView } from "../map_chunk_view";
|
|
|
|
|
|
|
|
|
|
const logger = createLogger("systems/ejector");
|
|
|
|
|
|
|
|
|
|
export class ItemEjectorSystem extends GameSystemWithFilter {
|
|
|
|
|
constructor(root) {
|
|
|
|
|
super(root, [ItemEjectorComponent]);
|
|
|
|
|
|
2020-09-18 16:32:53 +00:00
|
|
|
this.staleAreaDetector = new StaleAreaDetector({
|
|
|
|
|
root: this.root,
|
|
|
|
|
name: "item-ejector",
|
|
|
|
|
recomputeMethod: this.recomputeArea.bind(this),
|
|
|
|
|
});
|
2020-08-29 07:35:14 +00:00
|
|
|
|
2020-09-18 16:32:53 +00:00
|
|
|
this.staleAreaDetector.recomputeOnComponentsChanged(
|
|
|
|
|
[ItemEjectorComponent, ItemAcceptorComponent, BeltComponent],
|
|
|
|
|
1
|
|
|
|
|
);
|
2020-08-29 07:35:14 +00:00
|
|
|
|
2020-09-18 16:32:53 +00:00
|
|
|
this.root.signals.postLoadHook.add(this.recomputeCacheFull, this);
|
2020-08-29 07:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-18 16:32:53 +00:00
|
|
|
* Recomputes an area after it changed
|
|
|
|
|
* @param {Rectangle} area
|
2020-08-29 07:35:14 +00:00
|
|
|
*/
|
2020-09-18 16:32:53 +00:00
|
|
|
recomputeArea(area) {
|
|
|
|
|
/** @type {Set<number>} */
|
|
|
|
|
const seenUids = new Set();
|
|
|
|
|
for (let x = 0; x < area.w; ++x) {
|
|
|
|
|
for (let y = 0; y < area.h; ++y) {
|
|
|
|
|
const tileX = area.x + x;
|
|
|
|
|
const tileY = area.y + y;
|
|
|
|
|
// @NOTICE: Item ejector currently only supports regular layer
|
|
|
|
|
const contents = this.root.map.getLayerContentXY(tileX, tileY, "regular");
|
|
|
|
|
if (contents && contents.components.ItemEjector) {
|
|
|
|
|
if (!seenUids.has(contents.uid)) {
|
|
|
|
|
seenUids.add(contents.uid);
|
|
|
|
|
this.recomputeSingleEntityCache(contents);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-29 07:35:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-18 16:32:53 +00:00
|
|
|
* Recomputes the whole cache after the game has loaded
|
2020-08-29 07:35:14 +00:00
|
|
|
*/
|
2020-09-18 16:32:53 +00:00
|
|
|
recomputeCacheFull() {
|
|
|
|
|
logger.log("Full cache recompute in post load hook");
|
|
|
|
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
|
|
|
|
const entity = this.allEntities[i];
|
|
|
|
|
this.recomputeSingleEntityCache(entity);
|
2020-08-29 07:35:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Entity} entity
|
|
|
|
|
*/
|
|
|
|
|
recomputeSingleEntityCache(entity) {
|
|
|
|
|
const ejectorComp = entity.components.ItemEjector;
|
|
|
|
|
const staticComp = entity.components.StaticMapEntity;
|
|
|
|
|
|
|
|
|
|
for (let slotIndex = 0; slotIndex < ejectorComp.slots.length; ++slotIndex) {
|
|
|
|
|
const ejectorSlot = ejectorComp.slots[slotIndex];
|
|
|
|
|
|
|
|
|
|
// Clear the old cache.
|
|
|
|
|
ejectorSlot.cachedDestSlot = null;
|
|
|
|
|
ejectorSlot.cachedTargetEntity = null;
|
|
|
|
|
ejectorSlot.cachedBeltPath = null;
|
|
|
|
|
|
|
|
|
|
// Figure out where and into which direction we eject items
|
|
|
|
|
const ejectSlotWsTile = staticComp.localTileToWorld(ejectorSlot.pos);
|
|
|
|
|
const ejectSlotWsDirection = staticComp.localDirectionToWorld(ejectorSlot.direction);
|
|
|
|
|
const ejectSlotWsDirectionVector = enumDirectionToVector[ejectSlotWsDirection];
|
|
|
|
|
const ejectSlotTargetWsTile = ejectSlotWsTile.add(ejectSlotWsDirectionVector);
|
|
|
|
|
|
|
|
|
|
// Try to find the given acceptor component to take the item
|
|
|
|
|
// Since there can be cross layer dependencies, check on all layers
|
|
|
|
|
const targetEntities = this.root.map.getLayersContentsMultipleXY(
|
|
|
|
|
ejectSlotTargetWsTile.x,
|
|
|
|
|
ejectSlotTargetWsTile.y
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < targetEntities.length; ++i) {
|
|
|
|
|
const targetEntity = targetEntities[i];
|
|
|
|
|
|
|
|
|
|
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
|
|
|
|
const targetBeltComp = targetEntity.components.Belt;
|
|
|
|
|
|
|
|
|
|
// Check for belts (special case)
|
|
|
|
|
if (targetBeltComp) {
|
|
|
|
|
const beltAcceptingDirection = targetStaticComp.localDirectionToWorld(enumDirection.top);
|
|
|
|
|
if (ejectSlotWsDirection === beltAcceptingDirection) {
|
|
|
|
|
ejectorSlot.cachedTargetEntity = targetEntity;
|
|
|
|
|
ejectorSlot.cachedBeltPath = targetBeltComp.assignedPath;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for item acceptors
|
|
|
|
|
const targetAcceptorComp = targetEntity.components.ItemAcceptor;
|
|
|
|
|
if (!targetAcceptorComp) {
|
|
|
|
|
// Entity doesn't accept items
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const matchingSlot = targetAcceptorComp.findMatchingSlot(
|
|
|
|
|
targetStaticComp.worldToLocalTile(ejectSlotTargetWsTile),
|
|
|
|
|
targetStaticComp.worldDirectionToLocal(ejectSlotWsDirection)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!matchingSlot) {
|
|
|
|
|
// No matching slot found
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A slot can always be connected to one other slot only
|
|
|
|
|
ejectorSlot.cachedTargetEntity = targetEntity;
|
|
|
|
|
ejectorSlot.cachedDestSlot = matchingSlot;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update() {
|
2020-09-18 16:32:53 +00:00
|
|
|
this.staleAreaDetector.update();
|
2020-08-29 07:35:14 +00:00
|
|
|
|
|
|
|
|
// Precompute effective belt speed
|
|
|
|
|
let progressGrowth = 2 * this.root.dynamicTickrate.deltaSeconds;
|
|
|
|
|
|
|
|
|
|
if (G_IS_DEV && globalConfig.debug.instantBelts) {
|
|
|
|
|
progressGrowth = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go over all cache entries
|
|
|
|
|
for (let i = 0; i < this.allEntities.length; ++i) {
|
|
|
|
|
const sourceEntity = this.allEntities[i];
|
|
|
|
|
const sourceEjectorComp = sourceEntity.components.ItemEjector;
|
|
|
|
|
|
|
|
|
|
const slots = sourceEjectorComp.slots;
|
|
|
|
|
for (let j = 0; j < slots.length; ++j) {
|
|
|
|
|
const sourceSlot = slots[j];
|
|
|
|
|
const item = sourceSlot.item;
|
|
|
|
|
if (!item) {
|
|
|
|
|
// No item available to be ejected
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Advance items on the slot
|
|
|
|
|
sourceSlot.progress = Math.min(
|
|
|
|
|
1,
|
|
|
|
|
sourceSlot.progress +
|
|
|
|
|
progressGrowth *
|
|
|
|
|
this.root.hubGoals.getBeltBaseSpeed() *
|
|
|
|
|
globalConfig.itemSpacingOnBelts
|
|
|
|
|
);
|
|
|
|
|
|
2020-08-29 09:08:30 +00:00
|
|
|
if (G_IS_DEV && globalConfig.debug.disableEjectorProcessing) {
|
|
|
|
|
sourceSlot.progress = 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 07:35:14 +00:00
|
|
|
// Check if we are still in the process of ejecting, can't proceed then
|
|
|
|
|
if (sourceSlot.progress < 1.0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if we are ejecting to a belt path
|
|
|
|
|
const destPath = sourceSlot.cachedBeltPath;
|
|
|
|
|
if (destPath) {
|
|
|
|
|
// Try passing the item over
|
|
|
|
|
if (destPath.tryAcceptItem(item)) {
|
|
|
|
|
sourceSlot.item = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Always stop here, since there can *either* be a belt path *or*
|
|
|
|
|
// a slot
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the target acceptor can actually accept this item
|
2020-09-18 16:18:38 +00:00
|
|
|
const destEntity = sourceSlot.cachedTargetEntity;
|
2020-08-29 07:35:14 +00:00
|
|
|
const destSlot = sourceSlot.cachedDestSlot;
|
|
|
|
|
if (destSlot) {
|
2020-09-18 16:18:38 +00:00
|
|
|
const targetAcceptorComp = destEntity.components.ItemAcceptor;
|
2020-08-29 07:35:14 +00:00
|
|
|
if (!targetAcceptorComp.canAcceptItem(destSlot.index, item)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to hand over the item
|
2020-09-18 16:18:38 +00:00
|
|
|
if (this.tryPassOverItem(item, destEntity, destSlot.index)) {
|
2020-08-29 07:35:14 +00:00
|
|
|
// Handover successful, clear slot
|
2020-09-19 08:34:46 +00:00
|
|
|
if (!this.root.app.settings.getAllSettings().simplifiedBelts) {
|
Mod Support - 1.5.0 Update (#1361)
* initial modloader draft
* modloader features
* Refactor mods to use signals
* Add support for modifying and registering new transltions
* Minor adjustments
* Support for string building ids for mods
* Initial support for adding new buildings
* Refactor how mods are loaded to resolve circular dependencies and prepare for future mod loading
* Lazy Load mods to make sure all dependencies are loaded
* Expose all exported members automatically to mods
* Fix duplicate exports
* Allow loading mods from standalone
* update changelog
* Fix mods folder incorrect path
* Fix modloading in standalone
* Fix sprites not getting replaced, update demo mod
* Load dev mod via raw loader
* Improve mod developing so mods are directly ready to be deployed, load mods from local file server
* Proper mods ui
* Allow mods to register game systems and draw stuff
* Change mods path
* Fix sprites not loading
* Minor adjustments, closes #1333
* Add support for loading atlases via mods
* Add support for loading mods from external sources in DEV
* Add confirmation when loading mods
* Fix circular dependency
* Minor Keybindings refactor, add support for keybindings to mods, add support for dialogs to mods
* Add some mod signals
* refactor game loading states
* Make shapez exports global
* Start to make mods safer
* Refactor file system electron event handling
* Properly isolate electron renderer process
* Update to latest electron
* Show errors when loading mods
* Update confirm dialgo
* Minor restructure, start to add mod examples
* Allow adding custom themesw
* Add more examples and allow defining custom item processor operations
* Add interface to register new buildings
* Fixed typescript type errors (#1335)
* Refactor building registry, make it easier for mods to add new buildings
* Allow overriding existing methods
* Add more examples and more features
* More mod examples
* Make mod loading simpler
* Add example how to add custom drawings
* Remove unused code
* Minor modloader adjustments
* Support for rotation variants in mods (was broken previously)
* Allow mods to replace builtin sub shapes
* Add helper methods to extend classes
* Fix menu bar on mac os
* Remember window state
* Add support for paste signals
* Add example how to add custom components and systems
* Support for mod settings
* Add example for adding a new item type
* Update class extensions
* Minor adjustments
* Fix typo
* Add notification blocks mod example
* Add small tutorial
* Update readme
* Add better instructions
* Update JSDoc for Replacing Methods (#1336)
* upgraded types for overriding methods
* updated comments
Co-authored-by: Edward Badel <you@example.com>
* Direction lock now indicates when there is a building inbetween
* Fix mod examples
* Fix linter error
* Game state register (#1341)
* Added a gamestate register helper
Added a gamestate register helper
* Update mod_interface.js
* export build options
* Fix runBeforeMethod and runAfterMethod
* Minor game system code cleanup
* Belt path drawing optimization
* Fix belt path optimization
* Belt drawing improvements, again
* Do not render belts in statics disabled view
* Allow external URL to load more than one mod (#1337)
* Allow external URL to load more than one mod
Instead of loading the text returned from the remote server, load a JSON object with a `mods` field, containing strings of all the mods. This lets us work on more than one mod at a time or without separate repos. This will break tooling such as `create-shapezio-mod` though.
* Update modloader.js
* Prettier fixes
* Added link to create-shapezio-mod npm page (#1339)
Added link to create-shapezio-mod npm page: https://www.npmjs.com/package/create-shapezio-mod
* allow command line switch to load more than one mod (#1342)
* Fixed class handle type (#1345)
* Fixed class handle type
* Fixed import game state
* Minor adjustments
* Refactor item acceptor to allow only single direction slots
* Allow specifying minimumGameVersion
* Add sandbox example
* Replaced concatenated strings with template literals (#1347)
* Mod improvements
* Make wired pins component optional on the storage
* Fix mod examples
* Bind `this` for method overriding JSDoc (#1352)
* fix entity debugger reaching HTML elements (#1353)
* Store mods in savegame and show warning when it differs
* Closes #1357
* Fix All Shapez Exports Being Const (#1358)
* Allowed setting of variables inside webpack modules
* remove console log
* Fix stringification of things inside of eval
Co-authored-by: Edward Badel <you@example.com>
* Fix building placer intersection warning
* Add example for storing data in the savegame
* Fix double painter bug (#1349)
* Add example on how to extend builtin buildings
* update readme
* Disable steam achievements when playing with mods
* Update translations
Co-authored-by: Thomas (DJ1TJOO) <44841260+DJ1TJOO@users.noreply.github.com>
Co-authored-by: Bagel03 <70449196+Bagel03@users.noreply.github.com>
Co-authored-by: Edward Badel <you@example.com>
Co-authored-by: Emerald Block <69981203+EmeraldBlock@users.noreply.github.com>
Co-authored-by: saile515 <63782477+saile515@users.noreply.github.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
2022-02-01 15:35:49 +00:00
|
|
|
targetAcceptorComp.onItemAccepted(destSlot.index, destSlot.slot.direction, item);
|
2020-09-19 08:34:46 +00:00
|
|
|
}
|
2020-08-29 07:35:14 +00:00
|
|
|
sourceSlot.item = null;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {BaseItem} item
|
|
|
|
|
* @param {Entity} receiver
|
|
|
|
|
* @param {number} slotIndex
|
|
|
|
|
*/
|
|
|
|
|
tryPassOverItem(item, receiver, slotIndex) {
|
|
|
|
|
// Try figuring out how what to do with the item
|
2020-10-08 17:47:27 +00:00
|
|
|
// @TODO: Kinda hacky. How to solve this properly? Don't want to go through inheritance hell.
|
2020-08-29 07:35:14 +00:00
|
|
|
|
|
|
|
|
const beltComp = receiver.components.Belt;
|
|
|
|
|
if (beltComp) {
|
|
|
|
|
const path = beltComp.assignedPath;
|
|
|
|
|
assert(path, "belt has no path");
|
|
|
|
|
if (path.tryAcceptItem(item)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Belt can have nothing else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
Puzzle DLC (#1172)
* Puzzle mode (#1135)
* Add mode button to main menu
* [WIP] Add mode menu. Add factory-based gameMode creation
* Add savefile migration, serialize, deserialize
* Add hidden HUD elements, zone, and zoom, boundary constraints
* Clean up lint issues
* Add building, HUD exclusion, building exclusion, and refactor
- [WIP] Add ConstantProducer building that combines ConstantSignal
and ItemProducer functionality. Currently using temp assets.
- Add pre-placement check to the zone
- Use Rectangles for zone and boundary
- Simplify zone drawing
- Account for exclusion in savegame data
- [WIP] Add puzzle play and edit buttons in puzzle mode menu
* [WIP] Add building, component, and systems for producing and
accepting user-specified items and checking goal criteria
* Add ingame puzzle mode UI elements
- Add minimal menus in puzzle mode for back, next navigation
- Add lower menu for changing zone dimenensions
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
* Performance optimizations (#1154)
* 1.3.1 preparations
* Minor fixes, update translations
* Fix achievements not working
* Lots of belt optimizations, ~15% performance boost
* Puzzle mode, part 1
* Puzzle mode, part 2
* Fix missing import
* Puzzle mode, part 3
* Fix typo
* Puzzle mode, part 4
* Puzzle Mode fixes: Correct zone restrictions and more (#1155)
* Hide Puzzle Editor Controls in regular game mode, fix typo
* Disallow shrinking zone if there are buildings
* Fix multi-tile buildings for shrinking
* Puzzle mode, Refactor hud
* Puzzle mode
* Fixed typo in latest puzzle commit (#1156)
* Allow completing puzzles
* Puzzle mode, almost done
* Bump version to 1.4.0
* Fixes
* [puzzle] Prevent pipette cheats (miners, emitters) (#1158)
* Puzzle mode, almost done
* Allow clearing belts with 'B'
* Multiple users for the puzzle dlc
* Bump api key
* Minor adjustments
* Update
* Minor fixes
* Fix throughput
* Fix belts
* Minor puzzle adjustments
* New difficulty
* Minor puzzle improvements
* Fix belt path
* Update translations
* Added a button to return to the menu after a puzzle is completed (#1170)
* added another button to return to the menu
* improved menu return
* fixed continue button to not go back to menu
* [Puzzle] Added ability to lock buildings in the puzzle editor! (#1164)
* initial test
* tried to get it to work
* added icon
* added test exclusion
* reverted css
* completed flow for building locking
* added lock option
* finalized look and changed locked building to same sprite
* removed unused art
* added clearing every goal acceptor on lock to prevent creating impossible puzzles
* heavily improved validation and prevented autocompletion
* validation only checks every 100 ticks to improve performance
* validation only checks every 100 ticks to improve performance
* removed clearing goal acceptors as it isn't needed because of validation
* Add soundtrack, puzzle dlc fixes
Co-authored-by: Greg Considine <gconsidine@users.noreply.github.com>
Co-authored-by: dengr1065 <dengr1065@gmail.com>
Co-authored-by: Sense101 <67970865+Sense101@users.noreply.github.com>
2021-05-23 14:32:05 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// NOTICE ! THIS CODE IS DUPLICATED IN THE BELT PATH FOR PERFORMANCE REASONS
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2020-08-29 07:35:14 +00:00
|
|
|
const itemProcessorComp = receiver.components.ItemProcessor;
|
|
|
|
|
if (itemProcessorComp) {
|
|
|
|
|
// Check for potential filters
|
|
|
|
|
if (!this.root.systemMgr.systems.itemProcessor.checkRequirements(receiver, item, slotIndex)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Its an item processor ..
|
|
|
|
|
if (itemProcessorComp.tryTakeItem(item, slotIndex)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Item processor can have nothing else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const undergroundBeltComp = receiver.components.UndergroundBelt;
|
|
|
|
|
if (undergroundBeltComp) {
|
|
|
|
|
// Its an underground belt. yay.
|
|
|
|
|
if (
|
|
|
|
|
undergroundBeltComp.tryAcceptExternalItem(
|
|
|
|
|
item,
|
|
|
|
|
this.root.hubGoals.getUndergroundBeltBaseSpeed()
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Underground belt can have nothing else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const storageComp = receiver.components.Storage;
|
|
|
|
|
if (storageComp) {
|
|
|
|
|
// It's a storage
|
|
|
|
|
if (storageComp.canAcceptItem(item)) {
|
|
|
|
|
storageComp.takeItem(item);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Storage can't have anything else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 17:30:04 +00:00
|
|
|
const filterComp = receiver.components.Filter;
|
|
|
|
|
if (filterComp) {
|
|
|
|
|
// It's a filter! Unfortunately the filter has to know a lot about it's
|
|
|
|
|
// surrounding state and components, so it can't be within the component itself.
|
|
|
|
|
if (this.root.systemMgr.systems.filter.tryAcceptItem(receiver, slotIndex, item)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 07:35:14 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {DrawParameters} parameters
|
|
|
|
|
* @param {MapChunkView} chunk
|
|
|
|
|
*/
|
|
|
|
|
drawChunk(parameters, chunk) {
|
2020-09-19 08:34:46 +00:00
|
|
|
if (this.root.app.settings.getAllSettings().simplifiedBelts) {
|
|
|
|
|
// Disabled in potato mode
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 07:35:14 +00:00
|
|
|
const contents = chunk.containedEntitiesByLayer.regular;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < contents.length; ++i) {
|
|
|
|
|
const entity = contents[i];
|
|
|
|
|
const ejectorComp = entity.components.ItemEjector;
|
|
|
|
|
if (!ejectorComp) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const staticComp = entity.components.StaticMapEntity;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < ejectorComp.slots.length; ++i) {
|
|
|
|
|
const slot = ejectorComp.slots[i];
|
|
|
|
|
const ejectedItem = slot.item;
|
|
|
|
|
|
|
|
|
|
if (!ejectedItem) {
|
|
|
|
|
// No item
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 16:18:38 +00:00
|
|
|
if (!ejectorComp.renderFloatingItems && !slot.cachedTargetEntity) {
|
|
|
|
|
// Not connected to any building
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 18:24:39 +00:00
|
|
|
// Limit the progress to the maximum available space on the next belt (also see #1000)
|
|
|
|
|
let progress = slot.progress;
|
|
|
|
|
const nextBeltPath = slot.cachedBeltPath;
|
|
|
|
|
if (nextBeltPath) {
|
2020-12-09 09:41:49 +00:00
|
|
|
/*
|
|
|
|
|
If you imagine the track between the center of the building and the center of the first belt as
|
|
|
|
|
a range from 0 to 1:
|
|
|
|
|
|
|
|
|
|
Building Belt
|
|
|
|
|
| X | X |
|
|
|
|
|
| 0...................1 |
|
|
|
|
|
|
|
|
|
|
And for example the first item on belt has a distance of 0.4 to the beginning of the belt:
|
|
|
|
|
|
|
|
|
|
Building Belt
|
|
|
|
|
| X | X |
|
|
|
|
|
| 0...................1 |
|
|
|
|
|
^ item
|
|
|
|
|
|
|
|
|
|
Then the space towards this first item is always 0.5 (the distance from the center of the building to the beginning of the belt)
|
|
|
|
|
PLUS the spacing to the item, so in this case 0.5 + 0.4 = 0.9:
|
|
|
|
|
|
|
|
|
|
Building Belt
|
|
|
|
|
| X | X |
|
|
|
|
|
| 0...................1 |
|
|
|
|
|
^ item @ 0.9
|
|
|
|
|
|
|
|
|
|
Since items must not get clashed, we need to substract some spacing (lets assume it is 0.6, exact value see globalConfig.itemSpacingOnBelts),
|
|
|
|
|
So we do 0.9 - globalConfig.itemSpacingOnBelts = 0.3
|
|
|
|
|
|
|
|
|
|
Building Belt
|
|
|
|
|
| X | X |
|
|
|
|
|
| 0...................1 |
|
|
|
|
|
^ ^ item @ 0.9
|
|
|
|
|
^ max progress = 0.3
|
|
|
|
|
|
|
|
|
|
Because now our range actually only goes to the end of the building, and not towards the center of the building, we need to multiply
|
|
|
|
|
all values by 2:
|
|
|
|
|
|
|
|
|
|
Building Belt
|
|
|
|
|
| X | X |
|
|
|
|
|
| 0.........1.........2 |
|
|
|
|
|
^ ^ item @ 1.8
|
|
|
|
|
^ max progress = 0.6
|
|
|
|
|
|
|
|
|
|
And that's it! If you summarize the calculations from above into a formula, you get the one below.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const maxProgress =
|
|
|
|
|
(0.5 + nextBeltPath.spacingToFirstItem - globalConfig.itemSpacingOnBelts) * 2;
|
|
|
|
|
progress = Math.min(maxProgress, progress);
|
2020-12-07 18:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Skip if the item would barely be visible
|
|
|
|
|
if (progress < 0.05) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-29 07:35:14 +00:00
|
|
|
const realPosition = staticComp.localTileToWorld(slot.pos);
|
|
|
|
|
if (!chunk.tileSpaceRectangle.containsPoint(realPosition.x, realPosition.y)) {
|
|
|
|
|
// Not within this chunk
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const realDirection = staticComp.localDirectionToWorld(slot.direction);
|
|
|
|
|
const realDirectionVector = enumDirectionToVector[realDirection];
|
|
|
|
|
|
2020-12-07 18:24:39 +00:00
|
|
|
const tileX = realPosition.x + 0.5 + realDirectionVector.x * 0.5 * progress;
|
|
|
|
|
const tileY = realPosition.y + 0.5 + realDirectionVector.y * 0.5 * progress;
|
2020-08-29 07:35:14 +00:00
|
|
|
|
|
|
|
|
const worldX = tileX * globalConfig.tileSize;
|
|
|
|
|
const worldY = tileY * globalConfig.tileSize;
|
|
|
|
|
|
|
|
|
|
ejectedItem.drawItemCenteredClipped(
|
|
|
|
|
worldX,
|
|
|
|
|
worldY,
|
|
|
|
|
parameters,
|
|
|
|
|
globalConfig.defaultItemDiameter
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|