Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { AbilityScore } from 'charactersheet/models/character/ability_score';
- import {
- CoreManager,
- Notifications
- } from 'charactersheet/utilities';
- import ko from 'knockout';
- export class AbilityScoresViewModelDelegate {
- constructor() {}
- /**
- * This method takes care of persisting the updated ability scores and sending out relevant
- * notifications.
- *
- * @param {AbilityScore[]} oldScores initial ability scores
- * @param {AbilityScore[]} newScores updated ability scores
- * @returns {AbilityScore[]} an array of the most up to date ability scores
- */
- updateAbilityScores = async (oldScores, newScores) => {
- let scoresModified = false;
- oldScores().forEach(async (old, i, _) => {
- let newScore = newScores().filter((element) => {
- return old.shortName() === element.shortName();
- });
- if (newScore.value() != old.value()) {
- scoresModified = true;
- const response = await newScore().ps.save();
- self.sendNotifications(response.object);
- }
- });
- if (scoresModified) {
- Notifications.abilityScores.changed.dispatch();
- var key = CoreManager.activeCore().uuid();
- const response = await AbilityScore.ps.list({coreUuid: key});
- return response.objects;
- } else {
- return oldScores;
- }
- };
- sendNotifications = (score) => {
- if (score.shortName() === 'INT') {
- Notifications.abilityScores.intelligence.changed.dispatch();
- } else if (score.shortName() === 'DEX') {
- Notifications.abilityScores.dexterity.changed.dispatch();
- }
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement