1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

[WIP] Fix achievements with unlock attempt on init. Fix lint

This commit is contained in:
Greg Considine 2021-03-10 11:37:46 -05:00
parent 4685f813e8
commit 454a844d28
6 changed files with 56 additions and 40 deletions

View File

@ -165,8 +165,10 @@ export class Blueprint {
} }
root.signals.bulkAchievementCheck.dispatch( root.signals.bulkAchievementCheck.dispatch(
ACHIEVEMENTS.placeBlueprint, count, ACHIEVEMENTS.placeBlueprint,
ACHIEVEMENTS.placeBp1000, count count,
ACHIEVEMENTS.placeBp1000,
count
); );
return count !== 0; return count !== 0;

View File

@ -43,7 +43,7 @@ export class MetaTrashBuilding extends MetaBuilding {
return; return;
} }
const itemProcessor = entity.components.ItemProcessor const itemProcessor = entity.components.ItemProcessor;
const tryTakeItem = itemProcessor.tryTakeItem.bind(itemProcessor); const tryTakeItem = itemProcessor.tryTakeItem.bind(itemProcessor);
itemProcessor.tryTakeItem = () => { itemProcessor.tryTakeItem = () => {
@ -54,7 +54,7 @@ export class MetaTrashBuilding extends MetaBuilding {
} }
return taken; return taken;
} };
} }
/** /**

2
src/js/globals.d.ts vendored
View File

@ -19,7 +19,7 @@ declare const G_BUILD_VERSION: string;
declare const G_ALL_UI_IMAGES: Array<string>; declare const G_ALL_UI_IMAGES: Array<string>;
declare const G_IS_RELEASE: boolean; declare const G_IS_RELEASE: boolean;
declare const G_CHINA_VERSION : boolean; declare const G_CHINA_VERSION: boolean;
// Polyfills // Polyfills
declare interface String { declare interface String {

View File

@ -2,11 +2,11 @@
import { Application } from "../application"; import { Application } from "../application";
import { Entity } from "../game/entity"; import { Entity } from "../game/entity";
import { GameRoot } from "../game/root"; import { GameRoot } from "../game/root";
import { ShapeDefinition } from "../game/shape_definition";
import { THEMES } from "../game/theme"; import { THEMES } from "../game/theme";
/* typehints:end */ /* typehints:end */
import { enumAnalyticsDataSource } from "../game/production_analytics"; import { enumAnalyticsDataSource } from "../game/production_analytics";
import { ShapeDefinition } from "../game/shape_definition";
import { ShapeItem } from "../game/items/shape_item"; import { ShapeItem } from "../game/items/shape_item";
import { globalConfig } from "../core/config"; import { globalConfig } from "../core/config";
@ -171,14 +171,8 @@ export class AchievementCollection {
isValid: this.isBelt500TilesValid, isValid: this.isBelt500TilesValid,
signal: "entityAdded", signal: "entityAdded",
}); });
this.add(ACHIEVEMENTS.blueprint100k, { this.add(ACHIEVEMENTS.blueprint100k, this.createBlueprintOptions(100000));
isValid: this.isBlueprint100kValid, this.add(ACHIEVEMENTS.blueprint1m, this.createBlueprintOptions(1000000));
signal: "shapeDelivered",
});
this.add(ACHIEVEMENTS.blueprint1m, {
isValid: this.isBlueprint1mValid,
signal: "shapeDelivered",
});
this.add(ACHIEVEMENTS.completeLvl26, this.createLevelOptions(26)); this.add(ACHIEVEMENTS.completeLvl26, this.createLevelOptions(26));
this.add(ACHIEVEMENTS.cutShape); this.add(ACHIEVEMENTS.cutShape);
this.add(ACHIEVEMENTS.darkMode, { this.add(ACHIEVEMENTS.darkMode, {
@ -271,14 +265,14 @@ export class AchievementCollection {
this.root.signals.bulkAchievementCheck.add(this.bulkUnlock, this); this.root.signals.bulkAchievementCheck.add(this.bulkUnlock, this);
for (let [key, achievement] of this.map.entries()) { for (let [key, achievement] of this.map.entries()) {
if (achievement.init) {
achievement.init();
}
if (achievement.signal) { if (achievement.signal) {
achievement.receiver = this.unlock.bind(this, key); achievement.receiver = this.unlock.bind(this, key);
this.root.signals[achievement.signal].add(achievement.receiver); this.root.signals[achievement.signal].add(achievement.receiver);
} }
if (achievement.init) {
achievement.init();
}
} }
if (!this.hasDefaultReceivers()) { if (!this.hasDefaultReceivers()) {
@ -419,8 +413,18 @@ export class AchievementCollection {
return item.getItemType() === ITEM_SHAPE && item.definition.getHash() === shape; return item.getItemType() === ITEM_SHAPE && item.definition.getHash() === shape;
} }
createBlueprintOptions(count) {
return {
init: ({ key }) => this.unlock(key, ShapeDefinition.fromShortKey(SHAPE_BP)),
isValid: definition =>
definition.cachedHash === SHAPE_BP && this.root.hubGoals.storedShapes[SHAPE_BP] >= count,
signal: "shapeDelivered",
};
}
createLevelOptions(level) { createLevelOptions(level) {
return { return {
init: ({ key }) => this.unlock(key, this.root.hubGoals.level),
isValid: currentLevel => currentLevel >= level, isValid: currentLevel => currentLevel >= level,
signal: "storyGoalCompleted", signal: "storyGoalCompleted",
}; };
@ -463,6 +467,7 @@ export class AchievementCollection {
createUpgradeOptions(tier) { createUpgradeOptions(tier) {
return { return {
init: ({ key }) => this.unlock(key),
isValid: () => this.hasAllUpgradesAtLeastAtTier(tier), isValid: () => this.hasAllUpgradesAtLeastAtTier(tier),
signal: "upgradePurchased", signal: "upgradePurchased",
}; };
@ -518,6 +523,13 @@ export class AchievementCollection {
return true; return true;
} }
/** @param {Achievement} achievement */
initLogoBefore18({ key }) {
const item = new ShapeItem(ShapeDefinition.fromShortKey(SHAPE_LOGO));
this.unlock(key, item);
}
/** @param {ShapeItem} item @returns {boolean} */ /** @param {ShapeItem} item @returns {boolean} */
isLogoBefore18Valid(item) { isLogoBefore18Valid(item) {
return this.root.hubGoals.level < 18 && this.isShape(item, SHAPE_LOGO); return this.root.hubGoals.level < 18 && this.isShape(item, SHAPE_LOGO);
@ -595,6 +607,11 @@ export class AchievementCollection {
return item.getItemType() === ITEM_SHAPE && item.definition.layers.length === 4; return item.getItemType() === ITEM_SHAPE && item.definition.layers.length === 4;
} }
/** @param {Achievement} achievement */
initStore100Unique({ key }) {
this.unlock(key);
}
/** @returns {boolean} */ /** @returns {boolean} */
isStore100UniqueValid() { isStore100UniqueValid() {
return Object.keys(this.root.hubGoals.storedShapes).length >= 100; return Object.keys(this.root.hubGoals.storedShapes).length >= 100;
@ -617,8 +634,10 @@ export class AchievementCollection {
return false; return false;
} }
initTrash1000() { /** @param {Achievement} achievement */
initTrash1000({ key }) {
if (Number(this.root.savegame.currentData.stats.trashedCount)) { if (Number(this.root.savegame.currentData.stats.trashedCount)) {
this.unlock(key, 0);
return; return;
} }

View File

@ -5,11 +5,7 @@ import { GameRoot } from "../../game/root";
import { createLogger } from "../../core/logging"; import { createLogger } from "../../core/logging";
import { getIPCRenderer } from "../../core/utils"; import { getIPCRenderer } from "../../core/utils";
import { import { ACHIEVEMENTS, AchievementCollection, AchievementProviderInterface } from "../achievement_provider";
ACHIEVEMENTS,
AchievementCollection,
AchievementProviderInterface
} from "../achievement_provider";
const logger = createLogger("achievements/steam"); const logger = createLogger("achievements/steam");
@ -111,16 +107,15 @@ export class SteamAchievementProvider extends AchievementProviderInterface {
this.ipc = getIPCRenderer(); this.ipc = getIPCRenderer();
return this.ipc.invoke("steam:is-initialized") return this.ipc.invoke("steam:is-initialized").then(initialized => {
.then(initialized => { this.initialized = initialized;
this.initialized = initialized;
if (!this.initialized) { if (!this.initialized) {
logger.warn("Steam failed to intialize. Achievements won't sync."); logger.warn("Steam failed to intialize. Achievements won't sync.");
} else { } else {
logger.log("Steam achievement provider initialized"); logger.log("Steam achievement provider initialized");
} }
}); });
} }
/** /**

View File

@ -23,8 +23,9 @@ export class PlatformWrapperImplElectron extends PlatformWrapperImplBrowser {
this.app.storage = new StorageImplElectron(this); this.app.storage = new StorageImplElectron(this);
this.app.achievementProvider = new SteamAchievementProvider(this.app); this.app.achievementProvider = new SteamAchievementProvider(this.app);
return this.initializeAchievementProvider() return this.initializeAchievementProvider().then(() =>
.then(() => PlatformWrapperInterface.prototype.initialize.call(this)); PlatformWrapperInterface.prototype.initialize.call(this)
);
} }
steamOverlayFixRedrawCanvas() { steamOverlayFixRedrawCanvas() {
@ -58,12 +59,11 @@ export class PlatformWrapperImplElectron extends PlatformWrapperImplBrowser {
} }
initializeAchievementProvider() { initializeAchievementProvider() {
return this.app.achievementProvider.initialize() return this.app.achievementProvider.initialize().catch(err => {
.catch(err => { logger.error("Failed to initialize achievement provider, disabling:", err);
logger.error("Failed to initialize achievement provider, disabling:", err);
this.app.achievementProvider = new NoAchievementProvider(this.app); this.app.achievementProvider = new NoAchievementProvider(this.app);
}); });
} }
getSupportsFullscreen() { getSupportsFullscreen() {