
//-- this file is generated! don't try editing it.

import "luxe: io" for IO
import "luxe: bytes" for Byter, Bytes
import "luxe: world" for Block

//`blocks/human/human > runtime` types

  class ModifierRuntime {

    construct new() {
    } //new
    
  } //ModifierRuntime

//`blocks/human/human > runtime` compilers

  class ModifierRuntimeCompiler {

    construct new() {
    }

    bytes_count(instance) {

      var size = 4 //version

      size = size + 0
      
      return size

    } //bytes_count

    validate(from_source_id, elements) {

      var fields = {
        "type": false, //:luxe:internal
        "uuid": false, //:luxe:internal
        "luxe.self.modifier": false, //:luxe:internal
      }
      for(element in elements) {
        var instance = element.value
        for(field in instance) {
          if(fields[field.key] == null) {
            Fiber.abort("node `%(element.key)` in `%(from_source_id)` has extra field `%(field.key)`")
          } //if not found
        } //each field
        for(field in fields) {
          var required = field.value
          if(required && instance[field.key] == null) {
            Fiber.abort("node `%(element.key)` in `%(from_source_id)` is missing a required field `%(field.key)` (and the field has no default value)")
          }
        } //each field
      } //each element

    } //validate

    write(compiler, instance, out) {

      //version
      out.write_int32(0)

      return out

    } //write

    bytes_count_block() {

      return 8

    } //bytes_count_block

    write_block(compiler, out) {

      //source id
      out.write_uint32(compiler.string.hash("blocks/human/human > runtime"))

      //fields count
      out.write_int32(0)

    } //write_block

    write(instance) {

      var size = bytes_count(instance)
      var out = Byter.new(size+8)

      out.write_string("LUXEMRTM")

      write(instance, out)

      return out

    } //write

  } //ModifierRuntimeCompiler

//`blocks/human/human > runtime` block types

  class BlockModifierRuntime {

    field { "human" }
    source { "blocks/human/human > runtime" }

    construct new(block) {
      _block = block
      _inst_type = instance_type
      _inst = _inst_type.new(_block, 0)
    }

    construct new() {
      _block = Block.create()
      _inst_type = instance_type
      _inst = _inst_type.new(_block, 0)
      Block.set_type(_block, "blocks/human/human > runtime")
    } //new

    instance_type {

      class BlockInstModifierRuntime {
        slot { _slot }
        entity { Block.get_handle(_block, _slot) }
        block_set_slot(value) {
          _slot=value
          return this
        }
        construct new(block, slot) {
          _block = block
          _slot = slot
        } //new
        block { _block }
      } //BlockInstModifierRuntime

      return BlockInstModifierRuntime

    } //instance_type

    block { _block }
    count { Block.get_count(_block) }
    add() { Block.add(_block) }
    append(other_block) { Block.append(_block, other_block) }
    each(c, fn) {
      for(i in 0 ... c) {
        fn.call(0, _inst.block_set_slot(i))
      }
    } //each

    [slot, inst] { _inst.block_set_slot(slot) }

    [slot] { _inst_type.new(_block, slot) }
  } //BlockModifierRuntime
  

//`blocks/human/human > data` types

  class ModifierData {

    construct new() {
      _active = true
      _name = "unnamed"
      _color = [1, 0, 0]
    } //new
    
    active { _active }
    active=(vvv) { _active = vvv }

    name { _name }
    name=(vvv) { _name = vvv }

    color { _color }
    color=(vvv) { _color = vvv }

  } //ModifierData

//`blocks/human/human > data` compilers

  class ModifierDataCompiler {

    construct new() {
    }

    bytes_count(instance) {

      var size = 4 //version

      size = size + 4 // active

      size = size + 4 // name

      size = size + 12 // color

      size = size + 0
      
      return size

    } //bytes_count

    validate(from_source_id, elements) {

      var fields = {
        "type": false, //:luxe:internal
        "uuid": false, //:luxe:internal
        "luxe.self.modifier": false, //:luxe:internal
        "active": false,
        "name": false,
        "color": false,
      }
      for(element in elements) {
        var instance = element.value
        for(field in instance) {
          if(fields[field.key] == null) {
            Fiber.abort("node `%(element.key)` in `%(from_source_id)` has extra field `%(field.key)`")
          } //if not found
        } //each field
        for(field in fields) {
          var required = field.value
          if(required && instance[field.key] == null) {
            Fiber.abort("node `%(element.key)` in `%(from_source_id)` is missing a required field `%(field.key)` (and the field has no default value)")
          }
        } //each field
      } //each element

    } //validate

    write(compiler, instance, out) {

      //version
      out.write_int32(0)

      var active = instance["active"]
      if(active == null) active = true
        out.write_int32(active ? 1 : 0)


      var name = instance["name"]
      if(name == null) name = "unnamed"
        out.write_uint32((name && name != "") ? compiler.string.hash(name) : 0)


      var color = instance["color"]
      if(color == null) color = [1, 0, 0]
        out.write_float32(color[0])
        out.write_float32(color[1])
        out.write_float32(color[2])


      return out

    } //write

    bytes_count_block() {

      return 52

    } //bytes_count_block

    write_block(compiler, out) {

      //source id
      out.write_uint32(compiler.string.hash("blocks/human/human > data"))

      //fields count
      out.write_int32(3)

      // active
        out.write_uint32(compiler.string.hash("active"))
        out.write_uint32(1710517951) //type boolean
        var active_default = true
          out.write_int32(active_default ? 1 : 0)


      // name
        out.write_uint32(compiler.string.hash("name"))
        out.write_uint32(2729592961) //type id32
        var name_default = "unnamed"
          out.write_uint32((name_default && name_default != "") ? compiler.string.hash(name_default) : 0)


      // color
        out.write_uint32(compiler.string.hash("color"))
        out.write_uint32(1025475970) //type float3
        var color_default = [1, 0, 0]
          out.write_float32(color_default[0])
          out.write_float32(color_default[1])
          out.write_float32(color_default[2])


    } //write_block

    write(instance) {

      var size = bytes_count(instance)
      var out = Byter.new(size+8)

      out.write_string("LUXEMDTA")

      write(instance, out)

      return out

    } //write

  } //ModifierDataCompiler

//`blocks/human/human > data` block types

  class BlockModifierData {

    field { "human" }
    source { "blocks/human/human > data" }

    construct new(block) {
      _block = block
      _inst_type = instance_type
      _inst = _inst_type.new(_block, 0)
    }

    construct new() {
      _block = Block.create()
      _inst_type = instance_type
      _inst = _inst_type.new(_block, 0)
        Block.add(_block, "active", "boolean", true)
        Block.add(_block, "name", "id32", "unnamed")
        Block.add(_block, "color", "float3", [1, 0, 0])
      Block.set_type(_block, "blocks/human/human > data")
    } //new

    instance_type {

      class BlockInstModifierData {
        active { Block.get(_block, "active", _slot) }
        active=(v) { Block.set(_block, "active", _slot, v) }
        name { Block.get(_block, "name", _slot) }
        name=(v) { Block.set(_block, "name", _slot, v) }
        color { Block.get(_block, "color", _slot) }
        color=(v) { Block.set(_block, "color", _slot, v) }
        slot { _slot }
        entity { Block.get_handle(_block, _slot) }
        block_set_slot(value) {
          _slot=value
          return this
        }
        construct new(block, slot) {
          _block = block
          _slot = slot
        } //new
        block { _block }
      } //BlockInstModifierData

      return BlockInstModifierData

    } //instance_type

    block { _block }
    count { Block.get_count(_block) }
    add() { Block.add(_block) }
    append(other_block) { Block.append(_block, other_block) }
    each(c, fn) {
      for(i in 0 ... c) {
        fn.call(0, _inst.block_set_slot(i))
      }
    } //each

    [slot, inst] { _inst.block_set_slot(slot) }

    [slot] { _inst_type.new(_block, slot) }
  } //BlockModifierData
  

//`blocks/human/human > world` types

  class ModifierWorld {

    construct new() {
    } //new
    
  } //ModifierWorld

//`blocks/human/human > world` compilers

  class ModifierWorldCompiler {

    construct new() {
    }

    bytes_count(instance) {

      var size = 4 //version

      size = size + 0
      
      return size

    } //bytes_count

    validate(from_source_id, elements) {

      var fields = {
        "type": false, //:luxe:internal
        "uuid": false, //:luxe:internal
        "luxe.self.modifier": false, //:luxe:internal
      }
      for(element in elements) {
        var instance = element.value
        for(field in instance) {
          if(fields[field.key] == null) {
            Fiber.abort("node `%(element.key)` in `%(from_source_id)` has extra field `%(field.key)`")
          } //if not found
        } //each field
        for(field in fields) {
          var required = field.value
          if(required && instance[field.key] == null) {
            Fiber.abort("node `%(element.key)` in `%(from_source_id)` is missing a required field `%(field.key)` (and the field has no default value)")
          }
        } //each field
      } //each element

    } //validate

    write(compiler, instance, out) {

      //version
      out.write_int32(0)

      return out

    } //write

    bytes_count_block() {

      return 8

    } //bytes_count_block

    write_block(compiler, out) {

      //source id
      out.write_uint32(compiler.string.hash("blocks/human/human > world"))

      //fields count
      out.write_int32(0)

    } //write_block

    write(instance) {

      var size = bytes_count(instance)
      var out = Byter.new(size+8)

      out.write_string("LUXEMWLD")

      write(instance, out)

      return out

    } //write

  } //ModifierWorldCompiler

//`blocks/human/human > world` block types

  class BlockModifierWorld {

    field { "human" }
    source { "blocks/human/human > world" }

    construct new(block) {
      _block = block
      _inst_type = instance_type
      _inst = _inst_type.new(_block, 0)
    }

    construct new() {
      _block = Block.create()
      _inst_type = instance_type
      _inst = _inst_type.new(_block, 0)
      Block.set_type(_block, "blocks/human/human > world")
    } //new

    instance_type {

      class BlockInstModifierWorld {
        slot { _slot }
        entity { Block.get_handle(_block, _slot) }
        block_set_slot(value) {
          _slot=value
          return this
        }
        construct new(block, slot) {
          _block = block
          _slot = slot
        } //new
        block { _block }
      } //BlockInstModifierWorld

      return BlockInstModifierWorld

    } //instance_type

    block { _block }
    count { Block.get_count(_block) }
    add() { Block.add(_block) }
    append(other_block) { Block.append(_block, other_block) }
    each(c, fn) {
      for(i in 0 ... c) {
        fn.call(0, _inst.block_set_slot(i))
      }
    } //each

    [slot, inst] { _inst.block_set_slot(slot) }

    [slot] { _inst_type.new(_block, slot) }
  } //BlockModifierWorld
  
