nvs / map

Warcraft 3 map management tools
MIT License
18 stars 6 forks source link

Allow generation of Jass files with object modifications #43

Closed nvs closed 5 years ago

nvs commented 5 years ago

Basically, create corresponding Jass files for all object data. This would allow one to generate object data in Lua, and expose it to the Jass files. An example would be.

local map = ...
local objects = map.objects

local builder = {
    label = 'Builder'
    type = 'unit', 
    base = 'hpea'
}

builder.ugol = {
    type = 'integer',
    value = 0
}

-- This would automatically generate an id for the object.
objects.add_unit (builder)

-- This would use the specified id.
objects.u000 = builder

--
local ability = {
    label = 'Example',
    type = 'ability',
    base = 'AAns'
}

ability.atp1 = {
    type = 'string',
    values = {
        [1] = 'Example'
    }
}

This would then produce the following Jass:

globals
    // No prefix, no label, and specified id.
    constant integer u000_ugol = 0

    // No prefix, no label, and generated id.
    constant integer x000_ugol = 0

    // With a prefix option.
    constant integer Objects__u000_ugol = 0
    constant integer Objects__x000_ugol = 0

    // With both a prefix and label.
    constant integer Objects__Builder_ugol = 0

    // And for objects with multiple levels of a modification.
    constant string Objects__Example_atp1_001 = "Example"
endglobals

The reasoning behind a label is that the ability to automatically generate the object id could exist. It would be impossible to guess the id within a Jass file. Thus the need for a label to allow more consistent naming. The label would obviously be specific to each individual object. Clashes should probably raise an error. The prefix would be defined in the global configuration file.

As far as automatic generation of ids, consider looking at https://github.com/wurstscript/WurstStdlib2/blob/master/wurst/objediting/presets/ObjectIdGenerator.wurst. Of particular note is that heroes seem to expect an object id starting with a capitalized letter. Need to look into the details. If this is the case, a list of base objects that have the hero modification flag set by default can be included. Additionally, checking for the hero modification flag will need to be done regardless.

As far as why generation of Jass files is acceptable, any unused globals can simply be ignored when building the map script. Wurst already does this.

But, this may not even be needed. Native Lua support is rumored to be added with Reforged. In such a situation, the above behavior could be used as well. But new natives may be introduced also. This has not been officially announced, so I wouldn't place much stock in the idea yet.

nvs commented 5 years ago

An alternative option is to simply leverage Wurst. Of course, this depends on the individual project.

nvs commented 5 years ago

This is no longer necessary. A higher level object definition library can be introduced, whose files can simply be included into the war3map.lua if desired. That library does not need to be part of Map.