Skip to content

Deltas and Overrides

Stefania Makrygiannaki edited this page Jun 29, 2020 · 5 revisions

Modules can modify prefabs from other modules. This is useful if a module needs to add additional components to existing prefabs, e.g. a module that renders health bars could add a HealthBar component to minion prefabs from another module. Another case is the replacement or disabling of features, e.g. disabling a component that makes trees age but keeps the rest of the tree to create a world with never-aging trees.

For both purposes, each module provides a deltas and an overrides folder.

The main difference:

deltas -> Override or add single values in one prefab
overrides -> override the entire prefab

Example

Prefab Example

Take the following component from Module A as example:

public class ValuesComponent implements Component {
    public String a;
    public String b;
    public String c;
    public String d;
}

Module A could define the a prefab with this component like so, e.g. in Module A/assets/prefabs/anyfolder/valueThing.prefab:

{
    "values" : {
        "a" : "aa",
        "b" : "bb",
        "c" : "cc",
        "d" : "dd"
    }
}

If we instanciate an entity from this prefab, the ValuesComponent would have the values a=aa, b=bb, c=cc, d=dd.

UI Example

Let's say we have the following json UI file into a Module B e.g. in Module B/assets/ui/anyFolder/moduleBUi.ui, and a skin e.g. in Module B/assets/skins/anyfolder/SkinInModuleB.skin which is used in the moduleBUi.ui:

UI file:

{
    "type": "ModuleB:AType",
    "skin": "ModuleB:SkinInModuleB"
}

Deltas

Prefab Example

Deltas modify an existing prefab by keeping existing values. We can use deltas to change values or to add components.

Let's say Module B wants to modify the valueThing.prefab, so that the value d becomes d=CHANGED. and also add a BoxShapeComponent to the thing. The module has to define the file Module B/deltas/Module A/prefabs/anyfolder/valueThing.prefab:

{
    "values" : {
        "d" : "CHANGED"
    },
    "boxShape": {
    }
}

The general path for a delta is always deltas/<Name of the origin module>/prefabs/<same directory structure>/<prefab>. If we instanciate the valueThing in Module B, the ValueComponent has the properties a=aa, b=bb, c=cc, d=CHANGED and the entity will also have a BoxShapeComponent attached.

The main difference to the overrides is, that Module B/deltas/Module A/prefabs/anyfolder/valueThing.prefab

{
    "boxShape": {
    }
}

would still contain the ValueComponent with the properties a=aa, b=bb, c=cc, d=dd from Module A

UI Example

Currently, Deltas modify an existing UI by keeping all it existing values. But, we can use deltas to only change assigned skin file for now. To do that: You have another module, Module D, and want to use moduleBUi.ui from Module B, but with a different skin which you have created within Module D, the Module D/assets/skins/anyFolder/SkinInModuleD.skin

All you have to do to achieve that is to have a delta UI file within Module D at Module D/delta/Module B/ui/anyFolder/moduleBUi.ui, with only the new skin written inside:

{ "skin": "SkinInModuleD" }

Overrides

Prefab Example

Let's say Module C wants to remove the ValueComponent at all and replace the entire prefab with something else.

Module b could define Module C/overrides/Module A/prefabs/anyfolder/valueThing.prefab

{
    "Location": {}
}

The general path for overrides is similar to deltas: overrides/<Name of the origin module>/prefabs/<same directory structure>/<prefab>

In this case, an entity created from the valueThing.prefab in Module C has no ValueComponent because the entire prefab is overridden and has only a LocationComponent left.

The main difference to the deltas is, that the entire file is replaced with the new content.

UI Example

If you want to use the whole UI file from another module, but make more changes than just a skin, you need to use Overrides. What overrides does, is to replace the previously used UI screen within the module (e.g. core elements like the inventory or health) with newly structured design that you define.

Let's say that you want to use the common health bar in a Module E, but change its position to the top left. You do want to keep all its other attributes and functionalities, except its position. What you have to do, is

  • find where the original UI for the health bar is, which is at Health/assets/ui/hud/healthHud.ui (usually it's in a folder structured like ModuleName/assets/ui/anyFolder/theUiYouLookFor.ui)
  • create a new UI file at Module E/overrides/Health/ui/hud/healthHud.ui (structure: NewModule/overrides/OldModuleName/ui/anyFolder/moduleYouWantToOverrideName.ui)
  • place the exact same code that the file in the Health module has (you can copy-paste it) and change the attributes you want to be changed