crnormand / gurps

Implementing a GURPS 4e game aid for Foundry VTT
MIT License
105 stars 49 forks source link

Feature Request: Import GCA/GCS Player Data as Foundry Items #1966

Closed chrismaille closed 1 month ago

chrismaille commented 2 months ago

Updated on 09-07-24

Oh boy, this seems big.

Indeed, this is a significant change.

Currently, GGA does not use the Foundry Item Framework, except for dragged items. To handle player data, we use the Actor Component classes to store data received from GCA/GCS imports. For example, inventory is handled by the Equipment class, which is saved inside GurpsActor in actor.system.equipment, split between carried and other items. It uses fairly complex code that handles recursive logic to manage "parent" and "child" items—think of a sword inside a bag of holding inside a backpack.

The proposal is to add a new settings option: GURPS.settingUseFoundryItems, allowing the system to create Foundry items for not only equipment but also Advantages, Disadvantages, Skills, and Spells. The default value is disabled.

When enabled, on the next import, GGA will:

  1. Look for an existing GurpsItem for imported GCA/GCS traits, equipment, skills, or spells. If it exists, it will preserve the Item data, like name, image, counts, uses, and notes.
  2. Recursively create the GurpsItems. This can be a very long operation for GCS sheets on the first install. On subsequent imports, only the modified items will be imported.
  3. For equipment, create the actor.system.equipment as-is, linking the corresponding itemId.
  4. For other traits, create the correct actor.system.<key> object as-is, linking the corresponding itemId.
  5. If the GurpsItem is modified, the system will reflect the change in the corresponding actor.system.<key> object.

When disabled, on the next import, GGA will:

  1. Remove all GurpsItems previously created via import for that actor. Only imported items will be affected, not items from Compendium (dragged items) or those created by the user (saved items).
  2. Create the actor.system.<key> objects as-is, preserving data from removed GurpsItems (name, count, uses, notes) in the ActorComponent.itemInfo property.

The Settings:

image

The operation (using a GCA-generated character with a fairly small inventory):

GCAImport

The New Item Experience

To make this work, the Item sheet was reworked to handle Items, Spells, Skills, and Traits. For example, here is the Skill Item Sheet:

image

If you do not set the import field (the 'Roll' field), the system will use the otf field (the 'Skill Level' field) to define the skill target. If you set the import field, the system will use the number you defined.

More signs in the Actor Sheet.

The Actor sheet now shows an icon when the trait/skill/spell is from another Item or if the item was dragged from the compendium:

image

The blue icon is for dragged items (has globalid). The dark orange is for items generated from other items (has fromItem). The tooltip indicates the origin Item or the Global item which generated them.

Ok, but why this?

First, to make use of the Foundry Items Framework. Second, to offer an alternative to current GURPS Worlds in GGA, allowing export to another game system, like GCSGA, using an exported Compendium. I'm not sure if GCSGA developers will opt for this approach, but at least we can work with items like this (using Ripper93's Paper Doll):

GGADrag

By the way, this works for items even if the setting is disabled.

Ok, but I have some doubts

Q. What happens to my already created items?
A. The expected behavior is not to change any non-imported items from GCA/GCS. In other words, if you manually created an item on the sheet, it will remain unchanged by this code.

Q. What happens to item data that does not exist in Equipment, like the Image, if I disable this option?
A. All item-exclusive data will be backed up inside the Equipment object (system.itemInfo). If you enable it again, on the next import, a new item will be created with the same data as the previous one.

Q. Can I drag and drop items between actors created from different generators? One in GCA and another in GCS, for example?
A. Yes, on the next import, the system will ignore items from the other generator, preserving that item on the sheet.

Q. Can I work with both options - Items and Equipment - at the same time, in different Actors/Sheets?
A. For the imported items, no, to avoid some nasty bugs. If you enable or disable the option, you'll need to reimport all your actors to recreate items or equipment. A dialog will remind you to reimport the sheet. User-created or Compendium items work as intended, whether this option is enabled or not.

Q. Why does the import take so long?
A. Because the items are truly saved in the database. This is an expensive operation for JavaScript, and the current code is not optimized for that. This is an even bigger refactoring.

Nice, how can I test this?

  1. First, please, please, back up your game world.
  2. Make sure your GCS or GCA character is up-to-date with their Actor counterpart.
  3. Enable the settings and reimport all your actors.
  4. If you want to revert to the classic equipment, just disable the option and import all Actors again.

I've tested this code extensively, but there are many scenarios to cover. Any help is appreciated.