mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 10:21:45 -04:00
casting some black regex magic to format the render output of the typesafe config to make it feasible to write it back to file. the order still gets jumbled, but whatever.
This commit is contained in:
parent
ea05e5a4d6
commit
9a0ebf1bae
@ -1,8 +1,7 @@
|
||||
package li.cil.oc
|
||||
|
||||
import com.typesafe.config.{Config, ConfigFactory}
|
||||
import java.io.{FileOutputStream, File}
|
||||
import java.nio.channels.Channels
|
||||
import com.typesafe.config.{ConfigRenderOptions, Config, ConfigFactory}
|
||||
import java.io._
|
||||
import li.cil.oc.util.PackedColor
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
@ -125,7 +124,7 @@ class Settings(config: Config) {
|
||||
Array(tier1: Int, tier2: Int, tier3: Int)
|
||||
case _ =>
|
||||
OpenComputers.log.warning("Bad number of HDD sizes, ignoring.")
|
||||
Array(2048, 4096, 8192)
|
||||
Array(1024, 2048, 4096)
|
||||
}
|
||||
val floppySize = config.getInt("filesystem.floppySize") max 0
|
||||
val tmpSize = config.getInt("filesystem.tmpSize") max 0
|
||||
@ -165,17 +164,23 @@ object Settings {
|
||||
def get = settings
|
||||
|
||||
def load(file: File) = {
|
||||
if (!file.exists() || file.length() == 0) {
|
||||
val in = Channels.newChannel(classOf[Settings].getResourceAsStream("/reference.conf"))
|
||||
val out = new FileOutputStream(file).getChannel
|
||||
out.transferFrom(in, 0, Long.MaxValue)
|
||||
in.close()
|
||||
out.close()
|
||||
}
|
||||
val defaults = ConfigFactory.defaultReference().withOnlyPath("opencomputers")
|
||||
try {
|
||||
val config = ConfigFactory.parseFile(file).withFallback(defaults)
|
||||
settings = new Settings(config.getConfig("opencomputers"))
|
||||
|
||||
val renderSettings = ConfigRenderOptions.defaults.setJson(false).setOriginComments(false)
|
||||
val out = new PrintWriter(file)
|
||||
out.write(config.root.render(renderSettings).lines.
|
||||
// Strip extra spaces in front and fix additional space in of comments.
|
||||
map(_.stripPrefix(" ").replaceAll("^(\\s*)# ", "$1# ")).
|
||||
// Indent two spaces instead of four.
|
||||
map(line => """^(\s*)""".r.replaceAllIn(line, m => m.group(1).replace(" ", " "))).
|
||||
// Finalize the string.
|
||||
filter(_ != "").mkString("\n").
|
||||
// Newline after values.
|
||||
replaceAll( """((?:\s*#.*\n)(?:\s*[^#\s].*\n)+)""", "$1\n"))
|
||||
out.close()
|
||||
}
|
||||
catch {
|
||||
case e: Throwable =>
|
||||
|
@ -1,11 +1,10 @@
|
||||
# OpenComputers configuration. This file uses typesafe config's HOCON syntax.
|
||||
# Try setting your syntax highlighting to YAML, to help readability. At least
|
||||
# in Sublime Text that works really well.
|
||||
# Note that this file is only written if it doesn't exist or is empty. This
|
||||
# means that if new settings are added to mod, they will *not* appear in an
|
||||
# already existing config file! Sorry about the inconvenience.
|
||||
# Try setting your syntax highlighting to Ruby, to help readability. At least
|
||||
# in Sublime Text that works really well. Note that this file is overwritten
|
||||
# whenever you start the game! Changes to the comments may vanish.
|
||||
opencomputers {
|
||||
|
||||
# IDs used by the mod, adjust these if you get conflicts.
|
||||
ids {
|
||||
# The item ID used for all non-damageable items.
|
||||
item: 4600
|
||||
@ -255,6 +254,7 @@ opencomputers {
|
||||
harvestSpeedBoostPerLevel: 0.02
|
||||
}
|
||||
|
||||
# Allows fine-tuning of delays for robot actions.
|
||||
delays {
|
||||
# The time in seconds to pause execution after a robot turned either
|
||||
# left or right. Note that this essentially determines hw fast robots
|
||||
@ -363,6 +363,7 @@ opencomputers {
|
||||
# default.
|
||||
generatorEfficiency: 0.8
|
||||
|
||||
# Default "buffer" sizes, i.e. how much energy certain blocks can store.
|
||||
buffer {
|
||||
# The amount of energy a single capacitor can store.
|
||||
capacitor: 1600.0
|
||||
@ -388,6 +389,7 @@ opencomputers {
|
||||
converter: 1000.0
|
||||
}
|
||||
|
||||
# Default "costs", i.e. how much energy certain operations consume.
|
||||
cost {
|
||||
# The amount of energy a computer consumes per tick when running.
|
||||
computer: 0.5
|
||||
|
Loading…
x
Reference in New Issue
Block a user