VSCode XML Modding Template

Please post here for questions and discussion about data, event, art and sound modding and the game editor for Distant Worlds.

Moderator: MOD_DW2

Post Reply
brucethemoose
Posts: 46
Joined: Fri Feb 18, 2022 6:14 pm

VSCode XML Modding Template

Post by brucethemoose »

I posted this in the roadmap thread, but I figured I'd mirror it here so it doesn't get buried.

Thanks to the XSDs Elliot posted, VSCode supports editing DW2's XML files with game-specific syntax and error checking.

Here are some steps to get it working:

-Install VSCode
-Install the official XML extension from Red Hat. You can install extensions via one of the buttons in the left sidebar.
-Download the XSD files from this post and stick them in your DW2 data directory.
-Open the command palette with F1 or ctrl+shift+P
-Type "open settings" and click "Open Settings (JSON)"
-Paste the following code into the json file:

Code: Select all

 "xml.fileAssociations": [
        
      {
        "pattern": "Artifacts.xml",
        "systemId": "ArtifactList.xsd"
      },
      {
        "pattern": "ColonyEventDefinitions.xml",
        "systemId": "ColonyEventDefinitionList.xsd"
      },
      {
        "pattern": "ComponentDefinitions.xml",
        "systemId": "ComponentDefinitionList.xsd"
      },
      {
        "pattern": "CreatureTypes.xml",
        "systemId": "CreatureTypeList.xsd"
      },
      {
        "pattern": "FleetTemplates.xml",
        "systemId": "FleetTemplateList.xsd"
      },
      {
        "pattern": "GameEvents.xml",
        "systemId": "GameEventList.xsd"
      },
      {
        "pattern": "Governments.xml",
        "systemId": "GovernmentList.xsd"
      },
      {
        "pattern": "OrbTypes.xml",
        "systemId": "OrbTypeList.xsd"
      },
      {
        "pattern": "PlanetaryFacilityDefinitions.xml",
        "systemId": "PlanetaryFacilityDefinitionList.xsd"
      },
      {
        "pattern": "Races.xml",
        "systemId": "RaceList.xsd"
      },
      {
        "pattern": "ResearchProjectDefinitions.xml",
        "systemId": "ResearchProjectDefinitionList.xsd"
      },
      {
        "pattern": "Resources.xml",
        "systemId": "RescourceList.xsd"
      },
      {
        "pattern": "ShipHulls.xml",
        "systemId": "ShipHullList.xsd"
      },
      {
        "pattern": "SpaceItemDefinitions.xml",
        "systemId": "SpaceItemDefinitionList.xsd"
      },
      {
        "pattern": "TroopDefinitions.xml",
        "systemId": "TroopDefinitionList.xsd"
      }
    ]

For reference, this is what a full json looks like, with some enhanced support for large files:

Code: Select all

{
    "workbench.colorTheme": "Default Dark+",
    "xml.symbols.maxItemsComputed": 50000,
    "xml.codeLens.enabled": true,
    "editor.largeFileOptimizations": false,
    "xml.fileAssociations": [
      {
        "pattern": "ArtifactList.xml",
        "systemId": "Artifacts.xsd"
      },
      {
        "pattern": "ColonyEventDefinitions.xml",
        "systemId": "ColonyEventDefinitionList.xsd"
      },
      {
        "pattern": "ComponentDefinitions.xml",
        "systemId": "ComponentDefinitionList.xsd"
      },
      {
        "pattern": "CreatureTypes.xml",
        "systemId": "CreatureTypeList.xsd"
      },
      {
        "pattern": "FleetTemplates.xml",
        "systemId": "FleetTemplateList.xsd"
      },
      {
        "pattern": "GameEvents.xml",
        "systemId": "GameEventList.xsd"
      },
      {
        "pattern": "Governments.xml",
        "systemId": "GovernmentList.xsd"
      },
      {
        "pattern": "OrbTypes.xml",
        "systemId": "OrbTypeList.xsd"
      },
      {
        "pattern": "PlanetaryFacilityDefinitions.xml",
        "systemId": "PlanetaryFacilityDefinitionList.xsd"
      },
      {
        "pattern": "Races.xml",
        "systemId": "RaceList.xsd"
      },
      {
        "pattern": "ResearchProjectDefinitions.xml",
        "systemId": "ResearchProjectDefinitionList.xsd"
      },
      {
        "pattern": "Resources.xml",
        "systemId": "RescourceList.xsd"
      },
      {
        "pattern": "ShipHulls.xml",
        "systemId": "ShipHullList.xsd"
      },
      {
        "pattern": "SpaceItemDefinitions.xml",
        "systemId": "SpaceItemDefinitionList.xsd"
      },
      {
        "pattern": "TroopDefinitions.xml",
        "systemId": "TroopDefinitionList.xsd"
      }
    ]
}
-Open the data directory in vscode.

And that's it!


There is a problem though. The XSD files seem to be incomplete at the moment, so the editor may flag tons of existing "issues" in the vanilla files. Here's one such example in ComponentDefinitions.xml:

Code: Select all

Invalid element name:
 - FiringEffectScaling

One of the following is expected:
 - FiringEffectFilepath
 - ArmorImpactEffectFilepath
 - HullImpactEffectFilepath
 - FiringSoundEffectFilepath
 - ArmorImpactSoundEffectFilepath
 - HullImpactSoundEffectFilepath
 - ArmorImpactEffectScaling
 - HullImpactEffectScaling
 - FiringSoundEffectVolume
 - ArmorImpactEffectTintColor

Error indicated by:
 {the schema}
with code:
The line is "<FiringEffectScaling>2.5</FiringEffectScaling>"

But even without the XSD templates, VSCode is great at syntax checking, and is pretty much the gold standard in other modding communities like Rimworld and Stellaris.
Post Reply

Return to “Design and Modding”