Skip to content

Commit

Permalink
annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyline300 committed Sep 10, 2024
1 parent 9dc2624 commit 236a29a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/main/scala/com/skyline/warlangmod/Language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,47 @@ package com.skyline.warlangmod
import scala.io.BufferedSource
import scala.util.Try


// the base case class that stores the data
case class Language(objName: String, translation: String) extends Renderable {
override def render(): String =
override def render(): String = {
// combines both back together in a single line
s"$objName;$translation"
}

override def toString: String =
s"Language(objName=$objName, translation=$translation)"
}

// the case class we will use to store the Languages case class
case class Translations(languages: Vector[Language]) extends Renderable {
override def render(): String =
override def render(): String = {
// calls the render function from Languages, and makes a new lines after every
// Language class
languages.map(_.render()).mkString("\n")
}

override def toString: String =
s"Translations(languages=[${languages.mkString(",")}])"
}

object Language {
// parses the csv files
def parse(languageFile: BufferedSource): Translations = {
val iter = languageFile.getLines()
val languages = iter.flatMap { str =>
// removes the quotation marks of every line
val sanitizedString = str.replace("\"", "")
// splits the object name and it's localized translation names
val splitString = sanitizedString.split(";")
Try {
// gets the object name
val objName = splitString(0)
if(objName.isEmpty) {
throw new RuntimeException("This is gay")
}
// gets the translation names
val (_, translation) = splitString.splitAt(1)
// translation(0) filters it only to english
Language(objName, translation(0))
}.toOption
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object TranslationOverwriteService {
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
// what the fuck does this do again
val overwrittenLanguageTranslation = moddedMap.getOrElse(language.objName, language.translation)
language.copy(translation = overwrittenLanguageTranslation)
}
Expand Down

0 comments on commit 236a29a

Please sign in to comment.