delete protobuf stuff, and unused code

This commit is contained in:
Adam 2021-11-03 17:07:59 +01:00
parent 16d382db11
commit 7dd7baef34
132 changed files with 16 additions and 57708 deletions

View file

@ -1,12 +1,6 @@
import dev.adamko.gradle.pbandg.task.ProtobufCompileTask
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
plugins {
id("dev.adamko.factoriowebmap.archetype.base")
kotlin("multiplatform")
id("dev.adamko.gradle.pbandg.pb-and-g")
}
val projectId: String by project.extra
@ -43,9 +37,6 @@ kotlin {
sourceSets {
val jsMain by getting {
dependencies {
implementation(npm("ts-proto", "1.83.3"))
}
}
val jsTest by getting {
@ -69,86 +60,3 @@ kotlin {
}
}
}
dependencies {
protobufLibrary("com.google.protobuf:protobuf-javalite:3.19.1")
}
val rootPackageJson by rootProject.tasks.getting(RootPackageJsonTask::class)
val nodePath: Directory by extra {
val file = rootPackageJson.rootPackageJson.parentFile.normalize()
logger.lifecycle("Kotlin/JS NODE_PATH: $file")
project.layout.dir(provider { file }).get()
}
val nodeModulesDir: Directory by extra {
val file = nodePath.dir(NpmProject.NODE_MODULES)
logger.lifecycle("Kotlin/JS NODE_MODULES: $file")
file
}
afterEvaluate {
val protobufJava by tasks.creating(ProtobufCompileTask::class) {
description = "proto2java"
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
cliArgs.add("--java_out=lite:${project.mkdir("$temporaryDir/java").canonicalPath}")
}
val protobufKotlin by tasks.creating(ProtobufCompileTask::class) {
description = "proto2kotlin"
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
cliArgs.add("--kotlin_out=lite:${project.mkdir("$temporaryDir/kotlin").canonicalPath}")
}
val ktProto by configurations.creating {
isCanBeResolved = false
isCanBeConsumed = true
}
artifacts {
add(ktProto.name, protobufJava.outputDir) {
builtBy(protobufJava)
}
add(ktProto.name, protobufKotlin.outputDir) {
builtBy(protobufKotlin)
}
}
val protobufTypescript by tasks.creating(ProtobufCompileTask::class) {
description = "proto2typescript"
// linux:
// cliArgs.add("--plugin=${rootProject.buildDir}/js/packages/factorio-web-map-factorio-events-data-model/node_modules/.bin/protoc-gen-ts_proto.cmd")
// windows:
cliArgs.add("--plugin=protoc-gen-ts_proto=${rootProject.buildDir}/js/packages/factorio-web-map-factorio-events-data-model/node_modules/.bin/protoc-gen-ts_proto.cmd")
cliArgs.add("--ts_proto_out=${project.mkdir("$temporaryDir/typescript").canonicalPath}")
cliArgs.addAll(
"--ts_proto_opt=useOptionals=true",
"--ts_proto_opt=outputServices=false",
"--ts_proto_opt=outputJsonMethods=false",
// "--ts_proto_opt=outputEncodeMethods=false",
"--ts_proto_opt=forceLong=string",
"--ts_proto_opt=forceLong=number",
"--ts_proto_opt=esModuleInterop=true",
"--ts_proto_opt=exportCommonSymbols=false",
// "--proto_path=${rootProject.rootDir}",
)
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
}
val tsProto by configurations.creating {
isCanBeResolved = false
isCanBeConsumed = true
}
artifacts {
add(tsProto.name, protobufTypescript.outputDir) {
builtBy(protobufTypescript)
}
}
}

View file

@ -1,94 +0,0 @@
syntax = "proto3";
//option optimize_for = LITE_RUNTIME;
option java_multiple_files = true;
package dev.adamko.factorioevents;
//import "google/protobuf/any.proto";
//import "google/protobuf/timestamp.proto";
message FactorioServerLogRecord {
string mod_version = 1;
uint32 tick = 2;
string event_type = 3;
FactorioLuaObject data = 4;
}
message FactorioLuaObject {
string object_name = 1;
oneof data {
LuaControl lua_control = 2;
}
}
// https://lua-api.factorio.com/next/LuaControl.html
message LuaControl {
bool is_player = 2;
uint32 surface_index = 3;
Position position = 4;
uint32 force_index = 5;
oneof subtype {
LuaPlayer player = 10;
LuaEntity entity = 11;
}
}
// https://lua-api.factorio.com/next/LuaPlayer.html
message LuaPlayer {
uint32 index = 1; // unique ID
string name = 2;
repeated int32 data = 4 [packed = true];
Colour colour = 8;
bool is_connected = 10;
bool is_admin = 11;
uint32 afk_time_ticks = 100;
uint32 online_time_ticks = 101;
uint32 last_online_ticks = 102;
}
// https://lua-api.factorio.com/next/LuaEntity.html
message LuaEntity {
optional uint32 unit_number = 1; // (optional) unique ID
string name = 2;
string type = 3;
string status = 4; // https://lua-api.factorio.com/next/defines.html#defines.entity_status
bool is_active = 8;
bool is_moving = 9;
optional uint32 player_index = 50; // (optional) The player connected to this character or nil if none.
optional uint32 last_user_index = 51; // (optional) The last player that changed any setting on this entity.
Colour colour = 100; // (optional)
}
message LuaSurface {
uint32 index = 1; // unique ID
string name = 2;
float daytime = 3;
}
message LuaForce {
uint32 index = 1; // unique ID
string force_name = 2;
repeated uint32 player_ids = 100 [packed = true];
}
message Position {
int32 x = 1;
int32 y = 2;
}
message Colour {
float red = 1;
float green = 2;
float blue = 3;
float alpha = 4;
}

View file

@ -1,63 +0,0 @@
package dev.adamko.factorioevents.model
import kotlin.js.JsExport
import kotlin.jvm.JvmInline
//expect sealed interface JsonPrimitive {
// value class JsonString(val string: String) : JsonPrimitive
// value class JsonNumber(val number: Number) : JsonPrimitive
// value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
//}
sealed interface JsonPrimitive {
@JvmInline
value class JsonString(val string: String) : JsonPrimitive
@JvmInline
value class JsonNumber(val number: Number) : JsonPrimitive
@JvmInline
value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
}
class JsonArray<T : JsonPrimitive?>(
private val list: MutableList<T> = mutableListOf()
) : MutableList<T> by list
sealed interface JsonTableValue {
@JvmInline
value class JsonPrimitiveTV(val primitive: JsonPrimitive) : JsonTableValue
@JvmInline
value class JsonArrayTV<T : JsonPrimitive?>(val array: JsonArray<T>) : JsonTableValue
@JvmInline
value class JsonTableTV<T : JsonTable?>(val array: JsonTable) : JsonTableValue
}
//expect class JsonNumber() : JsonPrimitiveType
//expect class JsonArray<T : JsonPrimitive?>
//expect open class JsonTable<K : JsonPrimitive.JsonString, V : JsonTableValue?>
open class JsonTable(
protected val map: MutableMap<JsonPrimitive.JsonString, JsonTableValue?> = mutableMapOf()
) : MutableMap<JsonPrimitive.JsonString, JsonTableValue?> by map {
inline fun <reified T> get2(key: String): T? {
val jKey = JsonPrimitive.JsonString(key)
return when {
T::class is Number -> ((get(jKey) as? JsonTableValue.JsonPrimitiveTV)?.primitive as? JsonPrimitive.JsonNumber)?.number as? T
else -> return get(jKey) as? T
}
}
}
//@JsExport
class FactorioEvent : JsonTable() {
val tick: UInt?
get() = get2("tick")
// set(value) = map.put("tick", value)
}

View file

@ -1,31 +0,0 @@
package dev.adamko.factorioevents.model
//actual sealed interface JsonPrimitive {
// actual value class JsonString(val string: String) : JsonPrimitive
// actual value class JsonNumber(val number: Number) : JsonPrimitive
// actual value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
//}
//actual class JsonArray<T : JsonPrimitive?>(
// private val list: MutableList<T> = mutableListOf()
//) : MutableList<T> by list
//actual sealed interface JsonTableValue {
// actual value class JsonPrimitiveTV(val primitive: JsonPrimitive) : JsonTableValue
// actual value class JsonArrayTV<T : JsonPrimitive?>(val array: JsonArray<T>) : JsonTableValue
//}
//actual open class JsonTable<K : JsonPrimitive.JsonString, V: JsonTableValue?>(
// private val map: MutableMap<K, V> = mutableMapOf()
//) : MutableMap<K, V> by map
fun printMap() {
val f = JsonPrimitive.JsonString("test")
println(f.string)
println(f)
}

View file

@ -1,55 +0,0 @@
interface Identifiable<T> {
val id: T
}
interface IndexedModel {
val index: UInt
}
interface NamedModel {
val name: String
}
data class SurfaceModel(
override val name: String,
override val index: UInt,
val daytime: Float,
val darkness: Float,
val wind_speed: Double,
) : IndexedModel, NamedModel
/** Player/Entity shared props */
interface ControlModel {
val driving: Boolean
val forces: List<ForceModel>
}
//data class PlayerModel(
// val index: UInt,
// val characters: List<EntityModel>
//) : Identifiable<UInt> {
// override val id: UInt = index
//}
//data class EntityModel(
// val unit_number: Int,
// override val name: String,
// val type: String,
// val active: Boolean,
// val minable: Boolean,
// val health: Boolean,
// val speed: Float, override val driving: Boolean,
//) : ControlModel, NamedModel
data class ForceModel(
val index: UInt,
override val name: String,
val research_progress: Double,
) : Identifiable<UInt>, NamedModel {
override val id: UInt = index
}