added kvision web-map, cleaning up a few gradle things (tokens)

This commit is contained in:
Adam 2021-12-06 22:15:26 +01:00
parent 29d190b8f4
commit 6d60428ab9
31 changed files with 323 additions and 87 deletions

26
LICENSE
View file

@ -1,24 +1,6 @@
COPYRIGHT (C) LIMITED USE SOFTWARE LICENSE AGREEMENT
Copyright (C) 2021 adam@adamko.dev
All rights are reserved by the copyright holder.
This file is part of the Kafkatorio project.
Permission is granted to use this software as a Factorio mod.
Permission is granted distribute this software under the
condition that the distribution is publicly accessible,
and no payment or registration is required. Additionally,
all distributions must include the full source code of the
software, without restrictions or limitations.
Permission is granted to make modifications to this software
under the condition that any claim of ownership is
relinquished, and any modification becomes the property of
the original copyright holder of this software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information contact fredthedeadhead@gmail.com
The Kafkatorio project cannot be copied and/or distributed
without the express permission of the author - adam@adamko.dev

View file

@ -6,13 +6,20 @@
1. converts data to images
2. hosts a web map
## License
While this project is under development, [no license](https://choosealicense.com/no-permission/)
is provided.
## todo
* add settings
* is active - whether files are exported or not
* delete files - clean up all files
* tick-rate - how often reports are generated (
* requires on some sort of in-mod cache of map<entity-id, event>)
* tick-rate - how often reports are generated
* requires on some sort of in-mod cache of map<entity-id, event>
* also divide by game-speed? to keep ratio the same
### to investigate:
@ -48,4 +55,7 @@ https://github.com/dvidelabs/flatcc
#### CBOR
https://www.zash.se/lua-cbor.html
https://code.zash.se/lua-cbor/archive/68b3a36d0816.tar.gz
https://code.zash.se/lua-cbor/archive/68b3a36d0816.tar.gz

View file

@ -5,13 +5,32 @@ plugins {
`build-dashboard`
}
group = "dev.adamko"
version = "0.1.1"
group = "dev.adamko.kafkatorio"
version = "0.1.2"
val licenseFile: RegularFile by extra(layout.projectDirectory.file("LICENSE"))
val projectTokens: MutableMap<String, String> by extra(
mutableMapOf(
"project.version" to "$version",
"rootProject.name" to rootProject.name,
"date.year" to "${java.time.LocalDate.now().year}",
"author.email" to "adam@adamko.dev",
)
)
idea {
module {
isDownloadSources = true
isDownloadJavadoc = true
}
}
tasks.wrapper {
gradleVersion = "7.3"
gradleVersion = "7.3.1"
distributionType = Wrapper.DistributionType.ALL
}
tasks.assemble { dependsOn(tasks.wrapper) }
val startInfra by tasks.registering {
group = project.name

View file

@ -60,4 +60,4 @@ idea {
}
}
tasks.assemble { dependsOn(tasks.htmlDependencyReport) }
//tasks.assemble { dependsOn(tasks.htmlDependencyReport) }

View file

@ -8,14 +8,6 @@ plugins {
group = "${rootProject.group}.${project.name}"
version = rootProject.version
val licenseFile: RegularFile by extra(rootProject.layout.projectDirectory.file("LICENSE"))
val tokens: MutableMap<String, String> by extra(
mutableMapOf(
"project.version" to "$version",
)
)
idea {
module {
isDownloadSources = true

View file

@ -32,7 +32,7 @@ fun Configuration.factorioModAttributes(objects: ObjectFactory): Configuration =
attribute(BUNDLING_ATTRIBUTE, objects.named(Bundling.EMBEDDED))
}
fun Configuration.typescriptAttributes(objects: ObjectFactory) =
fun Configuration.typescriptAttributes(objects: ObjectFactory): Configuration =
attributes {
attribute(USAGE_ATTRIBUTE, objects.named("typescript"))
attribute(CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))

View file

@ -1,16 +1,8 @@
package dev.adamko.kafkatorio.lang
import org.gradle.kotlin.dsl.kotlin
import com.github.gradle.node.npm.task.NpmTask
import com.github.gradle.node.task.NodeTask
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.targets.js.dukat.DtsResolver
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
plugins {
@ -19,6 +11,8 @@ plugins {
id("dev.adamko.kafkatorio.lang.node")
}
// not in use at the moment
kotlin {
js(IR) {
binaries.executable()
@ -31,9 +25,9 @@ kotlin {
dependencies {
val kotlinWrappersVersion = "0.0.1-pre.270-kotlin-1.6.0"
implementation(
project.dependencies.enforcedPlatform(
"org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${kotlinWrappersVersion}"
)
project.dependencies.enforcedPlatform(
"org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${kotlinWrappersVersion}"
)
)
}

View file

@ -28,16 +28,16 @@ val updatePackageJson by tasks.registering(UpdatePackageJson::class) {
group = NodePlugin.NODE_GROUP
description = "Read the package.json file and update the version and name, based on the project."
propertiesToCheck["version"] = "${project.version}"
propertiesToCheck.put("version", "${project.version}")
// check to see if the properties are already up-to-date
onlyIf(!areJsonPropertiesUpToDate(packageJsonFile) { propertiesToCheck })
onlyIf(!areJsonPropertiesUpToDate(packageJsonFile) { propertiesToCheck.get() })
doLast {
val packageJsonContent = packageJsonFile.get().asFile.readText()
val packageJson = jsonMapper.parseToJsonElement(packageJsonContent).jsonObject
val newJsonProps = propertiesToCheck.mapValues { (_, newVal) -> JsonPrimitive(newVal) }
val newJsonProps = propertiesToCheck.get().mapValues { (_, newVal) -> JsonPrimitive(newVal) }
val packageJsonUpdate = JsonObject(packageJson + newJsonProps)
val packageJsonContentUpdated =

View file

@ -2,12 +2,20 @@ package dev.adamko.kafkatorio.task
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
abstract class UpdatePackageJson : DefaultTask() {
@get:Input
val propertiesToCheck: MutableMap<String, String> = mutableMapOf()
abstract val propertiesToCheck: MapProperty<String, String>
@get:OutputFile
abstract val packageJsonFile: RegularFileProperty
init {
super.doFirst {
propertiesToCheck.disallowChanges()
packageJsonFile.disallowChanges()
}
}
}

View file

@ -15,6 +15,7 @@ log4j2 = "2.14.1"
qosLogback = "1.2.5"
kafka = "3.0.0"
kotlinx-serialization = "1.3.1"
kvision = "5.6.1"
## test ##
junit = "5.8.1"

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View file

@ -5,6 +5,7 @@ import dev.adamko.kafkatorio.gradle.factorioModAttributes
import dev.adamko.kafkatorio.gradle.typescriptAttributes
import groovy.json.JsonOutput
import org.apache.tools.ant.filters.ReplaceTokens
import org.jetbrains.kotlin.gradle.targets.js.npm.SemVer
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
plugins {
@ -23,16 +24,18 @@ description =
val modName: String by extra("${rootProject.name}-events")
val distributionZipName: String by extra("${modName}_${project.version}.zip")
// version of Factorio that the mod is compatible with (must only be "major.minor" - patch causes error)
val modFactorioCompatibility = SemVer.from(libs.versions.factorio.get()).run { "$major.$minor" }
val tokens: MutableMap<String, String> by project.extra
tokens += mapOf(
val licenseFile: RegularFile by rootProject.extra
val projectTokens: MutableMap<String, String> by rootProject.extra
projectTokens += mapOf(
"mod.name" to modName,
"mod.title" to "Kafkatorio Events",
"mod.description" to (project.description ?: ""),
"factorio.version" to libs.versions.factorio.get().substringBeforeLast("."),
"factorio.version" to modFactorioCompatibility,
)
val licenseFile: RegularFile by project.extra
val tsSrcDir: Directory = layout.projectDirectory.dir("src/main/typescript")
node {
@ -52,7 +55,7 @@ val typescriptToLua by tasks.registering(NpmTask::class) {
description = "Convert Typescript To Lua"
group = project.name
dependsOn(tasks.npmInstall, fetchEventsSchema)
dependsOn(tasks.npmInstall, installEventsSchema)
execOverrides { standardOutput = System.out }
@ -84,7 +87,7 @@ val typescriptToLua by tasks.registering(NpmTask::class) {
}
val fetchEventsSchema by tasks.registering(Sync::class) {
val installEventsSchema by tasks.registering(Sync::class) {
description = "Fetch the latest shared data-model"
group = project.name
@ -124,10 +127,10 @@ distributions {
}
from(licenseFile)
from(typescriptToLua.map { it.outputs })
filter<ReplaceTokens>("tokens" to tokens)
filter<ReplaceTokens>("tokens" to projectTokens)
includeEmptyDirs = false
exclude {
// exclude empty lines
// exclude empty files
it.file.run {
isFile && useLines { lines -> lines.all { line -> line.isBlank() } }
}
@ -196,7 +199,6 @@ val downloadFactorioApiDocs by tasks.registering {
}
}
val factorioModProvider by configurations.registering {
asProvider()
factorioModAttributes(objects)
@ -204,13 +206,11 @@ val factorioModProvider by configurations.registering {
}
tasks.updatePackageJson {
propertiesToCheck["name"] = "${rootProject.name}-${project.name}"
propertiesToCheck.put("name", "${rootProject.name}-${project.name}")
packageJsonFile.set(layout.projectDirectory.file("src/main/typescript/package.json"))
}
tasks.assemble { dependsOn(fetchEventsSchema, tasks.updatePackageJson) }
//tasks.build { dependsOn(packageMod) }
tasks.assemble { dependsOn(installEventsSchema, tasks.updatePackageJson) }
//
//idea {

View file

@ -3,7 +3,7 @@
"version": "@project.version@",
"title": "@mod.title@",
"description": "@mod.description@",
"author": "fredthedeadhead",
"author": "@author.email@",
"factorio_version": "@factorio.version@",
"dependencies": []
}

View file

@ -1,6 +1,6 @@
{
"name": "kafkatorio-events-mod",
"version": "0.1.0",
"version": "0.1.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View file

@ -1,6 +1,6 @@
{
"name": "kafkatorio-events-mod",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"scripts": {
"build": "tstl",
@ -9,8 +9,7 @@
"engines": {
"node": ">=10.13.0"
},
"devDependencies": {
},
"devDependencies": {},
"dependencies": {
"lua-types": "^2.11.0",
"@types/node": "^12.0.8",
@ -21,10 +20,8 @@
"//": {
"typed-factorio": "0.10.0"
},
"peerDependencies": {
},
"optionalDependencies": {
},
"bundledDependencies": [
]
"license": "UNLICENSED",
"peerDependencies": {},
"optionalDependencies": {},
"bundledDependencies": []
}

View file

@ -1,6 +1,4 @@
// Generated code - do edit this file manually
// Generated by TypeScriptGenerator - do edit this file manually
interface FactorioObjectData {
object_name: string;
}

View file

@ -53,11 +53,9 @@ fun main(args: Array<String>) {
@Language("TypeScript")
val header = """
// Generated code - do edit this file manually
""".trimIndent()
|// Generated by TypeScriptGenerator - do edit this file manually
|
""".trimMargin()
object PropertyNameTransformer : ClassTransformer {
override fun transformPropertyName(

View file

@ -0,0 +1,39 @@
{
"js": {
"parsers": [
{
"expression": "tr",
"arguments": {
"text": 0
}
},
{
"expression": "ntr",
"arguments": {
"text": 0,
"textPlural": 1
}
},
{
"expression": "gettext",
"arguments": {
"text": 0
}
},
{
"expression": "ngettext",
"arguments": {
"text": 0,
"textPlural": 1
}
}
],
"glob": {
"pattern": "src/**/*.kt"
}
},
"headers": {
"Language": ""
},
"output": "src/main/resources/i18n/messages.pot"
}

8
modules/web-map/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
.*/
build/
out/
/refresh.sh
*.imp
*.ipr
*.iws
*.idea

View file

@ -0,0 +1,72 @@
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
plugins {
id("dev.adamko.kafkatorio.base")
kotlin("plugin.serialization")
kotlin("js") // version kotlinVersion
id("io.kvision") version "5.6.1"
}
kotlin {
js(IR) {
browser {
runTask {
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")
)
}
webpackTask {
outputFileName = "main.bundle.js"
}
testTask {
useKarma {
useChromeHeadless()
}
}
}
binaries.executable()
}
sourceSets {
val kvisionVersion: String = libs.versions.kvision.get()
main {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-nodejs:0.0.7")
implementation("io.kvision:kvision:$kvisionVersion")
implementation("io.kvision:kvision-bootstrap:$kvisionVersion")
implementation("io.kvision:kvision-bootstrap-css:$kvisionVersion")
implementation("io.kvision:kvision-bootstrap-icons:$kvisionVersion")
implementation("io.kvision:kvision-fontawesome:$kvisionVersion")
implementation("io.kvision:kvision-state:$kvisionVersion")
implementation("io.kvision:kvision-chart:$kvisionVersion")
val kotlinWrappersVersion = "0.0.1-pre.270-kotlin-1.6.0"
implementation(
project.dependencies.enforcedPlatform(
"org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${kotlinWrappersVersion}"
)
)
}
val webDir = file("src/main/web")
resources.srcDir(webDir)
}
test {
dependencies {
implementation(kotlin("test-js"))
implementation("io.kvision:kvision-testutils:$kvisionVersion")
}
}
}
}

View file

@ -0,0 +1,34 @@
package dev.adamko.kafkatorio.webmap
import io.kvision.Application
import io.kvision.CoreModule
import io.kvision.BootstrapModule
import io.kvision.BootstrapCssModule
import io.kvision.BootstrapIconsModule
import io.kvision.FontAwesomeModule
import io.kvision.ChartModule
import io.kvision.html.div
import io.kvision.module
import io.kvision.panel.root
import io.kvision.startApplication
class App : Application() {
override fun start() {
root("kvapp") {
div("Hello world")
}
}
}
fun main() {
startApplication(
::App,
module.hot,
BootstrapModule,
BootstrapCssModule,
BootstrapIconsModule,
FontAwesomeModule,
ChartModule,
CoreModule
)
}

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>KVision Template</title>
<script type="text/javascript" src="main.bundle.js"></script>
</head>
<body>
<div id="kvapp"></div>
</body>
</html>

View file

@ -0,0 +1,15 @@
package test.dev.adamko.kafkatorio.webmap
import io.kvision.test.SimpleSpec
import kotlin.test.Test
import kotlin.test.assertTrue
class AppSpec : SimpleSpec {
@Test
fun render() {
run {
assertTrue(true, "Dummy test")
}
}
}

View file

@ -0,0 +1,3 @@
config.module.rules.push({test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, type: 'asset'});
config.module.rules.push({test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, type: 'asset'});
config.module.rules.push({test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, type: 'asset/resource'});

View file

@ -0,0 +1,2 @@
config.module.rules.push({ test: /\.css$/, use: ["style-loader", { loader: "css-loader", options: {sourceMap: false} } ] });

View file

@ -0,0 +1,6 @@
config.module.rules.push(
{
test: /\.(jpe?g|png|gif|svg)$/i,
type: 'asset/resource'
}
);

View file

@ -0,0 +1,6 @@
config.module.rules.push(
{
test: /\.hbs$/i,
loader: 'handlebars-loader'
}
);

View file

@ -0,0 +1,9 @@
;(function() {
const webpack = require('webpack')
config.plugins.push(new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
}));
})();

View file

@ -0,0 +1,15 @@
;(function() {
const webpack = require('webpack')
try {
const moment = require("moment");
config.plugins.push(new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}));
config.plugins.push(new webpack.ProvidePlugin({
moment: "moment",
"window.moment": "moment"
}));
} catch (e) {
}
})();

View file

@ -0,0 +1,15 @@
config.resolve.modules.push("../../processedResources/js/main");
if (config.devServer) {
config.devServer.hot = true;
config.devtool = 'eval-cheap-source-map';
} else {
config.devtool = undefined;
}
// disable bundle size warning
config.performance = {
assetFilter: function (assetFilename) {
return !assetFilename.endsWith('.js');
},
};

View file

@ -12,6 +12,7 @@ include(
":modules:infra-kafka-pipe",
":modules:kt-rcon",
":modules:web-map",
)
enableFeaturePreview("VERSION_CATALOGS")