Add ESLint, Add worker utils

This commit is contained in:
uwap 2025-12-21 09:48:53 +01:00
parent a64f40b6cc
commit c026087af1
29 changed files with 3042 additions and 1734 deletions

53
src/Actions/Util.ts Normal file
View file

@ -0,0 +1,53 @@
import { Action, Fail } from "../Actions/Action";
export const notNull
= <T>(x: T | null | undefined, f: (y: T) => Action): Action => {
if (x == null) {
return Fail;
}
return f(x);
};
export const closestTowerToFill = (pos: RoomPosition): StructureTower | null =>
pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: structure => structure.structureType === STRUCTURE_TOWER
&& (structure as StructureTower).store
.getFreeCapacity(RESOURCE_ENERGY) > 0,
});
export const closestExtensionToFill
= (pos: RoomPosition): StructureExtension | null =>
pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: structure => structure.structureType === STRUCTURE_EXTENSION
&& (structure as StructureExtension).store
.getFreeCapacity(RESOURCE_ENERGY) > 0,
});
export const closestContainerWithEnergy
= (pos: RoomPosition): StructureContainer | null =>
pos.findClosestByRange(FIND_STRUCTURES, {
filter: structure => structure.structureType === STRUCTURE_CONTAINER
&& (structure as StructureContainer).store
.getUsedCapacity(RESOURCE_ENERGY) > 0,
});
export const closestContainerToFill
= (pos: RoomPosition): StructureContainer | null =>
pos.findClosestByRange(FIND_STRUCTURES, {
filter: structure => structure.structureType === STRUCTURE_CONTAINER
&& (structure as StructureContainer).store
.getFreeCapacity(RESOURCE_ENERGY) > 0,
});
export const closestStorageWithResource
= (pos: RoomPosition, t: ResourceConstant): StructureStorage | null =>
pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: structure => structure.structureType === STRUCTURE_STORAGE
&& (structure as StructureStorage).store
.getUsedCapacity(t) > 0,
});
export const closestStorageToFill
= (pos: RoomPosition, t: ResourceConstant): StructureStorage | null =>
pos.findClosestByRange(FIND_MY_STRUCTURES, {
filter: structure => structure.structureType === STRUCTURE_STORAGE
&& (structure as StructureStorage).store.getFreeCapacity(t) > 0,
});