We’d probably update IdentityTrait as such:
interface IdentityTrait extends ITrait {
type: TraitType.IDENTITY;
name: string;
description: string | DescriptionProvider;
firstTimeDescription?: string; // Special first-time text
examined?: boolean; // Track if examined before
}
and use DescriptionProvider to handle special cases:
interface DescriptionProvider {
type: 'static' | 'random' | 'conditional' | 'function';
// For static
text?: string;
// For random
variations?: string[];
// For conditional
conditions?: {
condition: string; // Reference to a check function
text: string;
}[];
// For function (loaded at runtime, not serialized)
provider?: (entity: IFEntity, context: any) => string;
}
…which would look something like…
const painting = {
traits: {
[TraitType.IDENTITY]: {
name: 'old painting',
description: {
type: 'random',
variations: [
'The painting depicts a stormy seascape, waves crashing against jagged rocks.',
'Looking at the painting, you notice subtle details in the brushwork suggesting hidden depths.',
'The painting seems to shift slightly as you look at it, the waves almost appearing to move.',
'Dark clouds dominate the painting\'s sky, with a barely visible ship on the horizon.'
]
}
}
}
}
..or..
const mirror = {
traits: {
[TraitType.IDENTITY]: {
name: 'ornate mirror',
description: {
type: 'conditional',
conditions: [
{
condition: 'is_broken',
text: 'The mirror is shattered into a spider web of cracks, distorting your reflection into a thousand fragments.'
},
{
condition: 'is_dirty',
text: 'The mirror\'s surface is covered in dust and grime, showing only a vague outline of your form.'
},
{
condition: 'default',
text: 'The ornate mirror reflects your image clearly in its polished surface.'
}
]
}
}
}
}
..but this is just a swag. These are the kinds of “tree-shaking” things that still need to happen.