Mod XML Validator

Discussion in 'Modding' started by Glazed, May 29, 2012.

  1. Glazed

    Glazed Member

    The project has been open-sourced! Check it out on Githhub.

    Requirements:
    Microsoft Windows with .Net 4.0 installed.

    Web version here for Mac and Linux users: http://dredmorcodex.com/XmlValidator (Dead)

    Change Log:

    1.1.3.5
    • I forgot to regenerate the words file, so I did that. One new word was added. (This supports case-insensitive XML validation.)

    1.1.3.4
    • Added hitsNeededToBreak to customBreakable
    • Spell effect "turns" is no a signed byte instead of unsigned (allows you to use -1)
    • mineTimer is now an unsigned int instead of unsigned byte to allow larger values.
    • beammissile spells can now use a PNG as their animation.
    Known Bugs:
    • It sometimes locks files, so you can't edit them until you close the validator.
    • It can erroneously report that you are using expansion resources when you shamelessly copy those resources into your mod and don't rename them. You dirty thief!
    What it does:
    • Validates the mod structure
      • A "mod" folder is required.
      • A "mod.xml" file is required in that folder.
      • All "DB" XML files are required to be in that folder.
    • Validates that the XML files match the schema expected by the game. This includes the names of elements, their child elements, their attribute names, their attribute data types, etc. This uses an embedded XSD file, and I call this step "XSD validation".
      For example:
      • ItemDB.xml must only contain <item> and <power> elements.
      • The "artifact" attribute on an item must be a 1 or 0.
    • Validate that the references and resources you specified exist.
      • References are when one element refers to another. It will check your mod for these, and the validator knows the names of all entities in the core game and all expansions, so it allows those, too.
        For example:
        • Spells that have effects that refer to other spells.
        • Items that refer to spells.
        • Rooms that refer to items.
      • Resources are physical files that the XML refers to. (Like above, the validator knows about all the files in the core game.)
        For example:
        • Spell effect animation frames exist
        • Spell effect animation has as many frames as you specified
        • Item icons exist
        • Monster sprites exist
    What it will never do:
    • Tell you why your spell is crashing the game even though it passes the above validations.
    • Validate that your room's script is not a pile of nonsense.
    • Validate that your room doesn't have holes in the walls.
    • A million more ways your mod could fail.
    What is looks like:
    snap004922.png
     

    Attached Files:

    Last edited: Dec 20, 2018
    GreyZ0mbie, zellking, Kazeto and 7 others like this.
  2. Glazed

    Glazed Member

    1.1.3.1
    Many XSD fixes contributed by Null for advanced XML feature that not even Gaslamp Games is using!
    • trapOrigin can now be "floor".
    • Lots of values changed from bytes to shorts to accomodate larger values.
    • Added "elements" for rooms: clock, magicBlocker.
    • Added room element types: wizardControls, wizardGraffiti, wizardKey, wizardPedestal, wizardPortal.
    • Added attributes for traps: can_push, id.
    • Added room sccript condition types: entered, exited, event, isAlive, started, stopped
    • Added room script condition attributes: started, stopped, eventType
    • Added room script action_type: set.
    • Added room script action create_type: clock, customEngraving, trap.
    • Added room script action strribute: set_type.
    • Added spell type: target_zombie.
    • Added spell effect type: moveCurses, resetCooldowns.
    1.1.2.3
    • Added charge (spell charging) for monsters.
    • Made chance and interruptable optional for dash since they are optional for charge, and I assume these attributes have a default value there, too.
    1.1.2.2
    • Added resetRandomCooldown spell effect type.
    1.1.2.1
    • Added "percentage" to spell effects which now works the same as "percent".
    1.1.2.0
    • Added validation for unstableEffect spells.
    • Removed default value for path in DredmorXmlValidator.
    • Added spell effect: swapWithMonster
    • Added buffTag attribute to spell effects.
    • Added consumeItemType: potion
    • In a previous version, a beep was added at the completion of validation for the Core Validator.
    1.1.1.0
    • Made monster dash spells optional.
    1.1.0.0:
    • Added ecrustDB element to the DredmorSchema.xsd file.
    • Altered item element so the type attribute supports values 7 and 8 for daggers and polearms. Now validating the thrown weapon "thrown" attribute as an image or sprite. Removed validation of certain toolkit button images because they aren't used anymore and were raising false errors.
    • Altered monster element to support new elements: sight, dash, primaryBuff and new attributes: diggleHell, horde, named, maxSpawns. "drop" now supports type in addition to name.
    • Altered spell element to support type targetFloorItem and attributes: noAnimation. New child effects of type randomUncurse, moveRandomCurse, grabItem, transformMonster, manipulateObject, randomizePotion, findRecipe, removeMonster, dropItem, ascendDungeonLevel. The requirements element now supports new attribute: zorkmids, and mp is now optional. The buff element now supports elements: payback, zorkmidAbsorption, and attributes: insufficientFunds, zorkmidUpkeep.
    • Altered abilities to support new element zorkmidbuff.
    • Added support for the new "dash" element for monsters. Validating the hitSpell and missSpell as spell resources.
    • Added support for validating the resources and element counts in the encrustDB file.
    • Created a new project to generate the words.txt file used for case-insensitive XSD validation. This was previously generated manually.

    Validation Workflow example:
    1. Install a text editor that can show line numbers, and preferably has a "Go To Line" command. I recommend Notepad++ (It's completely free.) the rest of this example will assume you're using Notepad++.
    2. Open the validator and paste in the directory path to your mod. Use the unzipped version of your mod. This will give you paths you can copy and paste into your text editor's Open File window.
    3. When a file has an error, note the line number of the error, then copy the file path and switch to Notepad++.
    4. In Notepad++ press Ctrl-O for the Open File window. You can immediately hit Ctrl-V (to paste in the path) and then press Enter. This will open the file with the error.
    5. Now press Ctrl-G for the "Go To..." dialog. Type in the line number from step 3, and click Go. Or you can just scroll until you find the line you want.
    Advanced Mod Editing Workflow:

    If you want to be really clever, I can set you up with the the XSD files and an XML editor that supports real-time validation and auto-complete. I just did this as a test using XML Notepad 2007. It doesn't have the most intuitive interface, but it does work:

    snap001122.png

    I also plan on seeing if Visual C# Express can do real-time XSD validation. Being a free version it might not, but if it works it has a much better interface. There's also an XSD plugin for Notepad++ called "XML Tools".

    If you would like to use the XSD files for assistance when working on the XML files you will need to accept some limitations. For one, XML (and thus XSD) is case-sensitive even though the game, for the most part, is not. You will have to use the correct capitalization or else you will get errors. You can use the Capitalization Fixer to fix your existing files. Notice in the screenshot above that "secondarybuff" is an error. The correct name is "secondaryBuff". I accounted for this in the validator so you don't get these errors. Secondly, the XSDs can't validate the references and resources. You'll still need to run your mod through the validator for that.

    I can give detailed instructions if anyone is interested.
     
    iamcreasy and OmniNegro like this.
  3. FaxCelestis

    FaxCelestis Will Mod for Digglebucks

    So much like. SO MUCH.
     
  4. Essence

    Essence Will Mod for Digglebucks

    Yes. As one of the alpha testers of this sweet sweet thing, I can say that without it, Compleat Essential Skills would have taken a lot longer to be out of beta. It's SO NICE knowing that all of your icons and stuff are correctly referenced, and that none of your XML is misspelled. (I had about a half-dozen misspellings buried in my stuff that was really making a few things (looking at you, Kuji Kiri) not work like at all. Glazed's awesome tool found them all for me.)

    It's not super-duper easy to work with -- the whole "error on line XYZ" thing is quite frequently referencing a line up to 100 away from where it says it is because different validators use different numbering schemas -- but it's SO WORTH working through the list, especially if you've got a big-ass mod like FaxPax or Compleat Essential Skills. :)
     
  5. Glazed

    Glazed Member

    Wait, what? I've never seen it be off by more than one line. It's not my code that's giving this line numbers. It's the .Net framework's XmlReader class. I doubt it can ever be 100 lines off. Microsoft is really good about testing their stuff. What text editor are you using to view the files?
     
  6. FaxCelestis

    FaxCelestis Will Mod for Digglebucks

    Code:
    C:\Users\James\Documents\Gaslamp Games\Dungeons of Dredmor\mods\FaxPax\mod\monDB.xml
    1 error(s) found.
    Line 2, Position: 76 -- The sound, 'ichor', or a numbered variant of it could not be found.
    It appears to be identifying splat="ichor" as a sound effect. It is not: splat= determines what blood splatter types (if any: the field is optional--just look at constructs) the game uses when the creature is damaged.

    Code:
    Line 1930, Position: 44 -- The 'text' attribute is not declared.
     
    Line 1930, Position: 2 -- The required attribute 'description' is missing.
     
    Line 1931, Position: 39 -- The 'text' attribute is not declared.
     
    Line 1931, Position: 2 -- The required attribute 'description' is missing.
    Code:
    <digglegod name="Diggle God of Mediocrity" text="The Diggle God of Mediocrity feebly asks for dirt? Or something? To dig, possibly?" art="sprites/diggle_god_mediocrity.png" spell="Diggle God of Mediocrity Blessing"/>
    <digglegod name="Diggle God of Booze" text="The Diggle God of Booze demands BEVERAGES. Preferably ALCOHOLIC ONES." art="sprites/diggle_god_booze.png" spell="Diggle God of Booze Blessing"/> 
    The <digglegod /> entries use text= instead of description=.
     
    Glazed likes this.
  7. Essence

    Essence Will Mod for Digglebucks

    Http://www.validrome.com. The farther through my spellDB I got, the further off it was. By the end, it was nearly 180 off.
     
  8. Glazed

    Glazed Member

  9. Glazed

    Glazed Member

    My bad. I will fix that tonight.

    If you say so... ;)
    Code:
      <digglegod name="Diggle God of Death" description="Dark and skeletal, the Diggle God of Death relaxes in his? stylish coffin." art="dungeon/diggle_god_death.png" spell="Diggle God of Death Blessing"/>
      <digglegod name="Diggle God of War" description="It is a statue of the Diggle God of War! Or possibly Battyman." art="dungeon/diggle_god_war.png" spell="Diggle God of War Blessing"/>
      <digglegod name="Diggle God of Fertility" description="The Diggle God of Fertility gazes upon his? egg with a look of mild constipation." art="dungeon/diggle_god_fertility.png" spell="Diggle God of Fertility Blessing"/>
      <digglegod name="Diggle God of Digging" description="The Diggle God of Digging mainly has his statues created by out-of-work visual arts students." art="dungeon/diggle_god_digging.png" spell="Diggle God of Digging Blessing"/>
      <digglegod name="Diggle God of Secrets" description="Congratulations, you found a statue of the Diggle God of Secrets. Now scamper." art="dungeon/diggle_god_secrets.png" spell="Diggle God of Secrets Blessing"/>
    
     
  10. FaxCelestis

    FaxCelestis Will Mod for Digglebucks

    :confused:

    I'll have to test to see if text= works too. I remember it working, but my memory is like a colander made of swiss cheese.
     
  11. Glazed

    Glazed Member

    I got this error with your mod:

    Code:
    The 'frameRate' attribute is invalid - The value '600' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:unsignedByte' - The string '600' is not a valid Byte value.
    I need to change the data type of that attribute. Unsigned byte only allows a maximum value of 255. I've personally used values as high as 2000 to get some very slow animations. It's fun. Now I want to test some really high value and fill the screen with spell casting animations. (I wish this attribute were called frameDelay. Frame rate implies the inverse of this. A rate of 600 should be really fast, Assuming that the value would mean Hertz.)

    Code:
    Line 767, Position: 4 -- The element 'spell' has incomplete content. List of possible elements expected: 'requirements, anim, effect, description, ai, impact, buff'.
    This one is interesting. You have an empty spell. When I saw this I figured it would be for a "null" entry in a triggerfromlist, and it appears I'm correct. I think I can change the spell element to allow an empty sequence of child elements by specifying minOccurs="0". It defaults to 1.

    Code:
    Line 442, Position: 3 -- The element 'ability' has invalid child element 'consumptionBuff'.
    Does this work yet? I also thought it was going to be "consumeBuff", but I could be wrong.
     
  12. Essence

    Essence Will Mod for Digglebucks

    I've been saying 'consumeBuff' here and there, but when I went back and looked at Nicholas' original syntax, it was apparently always consumptionBuff and I'm a foole with a final e. Whether it works or not, I have yet to test, but Nicholas has always referred to food/booze/consumption buffs as a group, so I'm assuming that because he fixed food and booze, consumption works, too.
     
  13. Glazed

    Glazed Member

    consumptionBuff... is that an enhancement to your tuberculosis level?
     
    r_b_bergstrom and FaxCelestis like this.
  14. Essence

    Essence Will Mod for Digglebucks

    Nicholas just said in chat that if it's not already working (it might be) he'll "probably" sneak it into the next RC. :)
     
  15. Glazed

    Glazed Member

    If he adds it, I'll add it. That's how this works. :)
     
  16. Glazed

    Glazed Member

    Version 0.2 uploaded.
     
  17. Glazed

    Glazed Member

    Just comment it out until it works. Also, stop using "spell" for you triggers! It's "name"! And get rid of all that deprecated monster junk!

    I'm going to keep using your mod as the example screenshot until it's error free. After that maybe I'll keep using it since there's now a new "No errors! Congratulations!" message if a mod passes all validations.
     
  18. Essence

    Essence Will Mod for Digglebucks

    Oh, allthat monstrous crape is depreciated? Cool. I thought I'd alreday fixed the name vs spell stuff though.
     
  19. FaxCelestis

    FaxCelestis Will Mod for Digglebucks

    Maybe you would if you stopped editing your xml from your phone.
     
    Kazeto and mining like this.
  20. Glazed

    Glazed Member

    Uploaded version 0.3