How to use oni-save-parser - 10 common examples

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 / save-structure / structure / gameObjects / behaviors / default.ts View on Github external
const typeInfo: TypeInfo = member.type;
      const code = getTypeCode(typeInfo.info);

      if (code === SerializationTypeCode.UserDefined) {
        template = templates.find(x => x.name === typeInfo.templateName);
        if (template == null) {
          // Unknown template.
          return null;
        }
      } else if (LIST_TYPES.indexOf(code) !== -1) {
        i++;

        if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
          const arrayTypeInfo = typeInfo.subTypes![0];
          template = templates.find(x => x.name === arrayTypeInfo.templateName);
          if (template == null) {
            // Unknown template.
            return null;
          }
        }
      } else if (code === SerializationTypeCode.Dictionary) {
        i++;
        if (
          getTypeCode(typeInfo.subTypes![1].info) ===
          SerializationTypeCode.UserDefined
        ) {
          const arrayTypeInfo = typeInfo.subTypes![1];
          template = templates.find(x => x.name === arrayTypeInfo.templateName);
github RoboPhred / oni-duplicity / src / services / save-structure / structure / gameObjects / behaviors / default.ts View on Github external
//  any sub-templates.

    for (let i = 0; i < subPath.length; i++) {
      const part = subPath[i];

      const member =
        template.fields.find(x => x.name === part) ||
        template.properties.find(x => x.name === part);
      if (!member) {
        break;
      }

      const typeInfo: TypeInfo = member.type;
      const code = getTypeCode(typeInfo.info);

      if (code === SerializationTypeCode.UserDefined) {
        template = templates.find(x => x.name === typeInfo.templateName);
        if (template == null) {
          // Unknown template.
          return null;
        }
      } else if (LIST_TYPES.indexOf(code) !== -1) {
        i++;

        if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
          const arrayTypeInfo = typeInfo.subTypes![0];
          template = templates.find(x => x.name === arrayTypeInfo.templateName);
          if (template == null) {
            // Unknown template.
github RoboPhred / oni-duplicity / src / pages / SaveEditor / components / editors / TemplateObjectEditor / derived-state.ts View on Github external
if (template == null) {
        return null;
      }

      const member =
        template.fields.find(x => x.name === part) ||
        template.properties.find(x => x.name === part);
      if (!member) {
        return null;
      }

      typeInfo = member.type;

      const typeCode = getTypeCode(typeInfo.info);

      if (typeCode === SerializationTypeCode.UserDefined) {
        template = oniSave.templates.find(
          x => x.name === member.type.templateName!
        );
      } else if (LIST_TYPES.indexOf(typeCode) !== -1) {
        i++;
        if (i === templatePath.length) {
          // Targeting an array but no index yet.
          break;
        }

        if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
          typeInfo = typeInfo.subTypes![0];
          template = oniSave.templates.find(
github RoboPhred / oni-duplicity / src / pages / SaveEditor / components / editors / TemplateObjectEditor / derived-state.ts View on Github external
if (i === templatePath.length) {
          // Targeting an index, but no key or value.
          // Fake a value for the ui.
          typeInfo = {
            info: SerializationTypeInfo.Pair,
            subTypes: typeInfo.subTypes
          };
          break;
        }
        let keyValueIndex = Number(templatePath[i]);
        typeInfo = typeInfo.subTypes![keyValueIndex];
        if (!typeInfo) {
          break;
        }

        if (getTypeCode(typeInfo.info) === SerializationTypeCode.UserDefined) {
          template = oniSave.templates.find(
            x => x.name === typeInfo.templateName
          );
        }
      } else {
        return null;
      }
    }

    return typeInfo;
  }
);
github RoboPhred / oni-duplicity / src / pages / SaveEditor / components / editors / TemplateObjectEditor / derived-state.ts View on Github external
const typeCode = getTypeCode(typeInfo.info);

      if (typeCode === SerializationTypeCode.UserDefined) {
        template = oniSave.templates.find(
          x => x.name === member.type.templateName!
        );
      } else if (LIST_TYPES.indexOf(typeCode) !== -1) {
        i++;
        if (i === templatePath.length) {
          // Targeting an array but no index yet.
          break;
        }

        if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
          typeInfo = typeInfo.subTypes![0];
          template = oniSave.templates.find(
            x => x.name === typeInfo.templateName
          );
        }
      } else if (typeCode === SerializationTypeCode.Dictionary) {
        i++;
        if (i === templatePath.length) {
          // Targeting a dict but no index yet.
          break;
        }

        // Select key or value
        i++;
github RoboPhred / oni-duplicity / src / services / save-structure / structure / gameObjects / behaviors / default.ts View on Github external
if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
          const arrayTypeInfo = typeInfo.subTypes![0];
          template = templates.find(x => x.name === arrayTypeInfo.templateName);
          if (template == null) {
            // Unknown template.
            return null;
          }
        }
      } else if (code === SerializationTypeCode.Dictionary) {
        i++;
        if (
          getTypeCode(typeInfo.subTypes![1].info) ===
          SerializationTypeCode.UserDefined
        ) {
          const arrayTypeInfo = typeInfo.subTypes![1];
          template = templates.find(x => x.name === arrayTypeInfo.templateName);
          if (template == null) {
            // Unknown template.
            return null;
          }
        }
      }
    }

    return template.name;
  },
github RoboPhred / oni-duplicity / src / pages / SaveEditor / components / editors / TemplateObjectEditor / derived-state.ts View on Github external
const part = templatePath[i];

      if (template == null) {
        return null;
      }

      const member =
        template.fields.find(x => x.name === part) ||
        template.properties.find(x => x.name === part);
      if (!member) {
        return null;
      }

      typeInfo = member.type;

      const typeCode = getTypeCode(typeInfo.info);

      if (typeCode === SerializationTypeCode.UserDefined) {
        template = oniSave.templates.find(
          x => x.name === member.type.templateName!
        );
      } else if (LIST_TYPES.indexOf(typeCode) !== -1) {
        i++;
        if (i === templatePath.length) {
          // Targeting an array but no index yet.
          break;
        }

        if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
github RoboPhred / oni-duplicity / src / services / save-structure / structure / gameObjects / behaviors / default.ts View on Github external
// Chase the path up the template to see if we have entered
    //  any sub-templates.

    for (let i = 0; i < subPath.length; i++) {
      const part = subPath[i];

      const member =
        template.fields.find(x => x.name === part) ||
        template.properties.find(x => x.name === part);
      if (!member) {
        break;
      }

      const typeInfo: TypeInfo = member.type;
      const code = getTypeCode(typeInfo.info);

      if (code === SerializationTypeCode.UserDefined) {
        template = templates.find(x => x.name === typeInfo.templateName);
        if (template == null) {
          // Unknown template.
          return null;
        }
      } else if (LIST_TYPES.indexOf(code) !== -1) {
        i++;

        if (
          getTypeCode(typeInfo.subTypes![0].info) ===
          SerializationTypeCode.UserDefined
        ) {
          const arrayTypeInfo = typeInfo.subTypes![0];
          template = templates.find(x => x.name === arrayTypeInfo.templateName);