How to use the restructure.Optional function in restructure

To help you get started, we’ve selected a few restructure 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 wowserhq / blizzardry / lib / adt / index.js View on Github external
MMID: SkipChunk,
  MWMO: require('../chunked/mwmo'),
  MWID: SkipChunk,
  MDDF: SkipChunk,
  MODF: SkipChunk,
  MH2O: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMH2O;
  }),
  MCNKs: new r.Array(MCNK, 256),
  MFBO: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMFBO;
  }),
  MTXF: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMTXF;
  }),
  MTXP: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMTXP;
  }),

  flags: function flags() {
    return this.MHDR.flags;
  }
});
github wowserhq / blizzardry / src / lib / m2 / index.js View on Github external
maxBoundingBox: Vec3Float,
  boundingRadius: r.floatle,

  boundingTriangles: new Nofs(),
  boundingVertices: new Nofs(),
  boundingNormals: new Nofs(),
  attachments: new Nofs(),
  attachmentLookups: new Nofs(),
  events: new Nofs(),
  lights: new Nofs(),
  cameras: new Nofs(),
  cameraLookups: new Nofs(),
  ribbonEmitters: new Nofs(),
  particleEmitters: new Nofs(),

  blendingOverrides: new r.Optional(new Nofs(r.uint16le), function () {
    return (this.flags & 0x08) !== 0;
  }),

  overrideBlending: function () {
    return (this.flags & 0x08) !== 0;
  },

  canInstance: function () {
    let instance = true;

    this.bones.forEach((bone) => {
      if (bone.animated) {
        instance = false;
      }
    });
github wowserhq / blizzardry / lib / m2 / index.js View on Github external
maxBoundingBox: Vec3Float,
  boundingRadius: r.floatle,

  boundingTriangles: new Nofs(),
  boundingVertices: new Nofs(),
  boundingNormals: new Nofs(),
  attachments: new Nofs(),
  attachmentLookups: new Nofs(),
  events: new Nofs(),
  lights: new Nofs(),
  cameras: new Nofs(),
  cameraLookups: new Nofs(),
  ribbonEmitters: new Nofs(),
  particleEmitters: new Nofs(),

  unknown1: new r.Optional(r.uint32le, function () {
    return this.flags == 8;
  }),
  unknown2: new r.Optional(r.uint32le, function () {
    return this.flags == 8;
  })
});
github wowserhq / blizzardry / src / lib / wmo / group.js View on Github external
MOGP: MOGP,
  MOPY: MOPY,
  MOVI: MOVI,
  MOVT: MOVT,
  MONR: MONR,
  MOTV: MOTV,
  MOBA: MOBA,

  flags: function () {
    return this.MOGP.flags;
  },

  MOLR: new r.Optional(SkipChunk, function () {
    return this.flags & 0x200;
  }),
  MODR: new r.Optional(MODR, function () {
    return this.flags & 0x800;
  }),
  MOBN: new r.Optional(SkipChunk, function () {
    return this.flags & 0x1;
  }),
  MOBR: new r.Optional(SkipChunk, function () {
    return this.flags & 0x1;
  }),
  MOCV: new r.Optional(MOCV, function () {
    return this.flags & 0x4;
  }),

  indoor: function () {
    return (this.flags & 0x2000) !== 0 && (this.flags & 0x8) === 0;
  },
});
github wowserhq / blizzardry / src / lib / wmo / group.js View on Github external
MOVT: MOVT,
  MONR: MONR,
  MOTV: MOTV,
  MOBA: MOBA,

  flags: function () {
    return this.MOGP.flags;
  },

  MOLR: new r.Optional(SkipChunk, function () {
    return this.flags & 0x200;
  }),
  MODR: new r.Optional(MODR, function () {
    return this.flags & 0x800;
  }),
  MOBN: new r.Optional(SkipChunk, function () {
    return this.flags & 0x1;
  }),
  MOBR: new r.Optional(SkipChunk, function () {
    return this.flags & 0x1;
  }),
  MOCV: new r.Optional(MOCV, function () {
    return this.flags & 0x4;
  }),

  indoor: function () {
    return (this.flags & 0x2000) !== 0 && (this.flags & 0x8) === 0;
  },
});
github wowserhq / blizzardry / lib / adt / index.js View on Github external
MCIN: SkipChunk,
  MTEX: MTEX,
  MMDX: MMDX,
  MMID: SkipChunk,
  MWMO: require('../chunked/mwmo'),
  MWID: SkipChunk,
  MDDF: SkipChunk,
  MODF: SkipChunk,
  MH2O: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMH2O;
  }),
  MCNKs: new r.Array(MCNK, 256),
  MFBO: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMFBO;
  }),
  MTXF: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMTXF;
  }),
  MTXP: new r.Optional(SkipChunk, function () {
    return this.MHDR.offsetMTXP;
  }),

  flags: function flags() {
    return this.MHDR.flags;
  }
});
github wowserhq / blizzardry / src / lib / wmo / group.js View on Github external
});

export default Chunked({
  MOGP: MOGP,
  MOPY: MOPY,
  MOVI: MOVI,
  MOVT: MOVT,
  MONR: MONR,
  MOTV: MOTV,
  MOBA: MOBA,

  flags: function () {
    return this.MOGP.flags;
  },

  MOLR: new r.Optional(SkipChunk, function () {
    return this.flags & 0x200;
  }),
  MODR: new r.Optional(MODR, function () {
    return this.flags & 0x800;
  }),
  MOBN: new r.Optional(SkipChunk, function () {
    return this.flags & 0x1;
  }),
  MOBR: new r.Optional(SkipChunk, function () {
    return this.flags & 0x1;
  }),
  MOCV: new r.Optional(MOCV, function () {
    return this.flags & 0x4;
  }),

  indoor: function () {
github wowserhq / blizzardry / src / lib / adt / index.js View on Github external
soundEmitterCount: r.uint32le,
  offsetMCLQ: r.uint32le,
  sizeMCLQ: r.uint32le,
  position: Vec3Float,
  offsetMCCV: r.uint32le,

  skip: new r.Reserved(r.uint32le, 2),

  MCVT: MCVT,
  MCCV: new r.Optional(SkipChunk, function () {
    return this.offsetMCCV;
  }),
  MCNR: MCNR,
  MCLY: MCLY,
  MCRF: MCRF,
  MCSH: new r.Optional(MCSH, function () {
    return this.flags & 0x01;
  }),
  MCAL: MCAL,
  MCLQ: new r.Optional(MCLQ, function () {
    return this.offsetMCLQ;
  }),
  MCSE: new r.Optional(SkipChunk, function () {
    return this.offsetMCSE;
  }),
});

const ADT = function (wdtFlags) {
  return Chunked({
    MHDR: MHDR,

    flags: function () {
github wowserhq / blizzardry / src / lib / adt / index.js View on Github external
MCVT: MCVT,
  MCCV: new r.Optional(SkipChunk, function () {
    return this.offsetMCCV;
  }),
  MCNR: MCNR,
  MCLY: MCLY,
  MCRF: MCRF,
  MCSH: new r.Optional(MCSH, function () {
    return this.flags & 0x01;
  }),
  MCAL: MCAL,
  MCLQ: new r.Optional(MCLQ, function () {
    return this.offsetMCLQ;
  }),
  MCSE: new r.Optional(SkipChunk, function () {
    return this.offsetMCSE;
  }),
});

const ADT = function (wdtFlags) {
  return Chunked({
    MHDR: MHDR,

    flags: function () {
      return this.MHDR.flags;
    },

    wdtFlags: function () {
      return wdtFlags;
    },
github wowserhq / blizzardry / src / lib / adt / index.js View on Github external
flags: function () {
      return this.MHDR.flags;
    },

    wdtFlags: function () {
      return wdtFlags;
    },

    MCIN: SkipChunk,
    MTEX: MTEX,
    MMDX: MMDX,
    MMID: SkipChunk,
    MWMO: MWMO,
    MWID: SkipChunk,
    MDDF: new r.Optional(MDDF, function () {
      return this.MHDR.offsetMDDF;
    }),
    MODF: new r.Optional(MODF, function () {
      return this.MHDR.offsetMODF;
    }),
    MH2O: new r.Optional(SkipChunk, function () {
      return this.MHDR.offsetMH2O;
    }),
    MCNKs: new r.Array(MCNK, 256),
    MFBO: new r.Optional(SkipChunk, function () {
      return this.MHDR.offsetMFBO;
    }),
    MTXF: new r.Optional(SkipChunk, function () {
      return this.MHDR.offsetMTXF;
    }),
    MTXP: new r.Optional(SkipChunk, function () {