Improved typing of creature properties
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { PropTask } from '/imports/api/engine/action/tasks/Task';
|
||||
import TaskResult from 'imports/api/engine/action/tasks/TaskResult';
|
||||
import TaskResult from '/imports/api/engine/action/tasks/TaskResult';
|
||||
import getPropertyTitle from '/imports/api/utility/getPropertyTitle';
|
||||
import { findLast, filter, difference, intersection } from 'lodash';
|
||||
import { getPropertiesOfType, getPropertyAncestors } from '/imports/api/engine/loadCreatures';
|
||||
@@ -53,9 +53,10 @@ export default async function applyBuffRemoverProperty(
|
||||
} else {
|
||||
// Get all the buffs targeted by tags
|
||||
const allBuffs = getPropertiesOfType(targetId, 'buff');
|
||||
const targetedBuffs = filter(allBuffs, buff => {
|
||||
const targetedBuffs = filter(allBuffs, (buff): boolean => {
|
||||
if (buff.inactive) return false;
|
||||
if (buffRemoverMatchTags(prop, buff)) return true;
|
||||
return false;
|
||||
});
|
||||
// Remove the buffs
|
||||
if (prop.removeAll) {
|
||||
@@ -65,7 +66,7 @@ export default async function applyBuffRemoverProperty(
|
||||
});
|
||||
} else {
|
||||
// Sort in reverse order
|
||||
targetedBuffs.sort((a, b) => b.order - a.order);
|
||||
targetedBuffs.sort((a, b) => b.left - a.left);
|
||||
// Remove the one with the highest order
|
||||
const buff = targetedBuffs[0];
|
||||
if (buff) {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { debounce } from 'lodash';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures';
|
||||
import CreatureVariables from '/imports/api/creature/creatures/CreatureVariables';
|
||||
import CreatureProperties, { CreatureProperty } from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import CreatureProperties, { CreatureProperty, CreaturePropertyByType } from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import computeCreature from './computeCreature';
|
||||
import { getFilter } from '/imports/api/parenting/parentingFunctions';
|
||||
import { ComputedPropertyTypeMap } from '../properties/Property.type';
|
||||
|
||||
const COMPUTE_DEBOUNCE_TIME = 100; // ms
|
||||
export const loadedCreatures: Map<string, LoadedCreature> = new Map(); // creatureId => {creature, properties, etc.}
|
||||
@@ -81,13 +82,13 @@ export function getProperties(creatureId: string): CreatureProperty[] {
|
||||
return props;
|
||||
}
|
||||
|
||||
export function getPropertiesOfType(creatureId, propType) {
|
||||
export function getPropertiesOfType<T extends keyof ComputedPropertyTypeMap>(creatureId, propType: T): CreaturePropertyByType<T>[] {
|
||||
const creature = loadedCreatures.get(creatureId);
|
||||
if (creature) {
|
||||
const props = Array.from(creature.properties.values())
|
||||
.filter(prop => !prop.removed && prop.type === propType)
|
||||
.sort((a, b) => a.left - b.left);
|
||||
return EJSON.clone(props);
|
||||
return EJSON.clone(props) as unknown as CreaturePropertyByType<T>[];
|
||||
}
|
||||
// console.time(`Cache miss on creature properties: ${creatureId}`)
|
||||
const props = CreatureProperties.find({
|
||||
@@ -98,7 +99,7 @@ export function getPropertiesOfType(creatureId, propType) {
|
||||
sort: { left: 1 },
|
||||
}).fetch();
|
||||
// console.timeEnd(`Cache miss on creature properties: ${creatureId}`);
|
||||
return props;
|
||||
return props as unknown as CreaturePropertyByType<T>[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user