Config ID
Config ID is the unique identifier for each config entry. In a regular table it is the first column, while in a tree-backed regular table it is the root map key.
Supported Types
Section titled “Supported Types”| Category | Types |
|---|---|
| String | string |
| Signed integers | int, int8, int16, int32, int64 |
| Unsigned integers | uint, uint8, uint16, uint32, uint64 |
The default type is int64 for a regular table, and int for a tree-backed regular table.
Changing the Data Type
Section titled “Changing the Data Type”In a regular table, place a $%[=type] marker in any cell of the first row:
$% → type: string$%=string → type: string$%=int8 → type: int8$%=int32 → type: int32$%=uint64 → type: uint64In a tree-backed regular table, declare the root map as map[K], where the key type K is the config ID type.
Examples
Section titled “Examples”| $%=string | ||
| Desc | Hero name | Hero level |
| Name | name | level |
| Type | string | int32 |
| hero1 | Arthur | 10 |
| hero2 | Merlin | 15 |
| Desc | Hero name | Hero level | $%=uint8 |
| Name | name | level | |
| Type | string | int32 | |
| 1 | Arthur | 10 | |
| 2 | Merlin | 15 |
Cross-Table References
Section titled “Cross-Table References”The config ID serves as the lookup key when referencing a config entry via the ref type. Similarly, backref and backref-n resolve back-references using config IDs under the hood.
Anchor
Section titled “Anchor”Adding an anchor field to a regular table with integer config IDs bridges the gap between opaque numbers and meaningful names, making ref fields much easier to fill and read. For example, provided the config ID 101 has an anchor value of sword, you can enter sword in a ref cell instead of 101.
| Desc | Weapon name | - |
| Name | name | anchor |
| Type | string | anchor |
| 101 | Sword | sword |
| 102 | Shield | shield |
| Desc | Hero name | Equipped weapon |
| Name | name | weapon |
| Type | string | ref@weapon |
| 1 | Arthur | sword |
| 2 | Merlin | 102 |
Resolving a Config Entry
Section titled “Resolving a Config Entry”In the generated code, a config ID is not a plain int64 or string. Each regular table has its own ID type, and that type carries a shortcut straight to the config entry it identifies — so you can go from an ID to its entry without holding onto the table and looking it up by hand.
The HeroCfgID type has a Cfg() method. It returns the matching *HeroCfg through the global GetConfigAtlas().
type HeroCfgID int64
func (x HeroCfgID) Cfg() *HeroCfg { return GetConfigAtlas().HeroTable[x]}
type HeroCfg struct { Name string // ... other fields}
var cfgID HeroCfgID = 1name := cfgID.Cfg().Name // <-- one hop from ID to config entryThe HeroCfgId type has a Cfg property. It returns the matching HeroCfg through the static ConfigAtlas.Instance.
public partial struct HeroCfgId{ public long Value; public readonly HeroCfg Cfg => ConfigAtlas.Instance.HeroTable[Value]!;}
public partial class HeroCfg{ public string Name { get; set; } // ... other fields}
HeroCfgId cfgId = 1;string name = cfgId.Cfg.Name; // <-- one hop from ID to config entry