Output

Output lets you produces resources within your game. For example

  • Currency that can be gained.
  • The unlocking of achievements.
  • Rolling on a loot table.

Its counterpart, Input, can be used to consume resources.

In Ludiek, Outputs are an abstract Engine concept. You provide an output shape and logic to produce the output. At runtime, the Engine queries the registered producers and invokes their produce method.

Sounds complicated? It’s really not! Let’s take a look at the Currency Plugin. It provides the CurrencyOutput.

First we define the shape of what an instance of our output should look like:

interface CurrencyOutput extends BaseOutput {
  type: '/output/gain-currency';
  id: string;
  amount: number;
}

And we extend a LudiekProducer for the consuming currency logic:

// This tells the engine that this producer depends on the currency plugin
type Dependencies = {
  plugins: [CurrencyPlugin];
};

export class CurrencyProducer extends LudiekProducer<CurrencyOutput, Dependencies> {
  readonly type = '/output/gain-currency';

  canProduce(): boolean {
    return true;
  }

  produce(output: CurrencyOutput): void {
    this.engine.plugins.currency.gainCurrency(output);
  }
}

And we can use it fully type-safe!

game.engine.produce({
  type: '/output/gain-currency',
  id: '/currency/money',
  amount: 100,
});

Any game content can now use this output!