How to use the oni-save-parser.getBehavior function in oni-save-parser

To help you get started, we’ve selected a few oni-save-parser 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 RoboPhred / oni-duplicity / src / services / oni-save / selectors / material.ts View on Github external
function addMaterialObject(
  name: string,
  gameObject: GameObject,
  loose: boolean,
  rowsByMaterial: Record
) {
  const elementBehavior = getBehavior(gameObject, PrimaryElementBehavior);
  if (!elementBehavior) {
    return;
  }

  const { Units } = elementBehavior.templateData;

  // Use custom provided name, as many objects (food, clothing) have the same primary element.
  const row = getMaterialRow(name, rowsByMaterial);

  if (loose) {
    row.looseCount++;
    row.looseGrams += Units;
  } else {
    row.storedCount++;
    row.storedGrams += Units;
  }
github RoboPhred / oni-duplicity / src / services / oni-save / saga / export-behaviors.ts View on Github external
behaviors: exportBehaviors
  };

  const hash = objectHash(exportObject, { algorithm: "sha1" });
  exportObject.$sha1 = hash;

  const content = JSON.stringify(exportObject, null, 2);

  const blob = new Blob([content], {
    type: "application/javascript;charset=utf-8"
  });

  // TODO: Should have a config file defining valid behavior exports and file name source.
  let fileName = "export.json";
  if (gameObjectType === "Minion") {
    const identity = getBehavior(gameObject, MinionIdentityBehavior);
    if (identity) {
      fileName = `${identity.templateData.name}.json`;
    }
  }

  saveAs(blob, fileName);
}
github RoboPhred / oni-duplicity / src / services / oni-save / selectors / behaviors.ts View on Github external
(gameObjectsById, gameObjectId) => {
        const gameObject = gameObjectsById[gameObjectId];
        if (!gameObject) {
          return null;
        }

        return getBehavior(gameObject, behaviorName);
      }
    )(gameObjectIdSelector);
github RoboPhred / oni-duplicity / src / pages / SaveEditor / components / editors / game-objects / components / GameObjectHeader / derived-state.ts View on Github external
const primaryElementBehavior = createSelector(selectedValue, value => {
  if (!value) {
    return null;
  }

  return getBehavior(value, PrimaryElementBehavior);
});
github RoboPhred / oni-duplicity / src / services / oni-save / selectors / space-manager.ts View on Github external
}

      const saveGameGroup = find(
        saveGame.gameObjects,
        x => x.name === "SaveGame"
      );
      if (!saveGameGroup) {
        return null;
      }

      const saveGameObject = saveGameGroup.gameObjects[0];
      if (!saveGameObject) {
        return null;
      }

      const spaceBehavior = getBehavior(
        saveGameObject,
        SpacecraftManagerBehavior
      );
      if (!spaceBehavior) {
        return null;
      }

      return spaceBehavior.templateData;
    }
  )
github RoboPhred / oni-duplicity / src / services / oni-save / reducer / copy-behaviors.ts View on Github external
const gameObjects = gameObjectsByIdSelector.local(state);
  if (!gameObjects || !gameObjects[gameObjectId]) {
    return state;
  }
  const gameObject = gameObjects[gameObjectId];

  const typesById = gameObjectTypesByIdSelector.local(state);
  if (!typesById || !typesById[gameObjectId]) {
    return state;
  }
  const gameObjectType = typesById[gameObjectId];

  const copyBehaviors: Record = {};
  for (const behaviorName of behaviors) {
    const behavior = getBehavior(gameObject, behaviorName);
    if (!behavior) {
      continue;
    }
    copyBehaviors[behaviorName] = {
      templateData: behavior.templateData,
      extraData: behavior.extraData
    };
  }

  return {
    ...state,
    copyPasteData: {
      gameObjectType,
      behaviors: copyBehaviors
    }
  };
github RoboPhred / oni-duplicity / src / services / oni-save / utils.ts View on Github external
export function getGameObjectId(gameObject: GameObject): number | null {
  const idBehavior = getBehavior(gameObject, KPrefabIDBehavior);
  if (!idBehavior) {
    return null;
  }

  return idBehavior.templateData.InstanceID;
}