Metadata on Items

Things that we aren't going to implement
Post Reply
havvy
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Aug 29, 2014 9:49 pm
Contact:

Metadata on Items

Post by havvy »

There are three proposals here. They all try to solve the same problem -- giving the modder a place to put data that isn't touched by the internal game engine.

I'm a bit tired, so I might not explain well here. Ask questions if you're confused.

1) Allow the creation of new "types". These types would be extensions of basic items and cleverly map to some number of C++ classes. Basically, the modder describes what fields there are, whether they are mutable once the item is created, and whether the field is an int or a float. Also possibly have readonly fields that only exist on the Lua prototype table. By only allowing up to four fields, you only need 5 C++ classes. The main benefits this has over the other two proposals is that it lets the modder better describe what they're doing, giving them express control over naming and types. It's easier to remember 'life' than it is to remember 'meta3' for instance. The main drawback is that it's more complex to implement.

Code: Select all

data:extend({
    type= "item-type",
    name= "breeder",
    field1= {name="fertility", type="float", readonly=true},
    field2= {name="lifespan", type="int", readonly=true},
    field3= {name="life", type="int", readonly=false},
    statics = {"output"="string", quality="int"}
},

{
    type ="breeder" -- As per the type defined above
    name ="juice-breeder",
    -- Omitted: All the usual item properties like icon and flags
    output = "breeder-juice"
    quality = 1
}
})

-- And then to create a juice-breeder, one of the following
jb = game.createentity(name="juice-breeder", position=somePosition, fields={fertility=0.2, lifespan=5000, life=5000})
jb = game.createentityof("breeder")(name="juice-breeder", position=somePosition, fertility=0.2, lifespan=5000, life=5000)

-- And then to mutate a property
jb.life = jb.life - 1

-- And then to read a static property
print(jb.output) -- "breeder-juice"
2) Add a fat-item type with four floating point fields called meta1 through meta4. All fields would be mutable. Possibly also have the String->String map, but accessed directly. The drawback to this one is that the modder cannot rename the meta property names nor choose mutability and numeric type of the field. The benefits are that it maps to one class.

Code: Select all

data:extend({
  type="fat-item"
  name="juice-breeder",
  -- Omitted usual item properties as per previous example.
  static={"output"="breeder-juice"}, -- actually, being able to define properties like this on all prototypes would be nice.
  meta2 = 5000.0, -- default value if not explicitly defined during instantiation.
  meta3 = 5000.0, -- default value is 0.0 if not left out, such as meta1 here.
})

-- Creating a juice-breeder
jb = createfatentity(name="juice-breeder", position=somePosition, meta1=0.20)

-- Reading the static properties.
jb.static.output -- "breeder-juice"
3) Add a metadata field (float) to all entity types. This is probably not a good idea, because it'll make saves even slower than they currently are.

Post Reply

Return to “Won't implement”