boardgame.io
Version:
library for turn-based games
41 lines (32 loc) • 809 B
text/typescript
/*
* Copyright 2018 The boardgame.io Authors
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
import type { Plugin } from '../types';
interface LogData {
metadata?: any;
}
export interface LogAPI {
setMetadata(metadata: any): void;
}
/**
* Plugin that makes it possible to add metadata to log entries.
* During a move, you can set metadata using ctx.log.setMetadata and it will be
* available on the log entry for that move.
*/
const LogPlugin: Plugin<LogAPI, LogData> = {
name: 'log',
flush: () => ({}),
api: ({ data }) => {
return {
setMetadata: (metadata) => {
data.metadata = metadata;
},
};
},
setup: () => ({}),
};
export default LogPlugin;