mucking around trying to get protoc working. I've finally got a task that downloads the exe...
This commit is contained in:
parent
ebba0bb767
commit
106d7a7923
12 changed files with 982 additions and 53 deletions
|
|
@ -2,3 +2,4 @@ kotlin.js.compiler=ir
|
|||
kotlin.mpp.stability.nowarn=true
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
org.gradle.dependency.verification.console=verbose
|
||||
|
|
|
|||
|
|
@ -1,52 +1,237 @@
|
|||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ExternalDependency
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.domainObjectContainer
|
||||
import org.gradle.kotlin.dsl.create
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||
|
||||
plugins {
|
||||
// id("dev.adamko.factoriowebmap.archetype.base")
|
||||
// kotlin("multiplatform")
|
||||
|
||||
id("dev.adamko.factoriowebmap.archetype.kotlin-jvm")
|
||||
|
||||
id("com.google.protobuf") version "0.8.17"
|
||||
|
||||
|
||||
id("dev.adamko.factoriowebmap.archetype.base")
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
val projectId: String by project.extra
|
||||
val buildDir: Directory = layout.buildDirectory.dir(projectId).get()
|
||||
val nodeModulesDir: Directory by project.extra
|
||||
|
||||
//kotlin {
|
||||
dependencies {
|
||||
}
|
||||
|
||||
|
||||
class ProtocPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
|
||||
val protocConfig =
|
||||
project.extensions.create("protocPluginConfig", ProtocPluginConfig::class, project)
|
||||
|
||||
// val protocDep: Configuration = project.configurations.create("protoc") {
|
||||
// isVisible = false
|
||||
// isCanBeConsumed = false
|
||||
// isCanBeResolved = true
|
||||
// isTransitive = false
|
||||
//
|
||||
// js(IR) {
|
||||
// binaries.executable()
|
||||
//// browser {
|
||||
//// commonWebpackConfig {
|
||||
//// cssSupport.enabled = true
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
// nodejs()
|
||||
// useCommonJs()
|
||||
//
|
||||
// compilations["main"].apply {
|
||||
// packageJson {
|
||||
// customField(
|
||||
// "scripts",
|
||||
// mapOf(
|
||||
// "build" to "tstl",
|
||||
// "dev" to "tstl --watch",
|
||||
// )
|
||||
// )
|
||||
// defaultDependencies {
|
||||
// add(protocConfig.dependencyProvider())
|
||||
// }
|
||||
// }
|
||||
|
||||
project.tasks.register<ProtocPrepareTask>("protocPrepare") {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// }
|
||||
// val prepareTask = project.tasks.register<Sync>("protocPrepare") {
|
||||
// group = "protoc"
|
||||
//
|
||||
// jvm {
|
||||
// compilations.all {
|
||||
// kotlinOptions.jvmTarget = "11"
|
||||
// val outputDir = project.rootProject.layout.projectDirectory.dir(".gradle/protoc")
|
||||
//
|
||||
// outputs.dir(outputDir)
|
||||
//
|
||||
//// doLast {
|
||||
// val protoc: File = protocDep.resolve().single()
|
||||
// logger.lifecycle("protoc file $protoc")
|
||||
//
|
||||
// from(protoc)
|
||||
// into(outputDir)
|
||||
//// }
|
||||
// }
|
||||
// testRuns["test"].executionTask.configure {
|
||||
// useJUnitPlatform()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
// project.tasks.build { dependsOn(prepareTask) }
|
||||
//
|
||||
// val generateTask = project.tasks.create<Exec>("protocGenerate") {
|
||||
// dependsOn(prepareTask)
|
||||
// }
|
||||
|
||||
// val protocDeps = project.configurations.create("pbAndG") {
|
||||
// this.let { config ->
|
||||
//
|
||||
// config.isVisible = false
|
||||
// config.isCanBeConsumed = false
|
||||
// config.isCanBeResolved = true
|
||||
// config.description = "protoc dependencies"
|
||||
//
|
||||
// config.defaultDependencies {
|
||||
// add(protocConfig.dependencyProvider())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// val generatorsContainer =
|
||||
// project.objects.domainObjectContainer(ProtocGenerationTask::class)
|
||||
// protocConfig.extensions.add("protocGenerate", generatorsContainer)
|
||||
//
|
||||
//
|
||||
// project.extensions.add("testingExtensionThingy", project.provider {
|
||||
// DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
// })
|
||||
//
|
||||
// project.tasks.withType<ProtocGenerationTask> {
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ProtocPluginConfig(private val project: Project) : java.io.Serializable {
|
||||
|
||||
val protocVersion: Property<String> =
|
||||
project.objects.property(String::class).convention("3.9.2")
|
||||
|
||||
val protocGroup: Property<String> =
|
||||
project.objects.property(String::class).convention("com.google.protobuf")
|
||||
|
||||
val protocArtifactName: Property<String> =
|
||||
project.objects.property(String::class).convention("protoc")
|
||||
|
||||
val protocArtifactExtension: Property<String> =
|
||||
project.objects.property(String::class).convention("exe")
|
||||
|
||||
/**
|
||||
* Should return one of
|
||||
*
|
||||
* * `linux`
|
||||
* * `osx`
|
||||
* * `windows`
|
||||
*/
|
||||
var osFamilyNameProvider: () -> String = {
|
||||
DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
}
|
||||
|
||||
/**
|
||||
* Should return one of
|
||||
*
|
||||
* * `aarch_64`
|
||||
* * `ppcle_64`
|
||||
* * `x86_32`
|
||||
* * `x86_64`
|
||||
*/
|
||||
var architectureProvider: () -> String = {
|
||||
DefaultNativePlatform.getCurrentArchitecture()
|
||||
.name
|
||||
.replace("-", "_")
|
||||
}
|
||||
|
||||
/**
|
||||
* Default: concatenate [osFamilyNameProvider] and [architectureProvider]
|
||||
*
|
||||
* Should return one of:
|
||||
*
|
||||
* * `linux-aarch_64`
|
||||
* * `linux-ppcle_64`
|
||||
* * `linux-x86_64`
|
||||
* * `osx-x86_32`
|
||||
* * `osx-x86_64`
|
||||
* * `windows-x86_32`
|
||||
*/
|
||||
var classifierProvider: () -> String = {
|
||||
"${osFamilyNameProvider()}-${architectureProvider()}"
|
||||
}
|
||||
|
||||
var dependencyProvider: () -> ExternalModuleDependency = {
|
||||
project.dependencies.create(
|
||||
group = protocGroup.get(),
|
||||
name = protocArtifactName.get(),
|
||||
version = protocVersion.get(),
|
||||
classifier = classifierProvider(),
|
||||
ext = protocArtifactExtension.get(),
|
||||
)
|
||||
}
|
||||
|
||||
// val generators = project.objects.domainObjectContainer(ProtocGenerationConfig::class)
|
||||
}
|
||||
|
||||
abstract class ProtocGenerationConfig
|
||||
|
||||
abstract class ProtocPrepareTask : DefaultTask() {
|
||||
|
||||
@get:OutputDirectory
|
||||
val outputDirectory: DirectoryProperty = project.objects.directoryProperty()
|
||||
.convention(project.rootProject.layout.projectDirectory.dir(".gradle/protoc"))
|
||||
|
||||
@get:OutputFile
|
||||
val protocOutput: RegularFileProperty = project.objects.fileProperty()
|
||||
.convention { outputDirectory.asFileTree.singleFile }
|
||||
|
||||
@Internal
|
||||
val protocPluginConfig: Provider<ProtocPluginConfig> = project.provider {
|
||||
project.extensions.getByType<ProtocPluginConfig>()
|
||||
}
|
||||
|
||||
@Internal
|
||||
val protocDependency: Provider<ExternalModuleDependency> = protocPluginConfig.map {
|
||||
it.dependencyProvider()
|
||||
}
|
||||
|
||||
init {
|
||||
super.setGroup("protoc")
|
||||
}
|
||||
|
||||
|
||||
@TaskAction
|
||||
fun prepare() {
|
||||
|
||||
val protocDep: Configuration = project.configurations.create("protoc") {
|
||||
isVisible = false
|
||||
isCanBeConsumed = false
|
||||
isCanBeResolved = true
|
||||
isTransitive = false
|
||||
|
||||
defaultDependencies {
|
||||
add(protocDependency.get())
|
||||
}
|
||||
}
|
||||
|
||||
val resolvedProtocDep = protocDep.resolve()
|
||||
|
||||
require(resolvedProtocDep.singleOrNull() != null) {
|
||||
"Expected to download a single protoc.exe, but got ${resolvedProtocDep.size}: ${resolvedProtocDep.joinToString()}"
|
||||
}
|
||||
|
||||
project.sync {
|
||||
from(resolvedProtocDep)
|
||||
into(outputDirectory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ProtocGenerationTask : DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun generate() {
|
||||
logger.lifecycle("generating protoc...")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
apply<ProtocPlugin>()
|
||||
|
||||
configure<ProtocPluginConfig> {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
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 {
|
||||
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;
|
||||
|
||||
uint32 player_index = 50; // (optional) The player connected to this character or nil if none.
|
||||
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;
|
||||
}
|
||||
95
modules/factorio-events-data-model2/build.gradle.kts
Normal file
95
modules/factorio-events-data-model2/build.gradle.kts
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
//import com.google.protobuf.gradle.builtins
|
||||
//import com.google.protobuf.gradle.generateProtoTasks
|
||||
//import com.google.protobuf.gradle.ofSourceSet
|
||||
//import com.google.protobuf.gradle.plugins
|
||||
//import com.google.protobuf.gradle.protobuf
|
||||
//import com.google.protobuf.gradle.protoc
|
||||
|
||||
|
||||
plugins {
|
||||
id("dev.adamko.factoriowebmap.archetype.base")
|
||||
// id("dev-adamko.pb-and-g")
|
||||
// kotlin("multiplatform")
|
||||
|
||||
// id("dev.adamko.factoriowebmap.archetype.kotlin-jvm")
|
||||
// java
|
||||
// kotlin("js")
|
||||
|
||||
// id("com.google.protobuf") version "0.8.17"
|
||||
|
||||
}
|
||||
|
||||
val projectId: String by project.extra
|
||||
val buildDir: Directory = layout.buildDirectory.dir(projectId).get()
|
||||
//val nodeModulesDir: Directory by project.extra
|
||||
|
||||
val protobufVersion = "3.19.0"
|
||||
|
||||
//kotlin {
|
||||
//// js {
|
||||
//// // To build distributions for and run tests on browser or Node.js use one or both of:
|
||||
////// browser()
|
||||
//// nodejs()
|
||||
//// }
|
||||
//}
|
||||
|
||||
|
||||
dependencies {
|
||||
// implementation(platform("com.google.protobuf:protobuf-bom:$protobufVersion"))
|
||||
//
|
||||
// implementation("com.google.protobuf:protobuf-java:$protobufVersion")
|
||||
// implementation("com.google.protobuf:protobuf-javalite:$protobufVersion")
|
||||
// implementation("com.google.protobuf:protobuf-kotlin-lite:$protobufVersion")
|
||||
// implementation("com.google.protobuf:protobuf-kotlin:$protobufVersion")
|
||||
// implementation("com.google.protobuf:protoc:$protobufVersion")
|
||||
//
|
||||
// implementation(platform("io.grpc:grpc-bom:1.41.0"))
|
||||
// implementation("io.grpc:grpc-stub:1.41.0")
|
||||
// implementation("io.grpc:grpc-protobuf:1.41.0")
|
||||
//
|
||||
// implementation("io.grpc:grpc-kotlin-stub:1.2.0")
|
||||
// implementation("io.grpc:protoc-gen-grpc-kotlin:1.2.0")
|
||||
//
|
||||
// implementation("javax.annotation:javax.annotation-api:1.3.2")
|
||||
//
|
||||
|
||||
// implementation(npm("protoc-gen-ts", "0.15.0"))
|
||||
|
||||
}
|
||||
|
||||
|
||||
//protobuf {
|
||||
// protoc {
|
||||
// // The artifact spec for the Protobuf Compiler
|
||||
// artifact = "com.google.protobuf:protoc:3.9.2"
|
||||
// }
|
||||
//
|
||||
// plugins {
|
||||
//
|
||||
// this.id("ts") {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// this.plugins {
|
||||
//// this.named("ts") {
|
||||
////
|
||||
//// }
|
||||
// }
|
||||
//
|
||||
// generateProtoTasks {
|
||||
// ofSourceSet("main").forEach { task ->
|
||||
// task.builtins {
|
||||
// getByName("java") {
|
||||
// option("lite")
|
||||
// }
|
||||
//// getByName("kotlin") {
|
||||
//// option("lite")
|
||||
//// }
|
||||
//// getByName("ts") {
|
||||
//// option("lite")
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
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)
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
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)
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
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 {
|
||||
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;
|
||||
|
||||
uint32 player_index = 50; // (optional) The player connected to this character or nil if none.
|
||||
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;
|
||||
}
|
||||
159
modules/protoc-gradle-plugin/build.gradle.kts
Normal file
159
modules/protoc-gradle-plugin/build.gradle.kts
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
import org.gradle.nativeplatform.platform.internal.ArchitectureInternal
|
||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.5.31"
|
||||
`kotlin-dsl`
|
||||
`java-gradle-plugin`
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("Protobuf & Gradle") {
|
||||
id = "dev-adamko.pb-and-g"
|
||||
implementationClass = "dev.adamko.gradle.pbandg.ProtocPluginKt"
|
||||
description =
|
||||
"Protobuf & Gradle. Wrapper for protoc to generate code from Proto Buffer files."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val protocConfiguration: Configuration by configurations.creating {
|
||||
// A configuration meant for consumers that need the implementation of this component
|
||||
isCanBeResolved = true
|
||||
isCanBeConsumed = false
|
||||
}
|
||||
|
||||
val protobufVersion = "3.19.0"
|
||||
val protocVersion = "3.9.2"
|
||||
|
||||
dependencies {
|
||||
implementation(platform("com.google.protobuf:protobuf-bom:$protobufVersion"))
|
||||
|
||||
implementation("com.google.protobuf:protobuf-java:$protobufVersion")
|
||||
implementation("com.google.protobuf:protobuf-javalite:$protobufVersion")
|
||||
implementation("com.google.protobuf:protobuf-kotlin-lite:$protobufVersion")
|
||||
implementation("com.google.protobuf:protobuf-kotlin:$protobufVersion")
|
||||
implementation("com.google.protobuf:protoc:$protobufVersion")
|
||||
|
||||
implementation(platform("io.grpc:grpc-bom:1.41.0"))
|
||||
implementation("io.grpc:grpc-stub:1.41.0")
|
||||
implementation("io.grpc:grpc-protobuf:1.41.0")
|
||||
|
||||
implementation("io.grpc:grpc-kotlin-stub:1.2.0")
|
||||
implementation("io.grpc:protoc-gen-grpc-kotlin:1.2.0")
|
||||
|
||||
implementation("javax.annotation:javax.annotation-api:1.3.2")
|
||||
//
|
||||
|
||||
// implementation(npm("protoc-gen-ts", "0.15.0"))
|
||||
|
||||
implementation(
|
||||
group = "com.google.protobuf",
|
||||
name = "protoc",
|
||||
version = "3.9.2",
|
||||
// configuration = "",
|
||||
classifier = "windows-x86_64",
|
||||
ext = "exe",
|
||||
)
|
||||
|
||||
protocConfiguration(
|
||||
group = "com.google.protobuf",
|
||||
name = "protoc",
|
||||
version = protocVersion,
|
||||
// configuration = "",
|
||||
classifier = "windows-x86_64",
|
||||
ext = "exe",
|
||||
)
|
||||
|
||||
// protocConfiguration("com.google.protobuf:protoc:3.9.2@exe")
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// https://github.com/protocolbuffers/protobuf/tree/master/protoc-artifacts
|
||||
// The name of a published protoc artifact is in the format:
|
||||
// protoc-<version>-<os>-<arch>.exe
|
||||
// e.g., protoc-3.6.1-linux-x86_64.exe
|
||||
// Note that artifacts for Linux/macOS also have the .exe suffix, but they are not windows binaries.
|
||||
val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
|
||||
val arch: ArchitectureInternal = DefaultNativePlatform.getCurrentArchitecture()
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
// ivy {
|
||||
// url = project.repositories.mavenCentral().url
|
||||
//
|
||||
// patternLayout {
|
||||
//
|
||||
// // com/google/protobuf/protoc/3.9.2/protoc-3.9.2-linux-aarch_64.exe
|
||||
// artifact("[organisation]/[module]/[revision]/[artifact]-[revision]-${os.name}-${arch.name}.[ext]")
|
||||
//
|
||||
//// artifact("3rd-party-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]")
|
||||
//// artifact("company-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]")
|
||||
//// ivy("ivy-files/[organisation]/[module]/[revision]/ivy.xml")
|
||||
//// artifact("[organisation]/[module]/[revision]/[artifact]-[revision].[ext]")
|
||||
// setM2compatible(true)
|
||||
// metadataSources {
|
||||
// artifact()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
tasks.register<Sync>("protocExecCopy") {
|
||||
group = project.name
|
||||
|
||||
// from(protocConfiguration.artifacts)
|
||||
|
||||
from(protocConfiguration.resolve())
|
||||
|
||||
into(project.layout.buildDirectory.dir("protocCopy"))
|
||||
}
|
||||
|
||||
//tasks.register("dlPc") {
|
||||
// group = project.name
|
||||
//
|
||||
// val downloadDir = this.temporaryDir
|
||||
//
|
||||
// outputs.dir(downloadDir)
|
||||
//
|
||||
// doLast {
|
||||
//
|
||||
//// downloadDir.mkdirs()
|
||||
//
|
||||
// val protocArtifactFileExt = "exe"
|
||||
//
|
||||
// val osFamilyName = DefaultNativePlatform.host().operatingSystem.toFamilyName()
|
||||
//
|
||||
// val arch: String =
|
||||
// DefaultNativePlatform.getCurrentArchitecture()
|
||||
// .name
|
||||
// .replace("-", "_")
|
||||
//
|
||||
// val artifact = "protoc-$protocVersion-${osFamilyName}-${arch}.$protocArtifactFileExt"
|
||||
//
|
||||
// val uri = uri(
|
||||
// ArtifactRepositoryContainer.MAVEN_CENTRAL_URL
|
||||
// + "com/google/protobuf/protoc/$protocVersion/$artifact"
|
||||
// )
|
||||
// // actual:
|
||||
// // https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-windows-x86_64.exe
|
||||
// // https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-windows-x86-64.exe
|
||||
//
|
||||
// ant.invokeMethod(
|
||||
// "get", mapOf(
|
||||
// "src" to uri,
|
||||
// "dest" to downloadDir.canonicalPath,
|
||||
// "verbose" to true,
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package dev.adamko.gradle.pbandg
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ExternalDependency
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.kotlin.dsl.domainObjectContainer
|
||||
import org.gradle.kotlin.dsl.create
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.kotlin.dsl.property
|
||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||
|
||||
|
||||
class ProtocPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
|
||||
val protocConfig =
|
||||
project.extensions.create("protocConfig", ProtocConfigExtension::class.java)
|
||||
|
||||
val protocDeps = project.configurations.create("pbAndG") {
|
||||
isVisible = false
|
||||
isCanBeConsumed = false
|
||||
isCanBeResolved = true
|
||||
description = "protoc dependencies"
|
||||
|
||||
defaultDependencies {
|
||||
// deps += project.dependencies.create("com.google.protobuf:protoc:3.19.0")
|
||||
add(protocConfig.dependencyProvider())
|
||||
}
|
||||
}
|
||||
|
||||
val generatorsContainer =
|
||||
project.objects.domainObjectContainer(ProtocGenerationTask::class.java)
|
||||
protocConfig.extensions.add("generate", generatorsContainer)
|
||||
|
||||
|
||||
project.extensions.add("asd", project.provider {
|
||||
DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
})
|
||||
|
||||
project.tasks.withType<ProtocGenerationTask> {
|
||||
// .getDataFiles()?.from(protocDeps)
|
||||
}
|
||||
|
||||
// project.getPlugins().withType(org.gradle.api.plugins.JavaPlugin::class) { javaPlugin ->
|
||||
// val sourceSets: SourceSetContainer =
|
||||
// project.getExtensions().getByType(SourceSetContainer::class.java)
|
||||
// val main: SourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
|
||||
// main.getJava().setSrcDirs(Arrays.asList("src"))
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract class ProtocConfigExtension(private val project: Project) : ExtensionAware {
|
||||
|
||||
val protocVersion: Property<String> =
|
||||
project.objects.property(String::class).convention("3.9.2")
|
||||
|
||||
val protocGroup: Property<String> =
|
||||
project.objects.property(String::class).convention("com.google.protobuf")
|
||||
|
||||
val protocArtifactName: Property<String> =
|
||||
project.objects.property(String::class).convention("protoc")
|
||||
|
||||
val protocArtifactExtension: Property<String> =
|
||||
project.objects.property(String::class).convention("exe")
|
||||
|
||||
var osFamilyNameProvider: () -> String = {
|
||||
DefaultNativePlatform.getCurrentOperatingSystem().toFamilyName()
|
||||
}
|
||||
|
||||
var architectureProviderMapper: (String) -> String = {
|
||||
it.replace("-", "_")
|
||||
}
|
||||
|
||||
var architectureProvider: () -> String = {
|
||||
DefaultNativePlatform.getCurrentArchitecture()
|
||||
.name
|
||||
.let(architectureProviderMapper)
|
||||
}
|
||||
|
||||
var classifierProvider: () -> String = {
|
||||
"${osFamilyNameProvider()}-${architectureProvider()}"
|
||||
}
|
||||
|
||||
var dependencyProvider: () -> ExternalDependency = {
|
||||
project.dependencies.create(
|
||||
group = protocGroup.get(),
|
||||
name = protocArtifactName.get(),
|
||||
version = protocVersion.get(),
|
||||
classifier = classifierProvider(),
|
||||
ext = protocArtifactExtension.get(),
|
||||
)
|
||||
}
|
||||
|
||||
val generators = project.objects.domainObjectContainer(ProtocGenerationConfig::class)
|
||||
|
||||
|
||||
}
|
||||
|
||||
abstract class ProtocGenerationConfig
|
||||
|
||||
abstract class ProtocGenerationTask : DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun generate() {
|
||||
logger.lifecycle("generating protoc...")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//class ProtocDownloadExe : DefaultTask() {
|
||||
//
|
||||
////@Input
|
||||
//val protocVersion = "3.9.2"
|
||||
//val protocArtifactFileExt = "exe"
|
||||
//
|
||||
//
|
||||
// @TaskAction
|
||||
// fun download() {
|
||||
//
|
||||
// val baseUri = project.repositories.mavenCentral().url
|
||||
//
|
||||
// val os: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
|
||||
// val arch: ArchitectureInternal = DefaultNativePlatform.getCurrentArchitecture()
|
||||
//
|
||||
// val artifact = "protoc-$protocVersion-${os.name}-${arch.name}.$protocArtifactFileExt"
|
||||
//
|
||||
// ant.invokeMethod(
|
||||
// "get", mapOf(
|
||||
// "src" to baseUri.resolve("/com/google/protobuf/protoc/3.9.2/protoc-3.9.2-linux-aarch_64.exe"),
|
||||
// "dest" to project.layout.buildDirectory.dir("protoc-artifact"),
|
||||
// "verbose" to true,
|
||||
// )
|
||||
// )
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
|||
plugins {
|
||||
id("dev.adamko.factoriowebmap.archetype.base")
|
||||
// kotlin("jvm")
|
||||
id("io.kvision") version "5.4.1"
|
||||
id("io.kvision") version "5.4.1"
|
||||
kotlin("js")
|
||||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
|
@ -24,13 +24,13 @@ kotlin {
|
|||
outputFileName = "main.bundle.js"
|
||||
sourceMaps = false
|
||||
devServer = KotlinWebpackConfig.DevServer(
|
||||
open = false,
|
||||
port = 3000,
|
||||
proxy = mutableMapOf(
|
||||
"/kv/*" to "http://localhost:8080",
|
||||
"/kvws/*" to mapOf("target" to "ws://localhost:8080", "ws" to true)
|
||||
),
|
||||
static = mutableListOf("$buildDir/processedResources/js/main")
|
||||
open = false,
|
||||
port = 3000,
|
||||
proxy = mutableMapOf(
|
||||
"/kv/*" to "http://localhost:8080",
|
||||
"/kvws/*" to mapOf("target" to "ws://localhost:8080", "ws" to true)
|
||||
),
|
||||
static = mutableListOf("$buildDir/processedResources/js/main")
|
||||
)
|
||||
}
|
||||
webpackTask {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
rootProject.name = "factorio-web-map"
|
||||
|
||||
|
||||
includeBuild("modules/protoc-gradle-plugin")
|
||||
|
||||
include(
|
||||
":modules:mod",
|
||||
":modules:mod",
|
||||
// ":modules:mod2",
|
||||
":modules:server",
|
||||
":modules:kt-rcon",
|
||||
":modules:factorio-events-data-model",
|
||||
":modules:factorio-events-processor",
|
||||
":modules:factorio-events-kafka-pipe",
|
||||
":modules:server",
|
||||
":modules:kt-rcon",
|
||||
":modules:factorio-events-data-model",
|
||||
// ":modules:factorio-events-data-model2",
|
||||
":modules:factorio-events-processor",
|
||||
":modules:factorio-events-kafka-pipe",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue