Skip to content

Commit

Permalink
Start working on adapter development documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Dec 2, 2023
1 parent d898d0a commit 0ba6ec9
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 16 deletions.
File renamed without changes.
106 changes: 106 additions & 0 deletions documentation/docs/develop/02-adapters/02-getting_started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: Getting Started
---

# Creating an Adapter
## Introduction
TypeWriter is a dynamic platform that supports the development of adapters, which are modular components enhancing the overall functionality. Adapters are self-contained, easily shareable, and integrate smoothly into the TypeWriter system. This guide is tailored to guide you through the process of creating an adapter, suitable for both beginners and experienced developers.

## Prerequisites
- Java Development Kit (JDK) 17 or higher.
- An Integrated Development Environment (IDE) such as IntelliJ IDEA or Eclipse.
- A basic understanding of Gradle and the Spigot API.

## Step 1: Setting Up a Gradle Project
Begin by establishing a Gradle project for your TypeWriter adapter. Below is a comprehensive setup for your `build.gradle.kts`:

```kotlin title="build.gradle.kts"
plugins {
kotlin("jvm") version "1.8.20"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

// Replace with your own information
group = "me.yourusername"
version = "0.0.1"

repositories {
maven("https://jitpack.io")
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://libraries.minecraft.net/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.codemc.io/repository/maven-snapshots/")
maven("https://repo.opencollab.dev/maven-snapshots/")

// Add other necessary repositories
}

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("com.github.gabber235:typewriter:main-SNAPSHOT") // Latest release version

// Already included in the TypeWriter plugin but still needed for compilation
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-RC")
compileOnly("com.github.dyam0:LirandAPI:96cc59d4fb")
compileOnly("net.kyori:adventure-api:4.13.1")
compileOnly("net.kyori:adventure-text-minimessage:4.13.1")

// Add other dependencies as needed
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
```

Ensure to replace placeholders like `me.yourusername` with your project details.

### Choosing the TypeWriter Version
Select the appropriate TypeWriter dependency version:
For stable and tested features, use the latest release version:
```kotlin
compileOnly("com.github.gabber235:typewriter:main-SNAPSHOT")
```
This is suitable for most development needs and is recommended for general adapter creation.

If you need the latest features and improvements (which might be unstable), use the latest development version:
```kotlin
compileOnly("com.github.gabber235:typewriter:develop-SNAPSHOT")
```
Note that this version may include changes that are not yet fully tested or documented.

If you need a specific version, visit the [JitPack page](https://jitpack.io/#gabber235/typewriter) and select the version you need.

## Step 2: Creating an Adapter Class
After setting up your project, create an adapter class. Here's an example:
kotlin title="ExampleAdapter.kt"
```kotlin
import me.gabber235.typewriter.adapters.Adapter
import me.gabber235.typewriter.adapters.TypewriteAdapter

@Adapter("Example", "An example adapter for documentation purposes", "0.0.1")
object ExampleAdapter : TypewriteAdapter() {
override fun initialize() {
// Any initializations needed to run the adapter.
}
}
```


## Step 3: Building the Adapter
After creating the adapter class, build the adapter. This can be done by running the `shadowJar` Gradle task.
This will generate a JAR file in the `build/libs` directory.
This JAR file can be used as an adapter in TypeWriter.
Place the JAR file in the `plugins/TypeWriter/adapters` directory and restart the server.
Typewriter will automatically load the adapter and run it.

If any problems occur, check the console for errors and ensure that the adapter is properly configured.
If you need help, join the [Discord server](https://discord.gg/HtbKyuDDBw) and ask for help.

## What's Next?
After creating an adapter, you can start adding features to it.
Check out the [Creating Entries](creating-entries) guide to learn how to add entries to your adapter.
44 changes: 44 additions & 0 deletions documentation/docs/develop/02-adapters/03-entries/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Create Entries
Creating adapters for the TypeWriter Spigot plugin involves working with various entry types, each serving a specific
purpose in crafting immersive player experiences.
This documentation explains the roles and functionalities of these entry types, providing clear guidance for developers on how to effectively use them.

## Base Entry Interfaces
There are three base interfaces that all entries extend atleast one of. These are:
1. **StaticEntry**: Represents static pages. These are used for content that does not change dynamically or trigger any actions. Examples include static text or images.
2. **TriggerEntry**: Designed for entries that initiate other actions or events. These entries can trigger one or more additional entries, making them crucial for interactive sequences.
3. **CinematicEntry**: Used for cinematic experiences. These entries are ideal for creating immersive story-driven sequences that engage players in a more visually dynamic way.


### 1. StaticEntry
- **AssetEntry**: Handles external assets, like images or files.
- **ArtifactEntry**: Manages plugin-generated assets, such as JSON files.
- **EntityEntry**: Serves as a base for static entities in the game.
- **SpeakerEntry**: Extends EntityEntry for entities capable of speaking, with defined display names and sounds.
- **FactEntry**: Represents static facts or data points.
- **SoundIdEntry**: Holds identifiers for specific sounds.
- **SoundSourceEntry**: Deals with the sources of sound emissions.

### 2. TriggerEntry
- **EventEntry**: A base for entries that are event-driven.
- **CustomCommandEntry**: Extends EventEntry to allow for the creation of custom in-game commands.

#### 2a. TriggerableEntry (an extension of TriggerEntry)
These are entries that can be triggered by other entries. They are the most common type of entry, and are used for creating interactive sequences.
- **DialogueEntry**: Specialized for dialogues with specific speakers, enhancing NPC interactions.
- **ActionEntry**: Executes actions based on player interactions, capable of modifying facts or triggering events.
- **CustomTriggeringActionEntry**: A variant of ActionEntry, allowing for custom trigger mechanisms and manual triggering of actions.

### 3. CinematicEntry
- Primarily used for crafting cinematic experiences in-game, this base interface doesn't have listed specialized interfaces, but it's pivotal for creating story-driven, visually dynamic sequences.


## Implementation and Usage
Each interface is designed with specific tags and methods to facilitate unique interactions within the TypeWriter plugin.
Implementing these interfaces allows developers to craft a wide range of player experiences, from simple static displays to complex, multi-step interactive quests and dialogues.

For instance, a TriggerableEntry can be used to set up a quest that only activates under certain conditions, while a DialogueEntry can bring an NPC to life with personalized dialogues.
Similarly, an ActionEntry can be used to create dynamic effects that change based on player actions, and a CinematicEntry can be used to create a visually dynamic story sequence.

In summary, these entry interfaces form the backbone of the TypeWriter plugin's functionality, offering a robust framework for creating immersive and interactive content within Minecraft.
By understanding and utilizing these interfaces, developers can greatly enhance the player experience, making it more engaging and dynamic.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
label: Static Entries
20 changes: 20 additions & 0 deletions documentation/docs/develop/02-adapters/03-entries/static/asset.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# AssetEntry
The AssetEntry is a specialized interface that extends the StaticEntry in the TypeWriter Spigot plugin.
It is primarily used for handling static assets within the game.
Assets can include various types of files such as images, sounds, or other external resources that are crucial to enhancing the game environment and player experience.
The key attribute of AssetEntry is the path, which specifies the location of the asset.

## Usage
```kotlin
@Entry("example_asset", "An example asset entry.", Colors.PINK, Icons.PERSON_WALKING)
class ExampleAssetEntry(
override val path: String = "",
): AssetEntry
```

To get the asset from the entry, you can use the following code:
```kotlin
val id = // ID of the entry
val entry = Query.findById<ExampleAssetEntry>(id)
val path = entry.path
```
10 changes: 10 additions & 0 deletions documentation/docs/develop/02-adapters/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Adapters
## Introduction
TypeWriter is a dynamic platform that supports the development of adapters, which are modular components enhancing the overall functionality. Adapters are self-contained, easily shareable, and integrate smoothly into the TypeWriter system. This guide is tailored to guide you through the process of creating an adapter, suitable for both beginners and experienced developers.

:::info
It is highly recommended to write adapters in Kotlin, as it is the primary language of TypeWriter. However, it is also possible to write adapters in Java, as long as the adapter is compiled into a `.jar` file.
:::

## Guides
- [Getting Started](getting-started)
1 change: 0 additions & 1 deletion documentation/docs/docs/02-installation-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ websocket:
port: 9092
# The authentication that is used. Leave unchanged if you don't know what you are doing.
auth: "session"

panel:
# The panel can be disabled while the sockets are still open. Only disable this if you know what you are doing.
# If the web sockets are disabled then the panel wil always be disabled.
Expand Down
10 changes: 5 additions & 5 deletions documentation/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const { themes } = require('prism-react-renderer');
const lightTheme = themes.github;
const darkTheme = themes.dracula;
import { themes } from 'prism-react-renderer';
const lightTheme = themes.vsLight;
const darkTheme = themes.vsDark;

/** @type {import('@docusaurus/types').Config} */
const config = {
Expand Down Expand Up @@ -136,7 +136,7 @@ const config = {
prism: {
theme: lightTheme,
darkTheme: darkTheme,
additionalLanguages: ['kotlin', 'yaml'],
additionalLanguages: ['kotlin', 'yaml', 'java', 'log'],
magicComments: [
{
className: 'highlight-red',
Expand Down Expand Up @@ -172,4 +172,4 @@ const config = {
]
};

module.exports = config;
export default config;
4 changes: 4 additions & 0 deletions documentation/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
border-radius: 0.5rem;
}

code span {
margin: 0;
}

.highlight-red {
background-color: #ff000020; /* Light red background */
border-left: 3px solid #ff000080; /* Darker red border */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ package me.gabber235.typewriter.entry.entries
import me.gabber235.typewriter.adapters.Tags
import me.gabber235.typewriter.adapters.modifiers.EntryIdentifier
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.entry.*
import me.gabber235.typewriter.entry.Query
import me.gabber235.typewriter.entry.TriggerableEntry

@Tags("dialogue")
interface DialogueEntry : TriggerableEntry {
@Help("The speaker of the dialogue")
@EntryIdentifier(SpeakerEntry::class)
val speaker: String
//val text: String
@Help("The speaker of the dialogue")
@EntryIdentifier(SpeakerEntry::class)
val speaker: String

val speakerDisplayName: String
get() = speakerEntry?.displayName ?: ""

val speakerDisplayName: String
get() = speakerEntry?.displayName ?: ""

val speakerEntry: SpeakerEntry?
get() = Query.findById(speaker)
val speakerEntry: SpeakerEntry?
get() = Query.findById(speaker)
}

0 comments on commit 0ba6ec9

Please sign in to comment.