{
  "settings": {},
  "classes": {
    "unlit": {
      "background_color": "#303238",
      "color": "#aeb4c0",
      "icon_color": "#7b8494"
    },
    "lit": {
      "background_color": "#fff2a6",
      "color": "#664400",
      "icon_color": "#cf8c00",
      "is_shining": true
    }
  },
  "elements": {
    "Charger": {
      "display": "Charger",
      "is_static": true,
      "description": "Combine with one or more Light Bulbs. Only participating bulbs gain 10 charge, up to 100."
    },
    "Bulb": {
      "display": [
        {
          "type": "icon",
          "name": "lightbulb"
        },
        " Light Bulb [",
        {
          "type": "bind",
          "target": {
            "name": "charge",
            "precision": 0
          }
        },
        "]",
        {
          "type": "progress",
          "value": {
            "type": "bind",
            "target": {
              "name": "charge"
            }
          }
        }
      ],
      "class": "unlit",
      "is_static": true,
      "description": "Select this bulb to turn it on. It glows and uses 1 charge per tick. Selecting another bulb turns the previous one off. Empty bulbs turn off. Recharge at Charger and select again.",
      "custom_props": {
        "charge": {
          "scope": "local",
          "type": "number",
          "value": 100,
          "events": {
            "min": {
              "value": 0
            },
            "max": {
              "value": 100
            },
            "at": {
              "value": 0,
              "do": [
                {
                  "type": "set_class",
                  "target": {
                    "uuid": {
                      "type": "computed",
                      "expression": "el_uuid()"
                    }
                  },
                  "class": "unlit"
                }
              ]
            }
          }
        },
        "active": {
          "type": "array",
          "value": []
        }
      },
      "events": {
        "on_tick": {
          "is_enabled": true,
          "do": [
            {
              "type": "set",
              "target": {
                "id": "Bulb",
                "filter": "el_uuid() in g('Bulb', 'active') and l(el_uuid(), 'charge') > 0",
                "limit": -1,
                "name": "charge"
              },
              "value": {
                "type": "computed",
                "expression": "l(el_uuid(), 'charge') - 1"
              }
            }
          ]
        }
      }
    }
  },
  "events": {
    "on_start": [
      "Charger",
      "Bulb",
      "Bulb",
      "Bulb"
    ],
    "on_join": [],
    "on_leave": []
  },
  "reactions": [
    {
      "reagents": [
        "Charger",
        {
          "id": "Bulb",
          "limit": -1
        }
      ],
      "result": [
        {
          "type": "set",
          "target": {
            "from": "reagents",
            "id": "Bulb",
            "limit": -1,
            "name": "charge"
          },
          "value": {
            "type": "computed",
            "expression": "l(el_uuid(), 'charge') + 10"
          }
        }
      ]
    },
    {
      "reagents": [
        {
          "id": "Bulb",
          "alias": "selected"
        }
      ],
      "result": [
        {
          "type": "set_class",
          "target": {
            "id": "Bulb",
            "filter": "el_uuid() in g('Bulb', 'active')",
            "limit": -1
          },
          "class": "unlit"
        },
        {
          "type": "set",
          "target": {
            "id": "Bulb",
            "name": "active"
          },
          "value": {
            "type": "computed",
            "expression": "group('selected')"
          }
        },
        {
          "type": "set_class",
          "target": {
            "from": "selected",
            "filter": "l(el_uuid(), 'charge') > 0"
          },
          "class": "lit"
        }
      ]
    }
  ]
}
