Skip to content

Commit

Permalink
example changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingPig525 committed Jun 6, 2024
1 parent 5f1d139 commit 20d6a7a
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 48 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/publish.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,24 @@ open class Template<T>(
val IfGame = IfGameCategory(this)
val Control = ControlCategory(this)

fun callFunction(function: Template<T>) = callFunction(function.name)
fun callFunction(name: String) {
blocks += CallFunctionBlock(name)
}
fun callProcess(name: String) {
blocks += CallProcessBlock(name)
}

fun invokeTemplate(template: Template<T>) {
if (template.blocks[0] is FunctionBlock) {
callFunction(template.name)
return
}
if (template.blocks[0] is ProcessBlock) {
callProcess(template.name)
return
}
throw Error("Cannot invoke Event template!")
}

fun Else(wrappedCode: Template<T>.() -> Unit) {
blocks += ElseBlock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class RepeatCategory<T> internal constructor(private val template: Template<T>)
) {
blocks += Block("repeat", ItemCollection(items).items, action)
blocks += BracketBlock(type = "repeat")
blocks += io.github.flyingpig525.base.Template(
io.github.flyingpig525.base.Template.Type.NONE,
blocks += Template(
Template.Type.NONE,
a = wrappedCode
).blocks
blocks += BracketBlock(false, "repeat")
Expand Down Expand Up @@ -201,9 +201,8 @@ class RepeatCategory<T> internal constructor(private val template: Template<T>)
* Repeats code indefinitely.
*/
fun forever(
items: Items<T>,
wrappedCode: Template<T>.() -> Unit
) = block(items, "Forever", wrappedCode)
) = block({}, "Forever", wrappedCode)

/**
* Repeats code once per entry in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.flyingpig525.base.item

import io.github.flyingpig525.base.JsonData

open class Item(val id: ID) {
var slot = 0

Expand All @@ -25,7 +27,7 @@ open class Item(val id: ID) {
fun <T> getItemJsonArgument(
item: T,
slot: Int? = null
): String where T : Item, T : io.github.flyingpig525.base.JsonData = """
): String where T : Item, T : JsonData = """
{
"item": {
"id": "${item.id}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.flyingpig525.base.item

class ItemCollection<T>(func: ItemCollection<T>.() -> Unit) where T : Item, T : io.github.flyingpig525.base.JsonData {
import io.github.flyingpig525.base.JsonData

class ItemCollection<T>(func: ItemCollection<T>.() -> Unit) where T : Item, T : JsonData {
val items: MutableList<T> = mutableListOf()

init {
Expand All @@ -9,7 +11,7 @@ class ItemCollection<T>(func: ItemCollection<T>.() -> Unit) where T : Item, T :

operator fun T.unaryPlus() = also { addItem(it) }

private fun addItem(item: T) {
fun addItem(item: T) {
items += item.apply {
slot = items.size
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

class GameValue(private val type: String, private var target: Target = Target.Default) : Item(ID.GAMEVALUE),
io.github.flyingpig525.base.JsonData {
JsonData {
override fun getJsonData(): String {
return """
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

class LocItem(val x: Float, val y: Float, val z: Float, val pitch: Float = 0f, val yaw: Float = 0f) : Item(ID.LOCATION),
io.github.flyingpig525.base.JsonData {
JsonData {

constructor(x: Int, y: Int, z: Int, pitch: Int = 0, yaw: Int = 0) : this(
x.toFloat(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

/**
* @param [nbt] NEVER making an item creator thing, so you have to get the nbt data yourself
*/
class MinecraftItem(val nbt: String) : Item(ID.ITEM), io.github.flyingpig525.base.JsonData {
class MinecraftItem(val nbt: String) : Item(ID.ITEM), JsonData {
override fun getJsonData(): String {
return """
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

class NumItem(private val value: Float) : Item(ID.NUMBER), io.github.flyingpig525.base.JsonData {
class NumItem(private val value: Float) : Item(ID.NUMBER), JsonData {

constructor(value: Int) : this(value.toFloat())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

class StringItem(val text: String) : Item(ID.STRING), io.github.flyingpig525.base.JsonData {
class StringItem(val text: String) : Item(ID.STRING), JsonData {

constructor(text: Char) : this(text.toString())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

class TextItem(val text: String) : Item(ID.RICHTEXT), io.github.flyingpig525.base.JsonData {
class TextItem(val text: String) : Item(ID.RICHTEXT), JsonData {
constructor(text: Char) : this(text.toString())

override fun getJsonData(): String = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.flyingpig525.base.item.type

import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

/*
Expand All @@ -12,7 +13,7 @@ import io.github.flyingpig525.base.item.Item
}
*/
class VarItem(val name: String, val scope: Scope = Scope.GAME) : Item(ID.VAR),
io.github.flyingpig525.base.JsonData {
JsonData {
enum class Scope(private val value: String) {
GAME("unsaved"),
LOCAL("local"),
Expand Down
41 changes: 31 additions & 10 deletions KotlinFire/src/test/kotlin/org/example/LibraryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
*/
package org.example

import io.github.flyingpig525.base.EventTemplate
import io.github.flyingpig525.base.Template.Type.*
import io.github.flyingpig525.base.TemplateCollection
import io.github.flyingpig525.base.block.PLAYEREVENT
import io.github.flyingpig525.base.item.type.LocItem
import io.github.flyingpig525.base.item.type.MinecraftItem
import io.github.flyingpig525.base.item.type.MinecraftItem.Companion.toMinecraftItem
import io.github.flyingpig525.base.item.type.NumItem.Companion.toNumItem
import io.github.flyingpig525.base.item.type.TextItem.Companion.toTextItem
import io.github.flyingpig525.base.item.type.VarItem
import io.github.flyingpig525.base.item.type.VarItem.Scope.*
import io.github.flyingpig525.base.item.type.VarItem.Companion.toVarItem
import kotlin.test.Test
class LibraryTest {
@Test fun caveGen() {
@Test fun caveGenExample() {
TemplateCollection {
println(EventTemplate(PLAYEREVENT.Join) {
EventTemplate(PLAYEREVENT.Join) {
PlayerAction.teleport {
+LocItem(0, 100, 0)
}
Expand Down Expand Up @@ -51,15 +49,24 @@ class LibraryTest {
}

}
}.getTemplateString())
codeClientPlaceTemplates()
}
// Uncomment this when trying out this example
// codeClientPlaceTemplates()
}
}

@Test fun helloWorldExample() {
@Test fun clickerExample() {
TemplateCollection {
val playerMoney = "%uuid money".toVarItem(SAVE)

val actionBarLoop = Template(PROCESS, "actionBarLoop") {
Repeat.forever {
PlayerAction.actionBar {
+"<green>Money: $playerMoney".toTextItem()
}
}
}

EventTemplate(PLAYEREVENT.Join) {
IfVar.varExists(
{
Expand All @@ -86,18 +93,32 @@ class LibraryTest {
PlayerAction.giveItems {
+"item".toVarItem(LINE)
}

invokeTemplate(actionBarLoop)
}

EventTemplate(PLAYEREVENT.RightClick) {
SetVariable.increment {
+playerMoney
}
PlayerAction.sendMessage {
+"<gradient:#7f52ff:#e3455d>Hello KotlinFire world!".toTextItem()
+"<gradient:#7f52ff:#e3455d>$playerMoney".toTextItem()
}
}
codeClientPlaceTemplates()
// Uncomment this when trying out this example
// codeClientPlaceTemplates()
}
}

@Test fun helloWorldExample() {
TemplateCollection {
EventTemplate(PLAYEREVENT.Join) {
PlayerAction.sendMessage {
+"<gradient:#7f52ff:#e3455d>Hello KotlinFire World!".toTextItem()
}
}
// Uncomment this when trying out this example
// codeClientPlaceTemplates()
}
}
}

0 comments on commit 20d6a7a

Please sign in to comment.