Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving CLI tooltip and usage #5

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bsp/sbt.json

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jobs:
with:
distribution: temurin
java-version: 17
- name: Test Build
run: sbt test
- name: Build JAR
run: sbt assembly
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ target/
*/target
**/target
.bsp/*
.bst/**/*
.bsp/**/*
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@ An updater for lang files for War Thunder, written in Scala

You will need your existing Units.csv file and the updated version file, renamed to UnitsN.csv, something you can get from Gszabi99's repository [here](https://github.com/gszabi99/War-Thunder-Datamine).
<br>
Run the file like so:
Help file
```shell
$ java -jar WarThunder-Lang-Updater-0.1.0-SNAPSHOT.jar --help

Usage: WarThunder Translation Updater [--input <string>] [--original <string>] [--output <string>]

A tool to update the translation files for WarThunder

Options and flags:
--help
Display this help text.
--input <string>, -i <string>
The input file to be updated, defaults to units.csv when not provided
--original <string>, -r <string>
The original file to be updated, defaults to unitsN.csv when not provided
--output <string>, -o <string>
The output file to be written to, defaults unitsMod.csv when not provided
```
run 'file path 1' 'file path 2'

Run the JAR file with the following command:
```shell
$ java -jar WarThunder-Lang-Updater-0.1.0-SNAPSHOT.jar --input <file path 1> --original <file path 2> --output <file path 3>
```
where file path 1 and 2 are your old and new version files respectively, it can be your absolute or relative path

Where `input` file is your old translations file and `original` is the translation file from the most recent WarThunder Client, it can be your absolute or relative path

The `output` file is the file that will be written to, it can be absolute or relative path


## Can you use this for any other file other than Units.csv?
Some of the localization files currently do not work with this program. So far I've confirmed it to work with units and units_weaponry.
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.13.11"
ThisBuild / scalaVersion := "2.13.13"

ThisBuild / organization := "com.skyline.warlangmod"

lazy val root = (project in file("."))
.settings(
name := "WarThunder Language Updater",
assembly / mainClass := Some("com.skyline.warlangmod.Main"),
libraryDependencies ++= Seq(
"com.monovore" %% "decline" % "2.4.1",
"org.scalameta" %% "munit" % "0.7.29" % Test,
),
)
15 changes: 15 additions & 0 deletions src/main/scala/com/skyline/warlangmod/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.skyline.warlangmod

import java.io.FileWriter

object App {
def run(inputFileName: String, originalFile: String, outputFileName: String): Unit = {
val parsingService = ParsingService.instance
val translationOverwrite = TranslationOverwriteService.instance
val outputService = Output.instance
val moddedTranslations = parsingService.translations(inputFileName)
val originalUpdatedTranslations = parsingService.translations(originalFile)
val updatedModdedFile = translationOverwrite.overwrite(originalUpdatedTranslations, moddedTranslations)
outputService.write(updatedModdedFile, outputFileName)
}
}
1 change: 0 additions & 1 deletion src/main/scala/com/skyline/warlangmod/Language.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.skyline.warlangmod

import scala.collection.mutable.ArrayBuffer
import scala.io.BufferedSource
import scala.util.Try

Expand Down
41 changes: 25 additions & 16 deletions src/main/scala/com/skyline/warlangmod/Main.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package com.skyline.warlangmod

import java.io.FileWriter
import com.monovore.decline._

object Main {
def main(args: Array[String]): Unit = {
import cats.implicits._

if(args.length < 2)
System.exit(1) // No input file
object Main extends CommandApp(
name = "WarThunder Translation Updater",
header = "A tool to update the translation files for WarThunder ",
main = {
val defaultInFile = "units.csv"
val defaultOriginalFile = "unitsN.csv"
val defaultOutFile = "unitsMod.csv"
val originalFile = Opts.option[String](
long = "original",
short = "r",
help = s"The original file to be updated, defaults to $defaultOriginalFile when not provided").withDefault(defaultOriginalFile)
val inFile = Opts.option[String](
long = "input",
short = "i",
help = s"The input file to be updated, defaults to $defaultInFile when not provided").withDefault(defaultInFile)
val outFile = Opts.option[String](
long = "output",
short = "o",
help = s"The output file to be written to, defaults $defaultOutFile when not provided").withDefault(defaultOutFile)

val parsingService = ParsingService()
val translationOverwriter = TranslationOverwriteService()
val outputService = Output()

val moddedTranslations = parsingService.translations(args(0))
val originalUpdatedTranslations = parsingService.translations(args(1))

val uptodateModdedTranslationFile = translationOverwriter.overwrite(originalUpdatedTranslations, moddedTranslations)

outputService.write(uptodateModdedTranslationFile)
(inFile, originalFile, outFile).mapN {
(inputFileName, originalFileName, outputFileName) => App.run(inputFileName, originalFileName, outputFileName)
}
}
}
)
11 changes: 7 additions & 4 deletions src/main/scala/com/skyline/warlangmod/Output.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.skyline.warlangmod

/**
* For writing the translations to a file
*/
trait Output {
def write(file: Translations): Unit
def write(file: Translations, outputFileName: String): Unit
}

object Output {
def apply(): Output = new Output {
lazy val instance: Output = new Output {
import java.io.FileWriter
override def write(file: Translations): Unit = {
val updatedFile = new FileWriter("UnitsMod.csv")
override def write(file: Translations, outputFileName: String): Unit = {
val updatedFile = new FileWriter(outputFileName)
updatedFile.write(file.render())
updatedFile.close()
}
Expand Down
20 changes: 11 additions & 9 deletions src/main/scala/com/skyline/warlangmod/ParsingService.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.skyline.warlangmod

import scala.io.Source

/**
* For parsing language/translation files of WarThunder
*/

trait ParsingService {
def translations(filename: String): Translations
}

object ParsingService {

def apply(): ParsingService = new ParsingService {
import scala.io.Source
override def translations(filename: String): Translations = {
val langFile = Source.fromFile(filename)
val translations = Language.parse(langFile)
langFile.close()
translations
}

lazy val instance: ParsingService = (filename: String) => {
val langFile = Source.fromFile(filename)
val translations = Language.parse(langFile)
langFile.close()
translations
}

}
3 changes: 3 additions & 0 deletions src/main/scala/com/skyline/warlangmod/Renderable.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.skyline.warlangmod

/**
* A trait for objects that can be rendered as a string.
*/
trait Renderable {
def render(): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ trait TranslationOverwriteService {
}

object TranslationOverwriteService {
def apply(): TranslationOverwriteService = new TranslationOverwriteService {
lazy val instance: TranslationOverwriteService = new TranslationOverwriteService {

private type ObjectName = String

override def overwrite(original: Translations, modded: Translations): Translations = {
val moddedMap = toMap(modded)
val updated = original.languages.map { language =>
// headOption because we only need the first translation which is english
// Fuck the french btw
val overwrittenLanguageTranslation = moddedMap.get(language.objName).getOrElse(language.translation)
val overwrittenLanguageTranslation = moddedMap.getOrElse(language.objName, language.translation)
language.copy(translation = overwrittenLanguageTranslation)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.skyline.warlangmod

import java.io.FileWriter
import java.nio.file.Files

class ParsingServiceInstanceSpec extends munit.FunSuite {
test("ParsingServiceInstance should parse a WarThunder Translation file format") {
val translations = Translations(
languages = Vector(
Language("something", "good")
)
)
val tmpFile = Files.createTempFile("ParsingServiceInstanceTestFile", null)
val writer = new FileWriter(tmpFile.toFile)
writer.write(translations.render())
writer.close()
val parsedTranslation = ParsingService.instance.translations(tmpFile.toAbsolutePath.toString)
assertEquals(parsedTranslation, translations)
}
}
Loading