use Array.isArray instead of isArray

This commit is contained in:
jakub791 2023-05-04 12:48:20 +02:00
parent 867695cf71
commit f4b77e852d
7 changed files with 11 additions and 18 deletions

View file

@ -1,5 +1,4 @@
import { computed } from "vue"; import { computed } from "vue";
import { isArray } from "@vue/shared";
import Select from "components/fields/Select.vue"; import Select from "components/fields/Select.vue";
import AchievementComponent from "features/achievements/Achievement.vue"; import AchievementComponent from "features/achievements/Achievement.vue";
import { GenericDecorator } from "features/decorators/common"; import { GenericDecorator } from "features/decorators/common";
@ -272,7 +271,7 @@ export function createAchievement<T extends AchievementOptions>(
const requirements = [ const requirements = [
createVisibilityRequirement(genericAchievement), createVisibilityRequirement(genericAchievement),
createBooleanRequirement(() => !genericAchievement.earned.value), createBooleanRequirement(() => !genericAchievement.earned.value),
...(isArray(achievement.requirements) ...(Array.isArray(achievement.requirements)
? achievement.requirements ? achievement.requirements
: [achievement.requirements]) : [achievement.requirements])
]; ];

View file

@ -1,4 +1,3 @@
import { isArray } from "@vue/shared";
import ClickableComponent from "features/clickables/Clickable.vue"; import ClickableComponent from "features/clickables/Clickable.vue";
import { import {
Component, Component,
@ -157,7 +156,7 @@ export function createAction<T extends ActionOptions>(
} }
]; ];
const originalStyle = unref(style); const originalStyle = unref(style);
if (isArray(originalStyle)) { if (Array.isArray(originalStyle)) {
currStyle.push(...originalStyle); currStyle.push(...originalStyle);
} else if (originalStyle != null) { } else if (originalStyle != null) {
currStyle.push(originalStyle); currStyle.push(originalStyle);

View file

@ -1,4 +1,3 @@
import { isArray } from "@vue/shared";
import Toggle from "components/fields/Toggle.vue"; import Toggle from "components/fields/Toggle.vue";
import ChallengeComponent from "features/challenges/Challenge.vue"; import ChallengeComponent from "features/challenges/Challenge.vue";
import { GenericDecorator } from "features/decorators/common"; import { GenericDecorator } from "features/decorators/common";
@ -355,7 +354,7 @@ export function createActiveChallenge(
export function isAnyChallengeActive( export function isAnyChallengeActive(
challenges: GenericChallenge[] | Ref<GenericChallenge | null> challenges: GenericChallenge[] | Ref<GenericChallenge | null>
): Ref<boolean> { ): Ref<boolean> {
if (isArray(challenges)) { if (Array.isArray(challenges)) {
challenges = createActiveChallenge(challenges); challenges = createActiveChallenge(challenges);
} }
return computed(() => (challenges as Ref<GenericChallenge | null>).value != null); return computed(() => (challenges as Ref<GenericChallenge | null>).value != null);

View file

@ -1,4 +1,3 @@
import { isArray } from "@vue/shared";
import ClickableComponent from "features/clickables/Clickable.vue"; import ClickableComponent from "features/clickables/Clickable.vue";
import type { import type {
CoercableComponent, CoercableComponent,
@ -165,7 +164,7 @@ export function createRepeatable<T extends RepeatableOptions>(
visibility: Visibility.None visibility: Visibility.None
} as const; } as const;
const visibilityRequirement = createVisibilityRequirement(repeatable as GenericRepeatable); const visibilityRequirement = createVisibilityRequirement(repeatable as GenericRepeatable);
if (isArray(repeatable.requirements)) { if (Array.isArray(repeatable.requirements)) {
repeatable.requirements.unshift(visibilityRequirement); repeatable.requirements.unshift(visibilityRequirement);
repeatable.requirements.push(limitRequirement); repeatable.requirements.push(limitRequirement);
} else { } else {

View file

@ -1,4 +1,3 @@
import { isArray } from "@vue/shared";
import { GenericDecorator } from "features/decorators/common"; import { GenericDecorator } from "features/decorators/common";
import type { import type {
CoercableComponent, CoercableComponent,
@ -151,7 +150,7 @@ export function createUpgrade<T extends UpgradeOptions>(
}; };
const visibilityRequirement = createVisibilityRequirement(upgrade as GenericUpgrade); const visibilityRequirement = createVisibilityRequirement(upgrade as GenericUpgrade);
if (isArray(upgrade.requirements)) { if (Array.isArray(upgrade.requirements)) {
upgrade.requirements.unshift(visibilityRequirement); upgrade.requirements.unshift(visibilityRequirement);
} else { } else {
upgrade.requirements = [visibilityRequirement, upgrade.requirements]; upgrade.requirements = [visibilityRequirement, upgrade.requirements];

View file

@ -1,4 +1,3 @@
import { isArray } from "@vue/shared";
import { globalBus } from "game/events"; import { globalBus } from "game/events";
import type { GenericLayer } from "game/layers"; import type { GenericLayer } from "game/layers";
import { addingLayers, persistentRefs } from "game/layers"; import { addingLayers, persistentRefs } from "game/layers";
@ -342,7 +341,7 @@ globalBus.on("addLayer", (layer: GenericLayer, saveData: Record<string, unknown>
// Show warning for persistent values inside arrays // Show warning for persistent values inside arrays
// TODO handle arrays better // TODO handle arrays better
if (foundPersistentInChild) { if (foundPersistentInChild) {
if (isArray(value) && !isArray(obj)) { if (Array.isArray(value) && !Array.isArray(obj)) {
console.warn( console.warn(
"Found array that contains persistent values when adding layer. Keep in mind changing the order of elements in the array will mess with existing player saves.", "Found array that contains persistent values when adding layer. Keep in mind changing the order of elements in the array will mess with existing player saves.",
ProxyState in obj ProxyState in obj

View file

@ -1,4 +1,3 @@
import { isArray } from "@vue/shared";
import { import {
CoercableComponent, CoercableComponent,
isVisible, isVisible,
@ -241,7 +240,7 @@ export function createBooleanRequirement(
* @param requirements The 1+ requirements to check * @param requirements The 1+ requirements to check
*/ */
export function requirementsMet(requirements: Requirements): boolean { export function requirementsMet(requirements: Requirements): boolean {
if (isArray(requirements)) { if (Array.isArray(requirements)) {
return requirements.every(requirementsMet); return requirements.every(requirementsMet);
} }
const reqsMet = unref(requirements.requirementMet); const reqsMet = unref(requirements.requirementMet);
@ -253,7 +252,7 @@ export function requirementsMet(requirements: Requirements): boolean {
* @param requirements The 1+ requirements to check * @param requirements The 1+ requirements to check
*/ */
export function maxRequirementsMet(requirements: Requirements): DecimalSource { export function maxRequirementsMet(requirements: Requirements): DecimalSource {
if (isArray(requirements)) { if (Array.isArray(requirements)) {
return requirements.map(maxRequirementsMet).reduce(Decimal.min); return requirements.map(maxRequirementsMet).reduce(Decimal.min);
} }
const reqsMet = unref(requirements.requirementMet); const reqsMet = unref(requirements.requirementMet);
@ -271,13 +270,13 @@ export function maxRequirementsMet(requirements: Requirements): DecimalSource {
* @param amount The amount of levels earned to be displayed * @param amount The amount of levels earned to be displayed
*/ */
export function displayRequirements(requirements: Requirements, amount: DecimalSource = 1) { export function displayRequirements(requirements: Requirements, amount: DecimalSource = 1) {
if (isArray(requirements)) { if (Array.isArray(requirements)) {
requirements = requirements.filter(r => isVisible(r.visibility)); requirements = requirements.filter(r => isVisible(r.visibility));
if (requirements.length === 1) { if (requirements.length === 1) {
requirements = requirements[0]; requirements = requirements[0];
} }
} }
if (isArray(requirements)) { if (Array.isArray(requirements)) {
requirements = requirements.filter(r => "partialDisplay" in r); requirements = requirements.filter(r => "partialDisplay" in r);
const withCosts = requirements.filter(r => unref(r.requiresPay)); const withCosts = requirements.filter(r => unref(r.requiresPay));
const withoutCosts = requirements.filter(r => !unref(r.requiresPay)); const withoutCosts = requirements.filter(r => !unref(r.requiresPay));
@ -315,7 +314,7 @@ export function displayRequirements(requirements: Requirements, amount: DecimalS
* @param amount How many levels to pay for * @param amount How many levels to pay for
*/ */
export function payRequirements(requirements: Requirements, amount: DecimalSource = 1) { export function payRequirements(requirements: Requirements, amount: DecimalSource = 1) {
if (isArray(requirements)) { if (Array.isArray(requirements)) {
requirements.filter(r => unref(r.requiresPay)).forEach(r => r.pay?.(amount)); requirements.filter(r => unref(r.requiresPay)).forEach(r => r.pay?.(amount));
} else if (unref(requirements.requiresPay)) { } else if (unref(requirements.requiresPay)) {
requirements.pay?.(amount); requirements.pay?.(amount);