fixed default config failing to load on some systems (reported on Minecraft Forums, could not reproduce but this change reportedly did the trick)

This commit is contained in:
Florian Nücke 2013-12-20 19:53:57 +01:00
parent eb28209f1b
commit 3a87ecd6ce
2 changed files with 14 additions and 7 deletions

View File

@ -164,7 +164,17 @@ object Settings {
def get = settings def get = settings
def load(file: File) = { def load(file: File) = {
val defaults = ConfigFactory.defaultReference().withOnlyPath("opencomputers") // typesafe config's internal method for loading the reference.conf file
// seems to fail on some systems (as does their parseResource method), so
// we'll have to load the default config manually. This was reported on the
// Minecraft Forums, I could not reproduce the issue, but this version has
// reportedly fixed the problem.
val defaults = {
val in = classOf[Settings].getResourceAsStream("/reference.conf")
val config = ConfigFactory.parseReader(new BufferedReader(new InputStreamReader(in)))
in.close()
config
}
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"))

View File

@ -699,9 +699,6 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
} }
try { try {
// Push a couple of functions that override original Lua API functions or
// that add new functionality to it.
// Push a couple of functions that override original Lua API functions or // Push a couple of functions that override original Lua API functions or
// that add new functionality to it. // that add new functionality to it.
lua.getGlobal("os") lua.getGlobal("os")
@ -776,7 +773,7 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
// clutter it. // clutter it.
lua.newTable() lua.newTable()
// Allow getting the real world time via os.realTime() for timeouts. // Allow getting the real world time for timeouts.
lua.pushScalaFunction(lua => { lua.pushScalaFunction(lua => {
lua.pushNumber(System.currentTimeMillis() / 1000.0) lua.pushNumber(System.currentTimeMillis() / 1000.0)
1 1
@ -786,7 +783,7 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
// The time the computer has been running, as opposed to the CPU time. // The time the computer has been running, as opposed to the CPU time.
lua.pushScalaFunction(lua => { lua.pushScalaFunction(lua => {
// World time is in ticks, and each second has 20 ticks. Since we // World time is in ticks, and each second has 20 ticks. Since we
// want os.uptime() to return real seconds, though, we'll divide it // want uptime() to return real seconds, though, we'll divide it
// accordingly. // accordingly.
lua.pushNumber((worldTime - timeStarted) / 20.0) lua.pushNumber((worldTime - timeStarted) / 20.0)
1 1
@ -831,7 +828,7 @@ class Computer(val owner: tileentity.Computer) extends ManagedComponent with Con
}) })
lua.setField(-2, "pushSignal") lua.setField(-2, "pushSignal")
// And it's ROM address. // And its ROM address.
lua.pushScalaFunction(lua => { lua.pushScalaFunction(lua => {
rom.foreach(rom => Option(rom.node.address) match { rom.foreach(rom => Option(rom.node.address) match {
case None => lua.pushNil() case None => lua.pushNil()