You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AssetEntry is a specialized interface that extends the `StaticEntry`.
5
-
It is primarily used for handling static assets within the game.
6
-
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.
7
-
The key attribute of AssetEntry is the path, which specifies the location of the asset.
3
+
# Asset & Artifact Entries
4
+
Assets and artifacts are both handled through similar interfaces that extend `StaticEntry`. Assets are static files like images, sounds, or other external resources, while artifacts are assets that are generated by the server at runtime.
5
+
6
+
## AssetEntry
7
+
The `AssetEntry` is primarily used for handling static assets. Assets can include various types of files such as images, data, or other external resources that can be used by an extension.
8
+
9
+
## ArtifactEntry
10
+
The `ArtifactEntry` is a specialized interface derived from `AssetEntry`. Its primary purpose is to handle artifacts, which are assets generated by the extensions. Unlike standard assets, artifacts are usually dynamic and created during runtime and stored between restarts. This makes them particularly useful for storing data arbitrary configuration data. As artifacts loaded in on reload, they are not suitable for storing real-time data.
8
11
9
12
## Usage
10
-
Here's a generic example of creating and using an `AssetEntry`:
"content": " // Next dialogue should be triggered or the current dialogue should complete its typing animation.\n DialogueTrigger.NEXT_OR_COMPLETE.triggerFor(player, context())\n\n // Forces the next dialogue to be triggered, even if the animation hasn't finished.\n DialogueTrigger.FORCE_NEXT.triggerFor(player, context())"
96
+
"content": " // Next dialogue should be triggered or the current dialogue should complete its typing animation.\n DialogueTrigger.NEXT_OR_SKIP_ANIMATION.triggerFor(player, context())\n\n // Forces the next dialogue to be triggered, even if the animation hasn't finished.\n DialogueTrigger.FORCE_NEXT.triggerFor(player, context())"
"content": "class ExampleInteraction(\n val player: Player,\n override val context: InteractionContext,\n override val priority: Int,\n val eventTriggers: List<EventTrigger>\n) : Interaction {\n override suspend fun initialize(): Result<Unit> {\n if (Random.nextBoolean()) {\n // Failing during initialization makes it so that the interaction will be stopped.\n return failure(\"Failed to initialize\")\n }\n\n // Setup your interaction state\n player.sendMessage(\"Starting interaction!\")\n\n return ok(Unit)\n }\n\n override suspend fun tick(deltaTime: Duration) {\n // Update your interaction state\n if (shouldEnd()) {\n // Trigger the stop event when done\n ExampleStopTrigger.triggerFor(player, context)\n }\n }\n\n override suspend fun teardown(force: Boolean) {\n // Cleanup your interaction state\n player.sendMessage(\"Ending interaction!\")\n }\n\n private fun shouldEnd(): Boolean = false // Your end condition\n}"
140
+
"content": "class ExampleInteraction(\n val player: Player,\n override val context: InteractionContext,\n override val priority: Int,\n val eventTriggers: List<EventTrigger>\n) : Interaction {\n override suspend fun initialize(): Result<Unit> {\n if (Random.nextBoolean()) {\n // Failing during initialization makes it so that the interaction will be stopped.\n return failure(\"Failed to initialize\")\n }\n\n // Setup your interaction state\n player.sendMessage(\"Starting interaction!\")\n\n return ok(Unit)\n }\n\n override suspend fun tick(deltaTime: Duration) {\n // Update your interaction state\n if (shouldEnd()) {\n // Trigger the stop event when done\n ExampleStopTrigger.triggerFor(player, context)\n }\n }\n\n override suspend fun teardown() {\n // Cleanup your interaction state\n player.sendMessage(\"Ending interaction!\")\n }\n\n private fun shouldEnd(): Boolean = false // Your end condition\n}"
"content": "suspend fun accessArtifactData(ref: Ref<out ArtifactEntry>) {\n val assetManager = KoinJavaComponent.get<AssetManager>(AssetManager::class.java)\n val entry = ref.get() ?: return\n val content: String? = assetManager.fetchAsset(entry)\n // Do something with the content\n}"
228
+
"content": "suspend fun accessArtifactData(ref: Ref<out ArtifactEntry>) {\n val assetManager = KoinJavaComponent.get<AssetManager>(AssetManager::class.java)\n val entry = ref.get() ?: return\n val stringContent: String? = assetManager.fetchStringAsset(entry)\n // Do something with the string content\n}"
"content": "suspend fun accessBinaryArtifactData(ref: Ref<out ArtifactEntry>) {\n val assetManager = KoinJavaComponent.get<AssetManager>(AssetManager::class.java)\n val entry = ref.get() ?: return\n val binaryContent: ByteArray? = assetManager.fetchBinaryAsset(entry)\n // Do something with the binary content\n}"
"content": "suspend fun accessArtifactDataUsingHelpers(ref: Ref<out ArtifactEntry>) {\n val entry = ref.get() ?: return\n\n // Check if artifact has data\n if (entry.hasData()) {\n // Access string data using helper method\n val stringContent: String? = entry.stringData()\n\n // Access binary data using helper method\n val binaryContent: ByteArray? = entry.binaryData()\n\n // Store string data\n entry.stringData(\"Updated artifact content\")\n\n // Store binary data\n entry.binaryData(byteArrayOf(1, 2, 3, 4, 5))\n }\n}"
"content": "suspend fun accessAssetData(ref: Ref<out AssetEntry>) {\n val assetManager = KoinJavaComponent.get<AssetManager>(AssetManager::class.java)\n val entry = ref.get() ?: return\n val content: String? = assetManager.fetchAsset(entry)\n // Do something with the content\n}"
244
+
"content": "suspend fun accessAssetData(ref: Ref<out AssetEntry>) {\n val assetManager = KoinJavaComponent.get<AssetManager>(AssetManager::class.java)\n val entry = ref.get() ?: return\n val stringContent: String? = assetManager.fetchStringAsset(entry)\n // Do something with the string content\n}"
"content": "suspend fun accessBinaryAssetData(ref: Ref<out AssetEntry>) {\n val assetManager = KoinJavaComponent.get<AssetManager>(AssetManager::class.java)\n val entry = ref.get() ?: return\n val binaryContent: ByteArray? = assetManager.fetchBinaryAsset(entry)\n // Do something with the binary content\n}"
"content": "suspend fun accessAssetDataUsingHelpers(ref: Ref<out AssetEntry>) {\n val entry = ref.get() ?: return\n\n // Check if asset has data\n if (entry.hasData()) {\n // Access string data using helper method\n val stringContent: String? = entry.stringData()\n\n // Access binary data using helper method\n val binaryContent: ByteArray? = entry.binaryData()\n\n // Store string data\n entry.stringData(\"Updated content\")\n\n // Store binary data\n entry.binaryData(byteArrayOf(1, 2, 3, 4, 5))\n }\n}"
"content": "@Entry(\"example_event_with_context_keys\", \"An example event entry with context keys.\", Colors.YELLOW, \"material-symbols:bigtop-updates\")\n// This tells Typewriter that this entry exposes some context\n// highlight-next-line\n@ContextKeys(ExampleContextKeys::class)\nclass ExampleEventEntryWithContextKeys(\n override val id: String = \"\",\n override val name: String = \"\",\n override val triggers: List<Ref<TriggerableEntry>> = emptyList(),\n) : EventEntry\n\n// highlight-start\nenum class ExampleContextKeys(override val klass: KClass<*>) : EntryContextKey {\n // The two `String::class` have to be the same.\n // The @KeyType is for the panel to know\n @KeyType(String::class)\n // The type here is for casting during runtime\n TEXT(String::class),\n\n @KeyType(Int::class)\n NUMBER(Int::class),\n\n // More complex types are also allowed.\n @KeyType(Position::class)\n POSITION(Position::class)\n}\n// highlight-end\n\n@EntryListener(ExampleEventEntryWithContextKeys::class)\nfun onEventAddContext(event: SomeBukkitEvent, query: Query<ExampleEventEntryWithContextKeys>) {\n val entries = query.find()\n // highlight-start\n entries.triggerAllFor(event.player) {\n // Make sure these values are drawn from the event.\n // You MUST supply all the context keys.\n ExampleContextKeys.TEXT withValue \"Hello World\"\n ExampleContextKeys.NUMBER withValue 42\n ExampleContextKeys.POSITION withValue Position.ORIGIN\n }\n // highlight-end\n}"
316
+
"content": "@Entry(\n \"example_event_with_context_keys\",\n \"An example event entry with context keys.\",\n Colors.YELLOW,\n \"material-symbols:bigtop-updates\"\n)\n// This tells Typewriter that this entry exposes some context\n// highlight-next-line\n@ContextKeys(ExampleContextKeys::class)\nclass ExampleEventEntryWithContextKeys(\n override val id: String = \"\",\n override val name: String = \"\",\n override val triggers: List<Ref<TriggerableEntry>> = emptyList(),\n) : EventEntry\n\n// highlight-start\nenum class ExampleContextKeys(override val klass: KClass<*>) : EntryContextKey {\n // The two `String::class` have to be the same.\n // The @KeyType is for the panel to know\n @KeyType(String::class)\n // The type here is for casting during runtime\n TEXT(String::class),\n\n @KeyType(Int::class)\n NUMBER(Int::class),\n\n // More complex types are also allowed.\n @KeyType(Position::class)\n POSITION(Position::class)\n}\n// highlight-end\n\n@EntryListener(ExampleEventEntryWithContextKeys::class)\nfun onEventAddContext(event: SomeBukkitEvent, query: Query<ExampleEventEntryWithContextKeys>) {\n val entries = query.find()\n // highlight-start\n entries.triggerAllFor(event.player) {\n // Make sure these values are drawn from the event.\n // You MUST supply all the context keys.\n ExampleContextKeys.TEXT withValue \"Hello World\"\n ExampleContextKeys.NUMBER withValue 42\n ExampleContextKeys.POSITION withValue Position.ORIGIN\n }\n // highlight-end\n}"
0 commit comments