How to use the serializr.identifier function in serializr

To help you get started, we’ve selected a few serializr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ksandin / darkestdungeon / src / state / types / Quest.ts View on Github external
import {v4 as uuid} from 'uuid';
import {QuestMap} from './QuestMap';
import {QuestObjective} from './QuestObjective';
import {Item} from './Item';
import {autorun, computed, intercept, observable, reaction, when} from 'mobx';
import {QuestInfo} from './QuestInfo';
import {DungeonId} from './Dungeon';
import {MapLocationId} from './QuestRoom';
import {cap, moveItem, removeItem} from '../../lib/Helpers';
import {Hero} from './Hero';
import {Battler} from './Battler';

export type QuestId = string;

export class Quest extends Battler {
  @serializable(identifier()) id: QuestId = uuid();
  @serializable bonfires: number = 0;
  @serializable dungeonId: DungeonId;
  @serializable isEscapable?: boolean = true;

  @serializable(object(QuestMap))
  map: QuestMap;

  @serializable(object(QuestObjective))
  objective: QuestObjective = new QuestObjective();

  @serializable(list(object(Item)))
  rewards: Item[] = [];

  @serializable(list(object(Hero)))
  @observable
  party: Hero[] = [];
github ksandin / darkestdungeon / src / state / types / Profile.ts View on Github external
import {HeirloomType} from './ItemInfo';
import {BuildingInfoId} from './BuildingInfo';
import {Stats} from './Stats';
import {HeroResidentInfo} from './HeroResidentInfo';
import {Skill} from './Skill';
import {MapSize} from './QuestMap';
import {Difficulty} from './Difficulty';
import {v4 as uuid} from 'uuid';

export type ProfileId = string;

const nullEstateEvent = new EstateEvent();
nullEstateEvent.shown = true;

export class Profile {
  @serializable(identifier()) id: ProfileId = uuid();
  @serializable difficulty: Difficulty;
  @serializable @observable isNameFinalized: boolean = false;
  @serializable @observable name: string = '';
  @serializable(object(Path)) @observable path: Path;
  @serializable @observable week: number = 0;
  @serializable(date()) @observable dateOfLastSave: Date = new Date();
  @serializable @observable selectedQuestId?: QuestId;
  @serializable @observable gold: number = 0;
  @observable debt: number = 0;

  @computed get goldAfterDebt () { return this.gold - this.debt; }

  @serializable(object(EstateEvent))
  @observable
  estateEvent = nullEstateEvent;
github ksandin / darkestdungeon / src / state / types / BuildingUpgradeInfo.ts View on Github external
import {BuildingUpgradeEffects} from './BuildingUpgradeEffects';
import {identifier, serializable} from 'serializr';
import {HeirloomType} from './ItemInfo';
import {createId} from './BuildingInfo';

export class BuildingUpgradeInfo {
  @serializable(identifier()) id: string;

  cost = new Map();
  effects = new BuildingUpgradeEffects();

  get isFree () {
    let sum = 0;
    this.cost.forEach((amount, type) => sum += amount);
    return sum === 0;
  }

  get description () {
    const effectStrings = [];
    for (const key in this.effects) {
      const val = (this.effects as any)[key];
      if (val !== 0) {
        const sign = val > 0 ? '+' : '-';
github ksandin / darkestdungeon / src / state / types / SkillInfo.ts View on Github external
return new SkillTarget(spots, object);
  }

  static anyOne (type: SkillTargetObject) {
    return SkillTarget.oneOf([true, true, true, true], type);
  }

  static backline = [true, true, false, false];
  static frontline = [false, false, true, true];
  static midline = [false, true, true, false];
}

export type SkillId = string;

export class SkillInfo implements IStatsSource {
  @serializable(identifier()) id: SkillId;
  name: string;
  iconUrl: string;
  statsSourceName: string = 'Skill';
  stats: Stats = new Stats();

  position: [boolean, boolean, boolean, boolean] = [true, true, true, true];
  damageScale: number = 1;
  movement: number = 0;
  statusTurns: number = 3;
  target: SkillTarget;
  buff: TurnStats;

  canUse (actor: Character, allies: Character[], enemies: Character[]) {
    allies = forceLength(allies, 4);
    enemies = forceLength(enemies, 4);
    const actorPosition = allies.indexOf(actor);
github nathanstitt / mobx-decorated-models / dist / build.module.js View on Github external
identifier: function identifier$$1() {
        return identifier();
    },
    field: function field() {
github ksandin / darkestdungeon / src / state / types / StatInfo.ts View on Github external
import {identifier, serializable} from 'serializr';

export class StatInfo {
  @serializable(identifier()) id: string;

  constructor (
    public shortName: string,
    public longName: string = shortName,
    public isPercentage: boolean = false

  ) {
    this.id = shortName;
  }

  public static lookup = new Map();
  static declare (shortName: string, longName: string, isPercentage?: boolean) {
    const id = shortName;
    let info = StatInfo.lookup.get(id);
    if (info) {
      return info;
github ksandin / darkestdungeon / src / state / types / ItemInfo.ts View on Github external
Armor = 'A',
  Trinket = 'T',
  Treasure = 'TR',
  Consumable = 'C',
  Heirloom = 'H'
}

export enum HeirloomType {
  Bust,
  Portrait,
  Deed,
  Crest
}

export class ItemInfo {
  @serializable(identifier()) id: string;

  name: string = '[single name]';
  pluralName: string = '[plural name]';
  iconUrl?: string;
  itemUrl?: string;
  description: string = '';
  type: ItemType = ItemType.Consumable;
  heirloomType?: HeirloomType;
  value: number = 0;
  sellValueScale: number = 1;
  stats: Stats = new Stats();
  resetHunger: boolean;
  removeBuffs: boolean;
  offsetLight: number = 0;
  buff?: TurnStats;
  getStoreCount?: (q: Quest) => number;
github ksandin / darkestdungeon / src / state / types / Curio.ts View on Github external
import {identifier, list, object, serializable} from 'serializr';
import {v4 as uuid} from 'uuid';
import {Item} from './Item';
import {TurnStats} from './Stats';
import {observable} from 'mobx';

export type CurioId = string;

export class Curio {
  @serializable(identifier()) id: CurioId = uuid();
  @serializable name: string = '';
  @serializable(object(TurnStats)) buff: TurnStats = null;
  @serializable(list(object(Item))) @observable items: Item[] = [];
  @serializable @observable hasBeenInteractedWith: boolean = false;
  @serializable replaceQuirk: boolean;
}
github ksandin / darkestdungeon / src / state / types / LevelInfo.ts View on Github external
import {identifier, serializable} from 'serializr';

export class LevelInfo {
  @serializable(identifier()) id: number;
  name: string;
  number: number;
  experience: number;

  constructor (
    public previous?: LevelInfo,
    public next?: LevelInfo
  ) {}

  get isMax () {
    return !this.next;
  }

  get relativeExperience () {
    const from = this.previous ? this.previous.experience : 0;
    return this.experience - from;
github ksandin / darkestdungeon / src / state / types / QuirkInfo.ts View on Github external
import {identifier, serializable} from 'serializr';
import {IStatsSource, Stats} from './Stats';
import {BuildingInfoId} from './BuildingInfo';

export type QuirkId = string;

export class QuirkInfo implements IStatsSource {
  @serializable(identifier()) id: QuirkId;
  public name: string;
  public treatmentCostScale = 1.5;
  public stats: Stats = new Stats();
  public forcedTreatmentIds: BuildingInfoId[] = [];
  public bannedTreatmentIds: BuildingInfoId[] = [];
  public isDisease: boolean;
  public isAffliction: boolean;
  statsSourceName: string = 'Quirk';

  get isForcedOrBanned () {
    return this.forcedTreatmentIds.length > 0 || this.bannedTreatmentIds.length > 0;
  }

  get isPositive () {
    return !this.isForcedOrBanned && this.stats.isPositive;
  }