Adding a Plugin

Ludiek is designed as a plugin first-architecture. Common game mechanics are distilled to their core and captured in plugins that focus on one thing only!

Don’t worry if that sounds too abstract. We will take a look at the simplest plugin first: The Currency Plugin!

Currency Plugin

Nearly every game needs to deal with some sort of currency management: gold coins dropped by slain monsters, quest points from completed quests, or the amount of antimatter in the universe.

It contains functionality for gaining, losing and paying specific amounts of money.

import { CurrencyPlugin } from '@123ishatest/ludiek';

// Create the plugin and load in content
const currencyPlugin = new CurrencyPlugin();
currencyPlugin.loadContent([{ id: '/currency/money' }]);

// Gain and lose some money
currencyPlugin.gainCurrency('/currency/money', 3);
currencyPlugin.loseCurrency('/currency/money', 2);

// Paying can only be done if we have enough money
const isPaid = currencyPlugin.payCurrency('/currency/money', 5);
console.log(isPaid); // false, we didn't have enough

Demo

You have 0 money!

Content

There is one thing we glossed over: we have to tell the plugin which Currencies exist in our game. The data that plugins (and your game) operate over is called Content and will be explained in the next section!