UNPKG

homm3-parsers

Version:

Collection of binary parsers able to parse various file formats related to Heroes of Might and Magic III

69 lines 4.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const binary_markup_1 = require("binary-markup"); const quest_bml_1 = require("./quest.bml"); const seersHut_bml_1 = require("./seersHut.bml"); const town_bml_1 = require("./town.bml"); const common_bml_1 = require("../common.bml"); const MetaType_1 = require("../contracts/enums/MetaType"); const spell_1 = require("../enums/spell"); const scholar_bml_1 = require("./scholar.bml"); const player_1 = require("../enums/player"); const randomDwelling_bml_1 = require("./randomDwelling.bml"); const common_bml_2 = require("./common.bml"); const hero_bml_1 = require("./hero.bml"); const pandoraBox_bml_1 = require("./pandoraBox.bml"); const creature_bml_1 = require("./creature.bml"); const event_bml_1 = require("./event.bml"); const skill_1 = require("../enums/skill"); const messageBearer = binary_markup_1.struct(common_bml_1.hommString `message`, binary_markup_1.skip(4)); const garrison = binary_markup_1.struct(binary_markup_1.enums(binary_markup_1.uint32, player_1.playerEnum) `owner`, common_bml_1.army `creatures`, binary_markup_1.when(common_bml_1.isNotRoE, binary_markup_1.uint8) `removableUnits`, binary_markup_1.skip(8)); const grail = binary_markup_1.struct(binary_markup_1.uint32 `allowableRadius`); const flagged = binary_markup_1.struct(binary_markup_1.uint32 `owner`); const artifactObject = binary_markup_1.struct( // binary_markup_1.flag `hasGuardians`, binary_markup_1.when(binary_markup_1.ctx `hasGuardians`, common_bml_2.guardians) `guardians`); const shrine = binary_markup_1.struct(binary_markup_1.uint32 `spell`); const spellScroll = binary_markup_1.struct(binary_markup_1.flag `hasGuardians`, binary_markup_1.when(binary_markup_1.ctx `hasGuardians`, common_bml_2.guardians) `guardians`, binary_markup_1.enums(binary_markup_1.uint32, spell_1.spellEnum) `spell`); const resource = binary_markup_1.struct(binary_markup_1.flag `hasGuardians`, binary_markup_1.when(binary_markup_1.ctx `hasGuardians`, common_bml_2.guardians) `hasGuardians`, binary_markup_1.uint32 `quantity`, binary_markup_1.skip(4)); const witchHut = binary_markup_1.struct(skill_1.skillsMask `potentialSkills`); const bodyMap = { [MetaType_1.MetaType.PlaceholderHero]: hero_bml_1.heroPlaceholder, [MetaType_1.MetaType.QuestGuard]: quest_bml_1.quest, [MetaType_1.MetaType.PandorasBox]: pandoraBox_bml_1.pandoraBox, [MetaType_1.MetaType.Sign]: messageBearer, [MetaType_1.MetaType.OceanBottle]: messageBearer, [MetaType_1.MetaType.Garrison]: garrison, [MetaType_1.MetaType.Event]: event_bml_1.event, [MetaType_1.MetaType.Grail]: grail, [MetaType_1.MetaType.Dwelling]: flagged, [MetaType_1.MetaType.Lighthouse]: flagged, [MetaType_1.MetaType.ResourceGenerator]: flagged, [MetaType_1.MetaType.Shipyard]: flagged, [MetaType_1.MetaType.AbandonedMine]: flagged, // Generic objects have no body [MetaType_1.MetaType.Boat]: binary_markup_1.pass, [MetaType_1.MetaType.PassableTerrain]: binary_markup_1.pass, [MetaType_1.MetaType.ImpassableTerrain]: binary_markup_1.pass, [MetaType_1.MetaType.Visitable]: binary_markup_1.pass, [MetaType_1.MetaType.Treasure]: binary_markup_1.pass, [MetaType_1.MetaType.MonolithTwoWay]: binary_markup_1.pass, [MetaType_1.MetaType.SubterraneanGate]: binary_markup_1.pass, [MetaType_1.MetaType.Town]: town_bml_1.town, [MetaType_1.MetaType.RandomDwelling]: randomDwelling_bml_1.randomDwelling, [MetaType_1.MetaType.RandomDwellingAlignment]: randomDwelling_bml_1.randomDwellingAlignment, [MetaType_1.MetaType.RandomDwellingLevel]: randomDwelling_bml_1.randomDwellingLevel, [MetaType_1.MetaType.Hero]: hero_bml_1.heroData, [MetaType_1.MetaType.RandomHero]: hero_bml_1.heroData, [MetaType_1.MetaType.Prison]: hero_bml_1.heroData, [MetaType_1.MetaType.Creature]: creature_bml_1.creatureData, [MetaType_1.MetaType.Artifact]: artifactObject, [MetaType_1.MetaType.Shrine]: shrine, [MetaType_1.MetaType.SpellScroll]: spellScroll, [MetaType_1.MetaType.Resource]: resource, [MetaType_1.MetaType.WitchHut]: binary_markup_1.when(common_bml_1.isNotRoE, witchHut), [MetaType_1.MetaType.SeersHut]: seersHut_bml_1.seersHut, [MetaType_1.MetaType.Scholar]: scholar_bml_1.scholar, }; exports.objectBody = binary_markup_1.struct(binary_markup_1.computed(binary_markup_1.ctx `attributes.metaType`) `type`, binary_markup_1.branch(binary_markup_1.ctx `type`, bodyMap) `data`); //# sourceMappingURL=body.bml.js.map