Skip to content

Commit

Permalink
i have no idea what just happened :|
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingPig525 committed Jun 5, 2024
1 parent eadf1b3 commit 158abe5
Show file tree
Hide file tree
Showing 43 changed files with 13,608 additions and 12,325 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions KotlinFire/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ plugins {
kotlin("jvm") version "1.9.23"

`java-base`
`maven-publish`

}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.github.flyingpig525"
artifactId = "KotlinFire"
version = "0.6"

from(components["java"])
}
}
}


repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
Expand Down Expand Up @@ -44,8 +58,12 @@ java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}

withSourcesJar()
withJavadocJar()
}


tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ import io.github.flyingpig525.base.block.EventBlock
import io.github.flyingpig525.base.block.PLAYEREVENT
import io.github.flyingpig525.base.item.Item

class EventTemplate<T> private constructor(event: EventBlock<T>, a: Template<T>.() -> Unit) : Template<T>(Template.Type.EVENT, "", a) where T : Item, T : JsonData {
class EventTemplate<T> private constructor(
event: EventBlock<T>,
a: Template<T>.() -> Unit
) : Template<T>(
Type.EVENT, "", a
) where T : Item, T : JsonData {

constructor(event: PLAYEREVENT, a: Template<T>.() -> Unit) : this(EventBlock(event.type, event.event), a)
constructor(event: ENTITYEVENT, a: Template<T>.() -> Unit) : this(EventBlock(event.type, event.event), a)
constructor(event: PLAYEREVENT, a: Template<T>.() -> Unit) : this(
EventBlock(
event.type,
event.event
), a
)

constructor(event: ENTITYEVENT, a: Template<T>.() -> Unit) : this(
EventBlock(
event.type,
event.event
), a
)

init {
blocks[0] = event
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package io.github.flyingpig525.base

interface JsonData {
fun getJsonData(): String
fun getJsonData(): String
}
60 changes: 40 additions & 20 deletions KotlinFire/src/main/kotlin/io/github/flyingpig525/base/Template.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import org.jetbrains.annotations.ApiStatus.Internal
typealias Items<T> = ItemCollection<T>.() -> Unit

@Suppress("LeakingThis")
open class Template<T>(type: Type = Type.FUNCTION, val name: String = "PutNameHere", a: Template<T>.() -> Unit) : JsonData where T : Item, T : JsonData {
open class Template<T>(
type: Type = Type.FUNCTION,
val name: String = "PutNameHere",
a: Template<T>.() -> Unit
) :
JsonData where T : Item, T : JsonData {
val blocks: MutableList<Block<T>> = mutableListOf()
val SetVariable = SetVariableCategory(this)
val EntityAction = EntityActionCategory(this)
Expand All @@ -34,25 +39,20 @@ open class Template<T>(type: Type = Type.FUNCTION, val name: String = "PutNameHe
fun callFunction(name: String) {
blocks += CallFunctionBlock(name)
}

fun Else(wrappedCode: Template<T>.() -> Unit) {
blocks += ElseBlock()
blocks += BracketBlock(type = "norm")
blocks += Template(Template.Type.NONE, a = wrappedCode).blocks
blocks += Template(
Type.NONE,
a = wrappedCode
).blocks
blocks += BracketBlock(false, "norm")
}

private var event: EventBlock<T> = EventBlock(PLAYEREVENT.Join.type, PLAYEREVENT.Join.event)

constructor(event: PLAYEREVENT, a: Template<T>.() -> Unit) : this(Type.EVENT, "", a) {
this.event = EventBlock(event.type, event.event)
}
constructor(event: ENTITYEVENT, a: Template<T>.() -> Unit) : this(Type.EVENT, "", a) {
this.event = EventBlock(event.type, event.event)
}

init {
if (type != Type.NONE) {
blocks += when(type) {
blocks += when (type) {
Type.FUNCTION -> FunctionBlock(name)
Type.PROCESS -> ProcessBlock(name)
// This will get changed by `EventTemplate`
Expand Down Expand Up @@ -92,39 +92,55 @@ open class Template<T>(type: Type = Type.FUNCTION, val name: String = "PutNameHe
developmentMode = true
}
runBlocking {
client.webSocket(method = HttpMethod.Post, host = "localhost", port = 31371, path = "/codeutilities/item") {
send("""
client.webSocket(
method = HttpMethod.Post,
host = "localhost",
port = 31371,
path = "/codeutilities/item"
) {
send(
"""
{
"type": "template",
"source": "KotlinFire",
"data": "${template.getJsonData().replace("\"", "\\\"")}"
}
""".trimIndent()
.replace("\n", "") + "\n"
.replace("\n", "") + "\n"
)
}
}
}

private val codeClientHttp = HttpClient(Java) {
install(WebSockets)
}

fun <T> codeClientPlaceTemplate(template: Template<T>) where T : Item, T : JsonData {
runBlocking {
codeClientHttp.webSocket(method = HttpMethod.Get, host = "localhost", port = 31375) {
codeClientHttp.webSocket(
method = HttpMethod.Get,
host = "localhost",
port = 31375
) {
val inc = incoming.receive()
if ("auth" in String(inc.data)) {
send("place ${template.getTemplateString()}")
send("place go")
}
incoming.receive()
close(CloseReason(CloseReason.Codes.NORMAL,"Function done."))
close(CloseReason(CloseReason.Codes.NORMAL, "Function done."))
}
}
}

fun <T> codeClientPlaceMultipleTemplates(templates: List<Template<T>>) where T : Item, T : JsonData {
runBlocking {
codeClientHttp.webSocket(method = HttpMethod.Get, host = "localhost", port = 31375) {
codeClientHttp.webSocket(
method = HttpMethod.Get,
host = "localhost",
port = 31375
) {
val inc = incoming.receive()
if ("auth" in String(inc.data)) {
send("place swap")
Expand All @@ -134,18 +150,22 @@ open class Template<T>(type: Type = Type.FUNCTION, val name: String = "PutNameHe
send("place go")
}
incoming.receive()
close(CloseReason(CloseReason.Codes.NORMAL,"Function done."))
close(CloseReason(CloseReason.Codes.NORMAL, "Function done."))
}
}
}
}
fun <T> codeClientPlaceMultipleTemplates(vararg templates: Template<T>) where T : Item, T : JsonData = Companion.codeClientPlaceMultipleTemplates(templates.toList())

fun <T> codeClientPlaceMultipleTemplates(vararg templates: Template<T>) where T : Item, T : JsonData =
codeClientPlaceMultipleTemplates(templates.toList())

enum class Type {
FUNCTION,
PROCESS,

@Internal
NONE,

@Internal
EVENT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@ import io.github.flyingpig525.base.item.Item

class TemplateCollection<T>(a: TemplateCollection<T>.() -> Unit) where T : Item, T : JsonData {
private val templates: MutableList<Template<T>> = mutableListOf()
fun EventTemplate(event: PLAYEREVENT, applier: Template<T>.() -> Unit): EventTemplate<T> {
fun EventTemplate(
event: PLAYEREVENT,
applier: Template<T>.() -> Unit
): EventTemplate<T> {
val temp = EventTemplate<T>(event, applier)
templates += temp
return temp
}
fun EventTemplate(event: ENTITYEVENT, applier: Template<T>.() -> Unit): EventTemplate<T> {

fun EventTemplate(
event: ENTITYEVENT,
applier: Template<T>.() -> Unit
): EventTemplate<T> {
val temp = EventTemplate<T>(event, applier)
templates += temp
return temp
}

fun Template(type: Template.Type = Template.Type.FUNCTION, name: String = "PutNameHere", applier: Template<T>.() -> Unit): Template<T> {
fun Template(
type: Template.Type = Template.Type.FUNCTION,
name: String = "PutNameHere",
applier: Template<T>.() -> Unit
): Template<T> {
val temp = Template(type, name, applier)
templates += temp
return temp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package io.github.flyingpig525.base.block

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

open class Block<T>(val codeBlock: String, var items: MutableList<T>, val action: String, val extra: String = "") :
JsonData where T : Item, T : JsonData {
io.github.flyingpig525.base.JsonData where T : Item, T : io.github.flyingpig525.base.JsonData {
init {
var i = 0
items = items.map { item ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.github.flyingpig525.base.block

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

class BracketBlock<T>(val open: Boolean = true, val type: String) : JsonData, Block<T>("bracket", mutableListOf(), "") where T : Item, T : JsonData {
override fun getJsonData(): String {
return """{
class BracketBlock<T>(val open: Boolean = true, val type: String) : io.github.flyingpig525.base.JsonData,
Block<T>("bracket", mutableListOf(), "") where T : Item, T : io.github.flyingpig525.base.JsonData {
override fun getJsonData(): String {
return """{
"id": "bracket",
"direct": "${if (open) "open" else "close"}",
"type": "$type"
}""".trimIndent()
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.github.flyingpig525.base.block

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

class CallFunctionBlock<T>(funcName: String) : Block<T>("call_func", mutableListOf(), "", "data: \"$funcName\"") where T : Item, T : JsonData
class CallFunctionBlock<T>(funcName: String) : Block<T>(
"call_func",
mutableListOf(),
"",
"data: \"$funcName\""
) where T : Item, T : io.github.flyingpig525.base.JsonData
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.github.flyingpig525.base.block

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

class CallProcessBlock<T>(processName: String) : Block<T>("call_process", mutableListOf(), "", "data: \"$processName\"") where T : Item, T : JsonData
class CallProcessBlock<T>(processName: String) : Block<T>(
"call_process",
mutableListOf(),
"",
"data: \"$processName\""
) where T : Item, T : io.github.flyingpig525.base.JsonData
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.github.flyingpig525.base.block

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

class ElseBlock<T> : Block<T>("else", mutableListOf(), "") where T : Item, T : JsonData {
override fun getJsonData(): String {
return """
class ElseBlock<T> : Block<T>("else", mutableListOf(), "") where T : Item, T : io.github.flyingpig525.base.JsonData {
override fun getJsonData(): String {
return """
{
"id": "block",
"block": "$codeBlock"
}
""".trimIndent()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@file:Suppress("UNUSED")

package io.github.flyingpig525.base.block

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

class EventBlock<T>(val type: Type, event: String) : Block<T>("process", mutableListOf(), event) where T : Item, T : JsonData {
override fun getJsonData(): String {
return """
class EventBlock<T>(val type: Type, event: String) :
Block<T>("process", mutableListOf(), event) where T : Item, T : io.github.flyingpig525.base.JsonData {
override fun getJsonData(): String {
return """
{
"id": "block",
"block": "$type",
Expand All @@ -16,15 +17,15 @@ class EventBlock<T>(val type: Type, event: String) : Block<T>("process", mutable
"action": "$action"
}
"""
}
}

enum class Type(val type: String) {
ENTITYEVENT("entity_event"),
PLAYEREVENT("event");
enum class Type(val type: String) {
ENTITYEVENT("entity_event"),
PLAYEREVENT("event");

override fun toString(): String {
return type
}
}
override fun toString(): String {
return type
}
}

}
Loading

0 comments on commit 158abe5

Please sign in to comment.