Skip to content

KotlinResources

ManApart edited this page Mar 21, 2021 · 1 revision

Kotlin Resources

Overview

Kotlin Resources are my attempt to make data files more dynamic. I had started all data as json, but found querying game state for things like quest events or behaviors to be really hard to express with Json.

Modability

The hope is that one day user jars can be provided and at startup any kotlin resource files can also be picked up and used

Behaviors example

Start by taking a look at ReflectionTools, as it generates resource files by taking a Resource Interface and a base Class. In our example, it takes a BehaviorResource class and a Behavior Class. It then generates the other files for us. (You need to manually add the collection -> generated piece to the DependencyInjector).

Name Kotlin Type Generated Purpose
Behavior Any No The object you're actually creating
BehaviorResource Interface No Each subtype in the resources package can be organized and grouped. The interface tells reflection it should be used when generating the final collection.
BehaviorsCollection Interface Yes Promises to return a List<Behavior>
BehaviorsGenerated Subtype of BehaviorsCollection Yes Grabs all BehaviorResource subtypes in the resources package and adds them to a list for the game to use
BehaviorsMock Subtype of BehaviorsCollection Yes A mock implementation used for testing
Clone this wiki locally