mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -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
|
package li.cil.oc
|
||||||
|
|
||||||
import com.typesafe.config.{Config, ConfigFactory}
|
import com.typesafe.config.{ConfigRenderOptions, Config, ConfigFactory}
|
||||||
import java.io.{FileOutputStream, File}
|
import java.io._
|
||||||
import java.nio.channels.Channels
|
|
||||||
import li.cil.oc.util.PackedColor
|
import li.cil.oc.util.PackedColor
|
||||||
import scala.collection.convert.WrapAsScala._
|
import scala.collection.convert.WrapAsScala._
|
||||||
|
|
||||||
@ -125,7 +124,7 @@ class Settings(config: Config) {
|
|||||||
Array(tier1: Int, tier2: Int, tier3: Int)
|
Array(tier1: Int, tier2: Int, tier3: Int)
|
||||||
case _ =>
|
case _ =>
|
||||||
OpenComputers.log.warning("Bad number of HDD sizes, ignoring.")
|
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 floppySize = config.getInt("filesystem.floppySize") max 0
|
||||||
val tmpSize = config.getInt("filesystem.tmpSize") max 0
|
val tmpSize = config.getInt("filesystem.tmpSize") max 0
|
||||||
@ -165,17 +164,23 @@ object Settings {
|
|||||||
def get = settings
|
def get = settings
|
||||||
|
|
||||||
def load(file: File) = {
|
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")
|
val defaults = ConfigFactory.defaultReference().withOnlyPath("opencomputers")
|
||||||
try {
|
try {
|
||||||
val config = ConfigFactory.parseFile(file).withFallback(defaults)
|
val config = ConfigFactory.parseFile(file).withFallback(defaults)
|
||||||
settings = new Settings(config.getConfig("opencomputers"))
|
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 {
|
catch {
|
||||||
case e: Throwable =>
|
case e: Throwable =>
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
# OpenComputers configuration. This file uses typesafe config's HOCON syntax.
|
# OpenComputers configuration. This file uses typesafe config's HOCON syntax.
|
||||||
# Try setting your syntax highlighting to YAML, to help readability. At least
|
# Try setting your syntax highlighting to Ruby, to help readability. At least
|
||||||
# in Sublime Text that works really well.
|
# in Sublime Text that works really well. Note that this file is overwritten
|
||||||
# Note that this file is only written if it doesn't exist or is empty. This
|
# whenever you start the game! Changes to the comments may vanish.
|
||||||
# means that if new settings are added to mod, they will *not* appear in an
|
|
||||||
# already existing config file! Sorry about the inconvenience.
|
|
||||||
opencomputers {
|
opencomputers {
|
||||||
|
|
||||||
|
# IDs used by the mod, adjust these if you get conflicts.
|
||||||
ids {
|
ids {
|
||||||
# The item ID used for all non-damageable items.
|
# The item ID used for all non-damageable items.
|
||||||
item: 4600
|
item: 4600
|
||||||
@ -255,6 +254,7 @@ opencomputers {
|
|||||||
harvestSpeedBoostPerLevel: 0.02
|
harvestSpeedBoostPerLevel: 0.02
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Allows fine-tuning of delays for robot actions.
|
||||||
delays {
|
delays {
|
||||||
# The time in seconds to pause execution after a robot turned either
|
# The time in seconds to pause execution after a robot turned either
|
||||||
# left or right. Note that this essentially determines hw fast robots
|
# left or right. Note that this essentially determines hw fast robots
|
||||||
@ -363,6 +363,7 @@ opencomputers {
|
|||||||
# default.
|
# default.
|
||||||
generatorEfficiency: 0.8
|
generatorEfficiency: 0.8
|
||||||
|
|
||||||
|
# Default "buffer" sizes, i.e. how much energy certain blocks can store.
|
||||||
buffer {
|
buffer {
|
||||||
# The amount of energy a single capacitor can store.
|
# The amount of energy a single capacitor can store.
|
||||||
capacitor: 1600.0
|
capacitor: 1600.0
|
||||||
@ -388,6 +389,7 @@ opencomputers {
|
|||||||
converter: 1000.0
|
converter: 1000.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Default "costs", i.e. how much energy certain operations consume.
|
||||||
cost {
|
cost {
|
||||||
# The amount of energy a computer consumes per tick when running.
|
# The amount of energy a computer consumes per tick when running.
|
||||||
computer: 0.5
|
computer: 0.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user