space-wizards / RobustToolbox

Robust multiplayer game engine, used by Space Station 14
https://spacestation14.io
Other
535 stars 393 forks source link

really need a way to add/remove items from component fields #5141

Open deltanedas opened 4 months ago

deltanedas commented 4 months ago

something like

- type: entity
  id: Base
  components:
  - type: Tag
    tags:
    - A
    - B

- type: Entity
  parent: Base
  id: Extended
  components:
  - type: Tag
    tags: !Add
    - C # A B C

- type: entity
  parent: Base
  id: Removed
  components:
  - type: Tag
    tags: !Remove
    - A # just B

then "just" handle the Add Remove markers by looking up the parent prototype and adding or removing

presumably this would only be possible on fields of the component, and not fields of those fields

  1. this would make maintaining tags specifically a hell of a lot easier, no random thing overwriting it which has happened countless times
  2. this would make a lot of fork work easier since you can shrimply add a tag and done dont have to copy paste it into every single descendant
K-Dynamic commented 4 months ago

Was literally just thinking about this

deltanedas commented 3 months ago

another example usecase

# pai that can play music
- type: entity
  id: PAIMusic
  - type: UserInterface
    interfaces:
      enum.MusicUiKey.Key:
        type: MusicBoundUserInterface

# pai that has map AND music
- type: entity
  parent: PAIMusic
  id: PAIMap
  components:
  - type: UserInterface
    interfaces: !Add
      enum.MapUiKey.Key:
        type: MapBoundUserInterface

# an expansion card that adds a userinterface regardless of what the pai already had
# so ComponentRegistry has to support this syntax too
# right now this has a shitty boilerplate AddUserInterface component that does this by hand
- type: entity
  id: CoolCard
  components:
  - type: PAIExpansionCard
    components:
    - type: UserInterface
      interfaces: !Add
        enum.CoolUiKey.Key:
          type: CoolUserInterface

# combining add and remove in the entity prototype and a registry
# a card that removes midi player if you are a bad person, and also has the cool ui
- type: entity
  parent: CoolCard
  id: EvilCard
  components:
  - type: PAIExpansionCard
    components: !Add # keep the CoolUi with this module
    - type: UserInterface
      interfaces: !Remove # uses just key instead of key: value
      - enum.MusicUiKey.Key
deltanedas commented 1 month ago
  - type: ChemicalPayload
    beakerSlotA: &slotDef                                                                                                                                                                                             
      whitelist:                                                                                                                                                                                                      
        components:                                                                                                                                                                                                   
        - FitsInDispenser                                                                                                                                                                                             
      swap: false                                                                                                                                                                                                     
    beakerSlotB: *slotDef

it seems to be already parsing special stuff to copy paste, so there must be a way this could be implemented, maybe reusing the symbols if ! isnt possible