1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
tobspr_shapez.io/src/js/game/buildings/trash.js

221 lines
6.0 KiB
JavaScript
Raw Normal View History

2020-09-24 14:12:05 +00:00
import { generateMatrixRotations } from "../../core/utils";
2020-05-09 14:45:23 +00:00
import { enumDirection, Vector } from "../../core/vector";
Achievements (#1087) * [WIP] Add boilerplate for achievement implementation * Add config.local.template.js and rm cached copy of config.local.js * [WIP] Implement painting, cutting, rotating achievements (to log only) * [WIP] Refactor achievements, jsdoc fixes, add npm script - Refactor achievements to make use of Signals - Move implemented achievement interfaces to appropriate platform folders (SteamAchievements in currently in use in browser wrapper for testing) - Fix invalid jsdocs - Add dev-standalone script to package.json scripts * Add steam/greenworks IPC calls and optional private-artifact dependency * Include private artifacts in standalone builds * Uncomment appid include * [WIP] Add steam overlay fix, add hash to artifact dependency * Update electron, greenworks. Add task to add local config if not present * Add more achievements, refactor achievement code * Add receiver flexibility and more achievements - Add check to see if necessary to create achievement and add receiver - Add remove receiver functionality when achievement is unlocked * Add achievements and accommodations for switching states - Fix startup code to avoid clobbering achievements on state switch - Add a few more achievements * Add achievements, ids. Update names, keys for consistency * Add play time achievements * [WIP] Add more achievements * Add more achievements. Add bulk achievement check signal * [WIP] Add achievements. Start savefile migration * Add achievements. Add savefile migration * Remove superfluous achievement stat * Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
import { ACHIEVEMENTS } from "../../platform/achievement_provider";
2020-05-09 14:45:23 +00:00
import { ItemAcceptorComponent } from "../components/item_acceptor";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
2021-02-26 14:20:37 +00:00
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
2020-05-09 14:45:23 +00:00
import { GameRoot } from "../root";
import { enumHubGoalRewards } from "../tutorial_goals";
2020-05-20 13:51:06 +00:00
2020-09-24 14:12:05 +00:00
const overlayMatrix = generateMatrixRotations([1, 1, 0, 1, 1, 1, 0, 1, 1]);
2020-05-09 14:45:23 +00:00
export class MetaTrashBuilding extends MetaBuilding {
constructor() {
super("trash");
}
2021-02-26 14:20:37 +00:00
/**
* @param {string} variant
*/
getSilhouetteColor(variant) {
return MetaTrashBuilding.silhouetteColors[variant]();
2020-05-09 14:45:23 +00:00
}
2021-02-26 14:20:37 +00:00
/**
* @param {string} variant
*/
getIsRemovable(variant) {
return MetaTrashBuilding.isRemovable[variant]();
2020-05-20 13:51:06 +00:00
}
2021-02-26 14:20:37 +00:00
/**
* @param {string} variant
*/
getIsRotateable(variant) {
return MetaTrashBuilding.isRotateable[variant]();
2020-09-24 14:12:05 +00:00
}
2020-05-09 14:45:23 +00:00
/**
* @param {GameRoot} root
*/
2021-02-26 14:20:37 +00:00
getAvailableVariants(root) {
const variants = MetaTrashBuilding.avaibleVariants;
let available = [];
for (const variant in variants) {
if (variants[variant](root)) available.push(variant);
}
return available;
}
/**
* Returns the edit layer of the building
* @param {GameRoot} root
* @param {string} variant
* @returns {Layer}
*/
getLayer(root, variant) {
// @ts-ignore
return MetaTrashBuilding.layerByVariant[variant](root);
}
/**
* @param {string} variant
*/
getDimensions(variant) {
return MetaTrashBuilding.dimensions[variant]();
}
/**
* @param {string} variant
*/
getShowLayerPreview(variant) {
return MetaTrashBuilding.layerPreview[variant]();
}
/**
* @param {number} rotation
* @param {number} rotationVariant
* @param {string} variant
* @param {Entity} entity
* @returns {Array<number>|null}
*/
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
let matrices = MetaTrashBuilding.overlayMatrices[variant](entity, rotationVariant);
return matrices ? matrices[rotation] : null;
}
/**
* @param {string} variant
*/
getRenderPins(variant) {
return MetaTrashBuilding.renderPins[variant]();
2020-05-09 14:45:23 +00:00
}
Achievements (#1087) * [WIP] Add boilerplate for achievement implementation * Add config.local.template.js and rm cached copy of config.local.js * [WIP] Implement painting, cutting, rotating achievements (to log only) * [WIP] Refactor achievements, jsdoc fixes, add npm script - Refactor achievements to make use of Signals - Move implemented achievement interfaces to appropriate platform folders (SteamAchievements in currently in use in browser wrapper for testing) - Fix invalid jsdocs - Add dev-standalone script to package.json scripts * Add steam/greenworks IPC calls and optional private-artifact dependency * Include private artifacts in standalone builds * Uncomment appid include * [WIP] Add steam overlay fix, add hash to artifact dependency * Update electron, greenworks. Add task to add local config if not present * Add more achievements, refactor achievement code * Add receiver flexibility and more achievements - Add check to see if necessary to create achievement and add receiver - Add remove receiver functionality when achievement is unlocked * Add achievements and accommodations for switching states - Fix startup code to avoid clobbering achievements on state switch - Add a few more achievements * Add achievements, ids. Update names, keys for consistency * Add play time achievements * [WIP] Add more achievements * Add more achievements. Add bulk achievement check signal * [WIP] Add achievements. Start savefile migration * Add achievements. Add savefile migration * Remove superfluous achievement stat * Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
addAchievementReceiver(entity) {
if (!entity.root) {
return;
}
const itemProcessor = entity.components.ItemProcessor;
Achievements (#1087) * [WIP] Add boilerplate for achievement implementation * Add config.local.template.js and rm cached copy of config.local.js * [WIP] Implement painting, cutting, rotating achievements (to log only) * [WIP] Refactor achievements, jsdoc fixes, add npm script - Refactor achievements to make use of Signals - Move implemented achievement interfaces to appropriate platform folders (SteamAchievements in currently in use in browser wrapper for testing) - Fix invalid jsdocs - Add dev-standalone script to package.json scripts * Add steam/greenworks IPC calls and optional private-artifact dependency * Include private artifacts in standalone builds * Uncomment appid include * [WIP] Add steam overlay fix, add hash to artifact dependency * Update electron, greenworks. Add task to add local config if not present * Add more achievements, refactor achievement code * Add receiver flexibility and more achievements - Add check to see if necessary to create achievement and add receiver - Add remove receiver functionality when achievement is unlocked * Add achievements and accommodations for switching states - Fix startup code to avoid clobbering achievements on state switch - Add a few more achievements * Add achievements, ids. Update names, keys for consistency * Add play time achievements * [WIP] Add more achievements * Add more achievements. Add bulk achievement check signal * [WIP] Add achievements. Start savefile migration * Add achievements. Add savefile migration * Remove superfluous achievement stat * Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
const tryTakeItem = itemProcessor.tryTakeItem.bind(itemProcessor);
itemProcessor.tryTakeItem = () => {
const taken = tryTakeItem(...arguments);
if (taken) {
entity.root.signals.achievementCheck.dispatch(ACHIEVEMENTS.trash1000, 1);
}
return taken;
};
Achievements (#1087) * [WIP] Add boilerplate for achievement implementation * Add config.local.template.js and rm cached copy of config.local.js * [WIP] Implement painting, cutting, rotating achievements (to log only) * [WIP] Refactor achievements, jsdoc fixes, add npm script - Refactor achievements to make use of Signals - Move implemented achievement interfaces to appropriate platform folders (SteamAchievements in currently in use in browser wrapper for testing) - Fix invalid jsdocs - Add dev-standalone script to package.json scripts * Add steam/greenworks IPC calls and optional private-artifact dependency * Include private artifacts in standalone builds * Uncomment appid include * [WIP] Add steam overlay fix, add hash to artifact dependency * Update electron, greenworks. Add task to add local config if not present * Add more achievements, refactor achievement code * Add receiver flexibility and more achievements - Add check to see if necessary to create achievement and add receiver - Add remove receiver functionality when achievement is unlocked * Add achievements and accommodations for switching states - Fix startup code to avoid clobbering achievements on state switch - Add a few more achievements * Add achievements, ids. Update names, keys for consistency * Add play time achievements * [WIP] Add more achievements * Add more achievements. Add bulk achievement check signal * [WIP] Add achievements. Start savefile migration * Add achievements. Add savefile migration * Remove superfluous achievement stat * Update lock files, fix merge conflict
2021-03-10 06:33:39 +00:00
}
2020-05-09 14:45:23 +00:00
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
2021-02-26 14:20:37 +00:00
MetaTrashBuilding.setupEntityComponents.forEach(func => func(entity));
}
/**
* @param {Entity} entity
* @param {number} rotationVariant
* @param {string} variant
*/
updateVariants(entity, rotationVariant, variant) {
MetaTrashBuilding.componentVariations[variant].bind(this)(entity, rotationVariant);
2020-05-20 13:51:06 +00:00
}
2021-02-26 14:20:37 +00:00
2021-03-02 13:33:22 +00:00
static setupEntityComponents = [
entity =>
entity.addComponent(
new ItemAcceptorComponent({
slots: [
{
pos: new Vector(0, 0),
directions: [
enumDirection.top,
enumDirection.right,
enumDirection.bottom,
enumDirection.left,
],
},
],
})
),
entity =>
entity.addComponent(
new ItemProcessorComponent({
inputsPerCharge: 1,
processorType: enumItemProcessorTypes.trash,
})
),
function (entity) {
// @ts-ignore
this.addAchievementReceiver(entity);
},
2021-03-02 13:33:22 +00:00
];
static overlayMatrices = {
[defaultBuildingVariant]: (entity, rotationVariant) =>
generateMatrixRotations([1, 1, 0, 1, 1, 1, 0, 1, 1]),
};
static dimensions = {
[defaultBuildingVariant]: () => new Vector(1, 1),
};
static silhouetteColors = {
[defaultBuildingVariant]: () => "#ed1d5d",
};
static isRemovable = {
[defaultBuildingVariant]: () => true,
};
static isRotateable = {
[defaultBuildingVariant]: () => true,
};
static renderPins = {
[defaultBuildingVariant]: () => false,
};
static layerByVariant = {
[defaultBuildingVariant]: root => "regular",
};
static layerPreview = {
[defaultBuildingVariant]: () => null,
};
static avaibleVariants = {
[defaultBuildingVariant]: root =>
root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_cutter_and_trash),
};
static componentVariations = {
[defaultBuildingVariant]: (entity, rotationVariant) => {
entity.components.ItemAcceptor.setSlots([
{
pos: new Vector(0, 0),
directions: [
enumDirection.top,
enumDirection.right,
enumDirection.bottom,
enumDirection.left,
],
},
]);
entity.components.ItemProcessor.inputsPerCharge = 1;
entity.components.ItemProcessor.type = enumItemProcessorTypes.trash;
},
};
}