Packages
r8 is a modular engine and instead of depending on a big monolithic game engine you can add the packages you need.
Add Package Dependency
To add the internationalization package i18n
you can run this command from within the app root directory. You may skip the version, in that case the latest available will be used, or master of there are no releases available.
r8 config --add packages i18n@0.1.0
Remove Package Dependency
If you do not longer want to depend on the internationalization package you run this command. Note that you must provide the version of the package.
r8 config --remove packages i18n@0.1.0
Create a Package
Create a folder and cd
into it.
mkdir mypackage
cd mypackage
r8 package --init
package name? [Empty Package] My Package
initialized a new package 'My Package' in /home/klarre/dev/mypackage
r8 package --init --create-directory --title 'My Package'
initialized a new package 'My Package' in /home/klarre/dev/mypackage
The config.yml
file looks like this.
---
title: My Package
version: 0.1.0
In some packages you may wish to listen to life cycle events, such as onCreate
and onDestroy
. This can be achieved by registering your package as a life cycle package. You will need to add a life-cycle
config entry and also implement the Core::LifeCycle
class.
r8 config --set life-cycle MyLifeCycle
#pragma once
#include <r8/core/life-cycle.h>
#include <r8/core/log.h>
class MyLifeCycle
: public Core::LifeCycle
{
private:
void onCreate() override {
LogInfo("MyLifeCycle::onCreate");
}
void onDestroy() override {
LogInfo("MyLifeCycle::onDestroy");
}
};