From 26c04f1ce9de8f4a207946e7d87de2128db3baf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 24 Nov 2013 01:54:15 +0100 Subject: [PATCH] made ram and disk sizes for the three tiers configurable and generalized their localization method (not one per tier but one for all that gets extended based on the tier); more informative status bare messages for text editor --- assets/opencomputers/lang/de_DE.lang | 8 +--- assets/opencomputers/lang/en_US.lang | 8 +--- assets/opencomputers/lua/rom/bin/edit.lua | 45 +++++++++++++----- assets/opencomputers/textures/items/hdd0.png | Bin 0 -> 265 bytes .../textures/items/{hdd4.png => hdd1.png} | Bin assets/opencomputers/textures/items/hdd8.png | Bin 265 -> 0 bytes .../textures/items/{ram32.png => ram0.png} | Bin .../textures/items/{ram64.png => ram1.png} | Bin .../textures/items/{ram128.png => ram2.png} | Bin li/cil/oc/Config.scala | 20 +++++++- li/cil/oc/Items.scala | 12 ++--- li/cil/oc/common/item/Delegate.scala | 2 + li/cil/oc/common/item/Delegator.scala | 9 ++++ li/cil/oc/common/item/HardDiskDrive.scala | 20 ++++++-- li/cil/oc/common/item/Memory.scala | 12 +++-- li/cil/oc/server/driver/item/FileSystem.scala | 2 +- 16 files changed, 99 insertions(+), 39 deletions(-) create mode 100644 assets/opencomputers/textures/items/hdd0.png rename assets/opencomputers/textures/items/{hdd4.png => hdd1.png} (100%) delete mode 100644 assets/opencomputers/textures/items/hdd8.png rename assets/opencomputers/textures/items/{ram32.png => ram0.png} (100%) rename assets/opencomputers/textures/items/{ram64.png => ram1.png} (100%) rename assets/opencomputers/textures/items/{ram128.png => ram2.png} (100%) diff --git a/assets/opencomputers/lang/de_DE.lang b/assets/opencomputers/lang/de_DE.lang index 345b01b18..6d435b587 100644 --- a/assets/opencomputers/lang/de_DE.lang +++ b/assets/opencomputers/lang/de_DE.lang @@ -19,12 +19,8 @@ oc:item.Disk.name=Diskette oc:item.GraphicsCardAdvanced.name=Hochwertige Grafikkarte oc:item.GraphicsCardBasic.name=Einfache Grafikkarte oc:item.GraphicsCardProfessional.name=Professionelle Grafikkarte -oc:item.HardDiskDrive2m.name=Festplatte (2MB) -oc:item.HardDiskDrive4m.name=Festplatte (4MB) -oc:item.HardDiskDrive8m.name=Festplatte (8MB) -oc:item.Memory128k.name=RAM (128KB) -oc:item.Memory32k.name=RAM (32KB) -oc:item.Memory64k.name=RAM (64KB) +oc:item.HardDiskDrive.name=Festplatte +oc:item.Memory.name=Speicher oc:item.NetworkCard.name=Netzwerkkarte oc:item.PowerSupply.name=Netzteil oc:item.RedstoneCard.name=Redstonekarte diff --git a/assets/opencomputers/lang/en_US.lang b/assets/opencomputers/lang/en_US.lang index c2cd2edb7..3afe0a929 100644 --- a/assets/opencomputers/lang/en_US.lang +++ b/assets/opencomputers/lang/en_US.lang @@ -19,12 +19,8 @@ oc:item.Disk.name=Floppy Disk oc:item.GraphicsCardAdvanced.name=Advanced Graphics Card oc:item.GraphicsCardBasic.name=Basic Graphics Card oc:item.GraphicsCardProfessional.name=Professional Graphics Card -oc:item.HardDiskDrive2m.name=Hard Disk Drive (2MB) -oc:item.HardDiskDrive4m.name=Hard Disk Drive (4MB) -oc:item.HardDiskDrive8m.name=Hard Disk Drive (8MB) -oc:item.Memory128k.name=RAM (128KB) -oc:item.Memory32k.name=RAM (32KB) -oc:item.Memory64k.name=RAM (64KB) +oc:item.HardDiskDrive.name=Hard Disk Drive +oc:item.Memory.name=Memory oc:item.NetworkCard.name=Network Card oc:item.PowerSupply.name=Power Supply oc:item.RedstoneCard.name=Redstone Card diff --git a/assets/opencomputers/lua/rom/bin/edit.lua b/assets/opencomputers/lua/rom/bin/edit.lua index 128e16e37..e5bfa5d5b 100644 --- a/assets/opencomputers/lua/rom/bin/edit.lua +++ b/assets/opencomputers/lua/rom/bin/edit.lua @@ -27,9 +27,6 @@ local scrollX, scrollY = 0, 0 ------------------------------------------------------------------------------- local function setStatus(value) - if not value then - value = string.format([["%s" %dL Menu: [Ctrl] ]], fs.name(filename), #buffer) - end local w, h = component.gpu.getResolution() component.gpu.set(1, h, text.padRight(unicode.sub(value, 1, w - 10), w - 10)) end @@ -175,7 +172,7 @@ local function delete() component.gpu.copy(1, cy + 2, w, h - (cy + 1), 0, -1) component.gpu.set(1, h, text.padRight(buffer[cby + (h - cy)], w)) end - setStatus() + setStatus("Save: [Ctrl+S] Close: [Ctrl+W]") end end @@ -193,6 +190,7 @@ local function insert(value) end component.gpu.set(cx, cy, value) right(len) + setStatus("Save: [Ctrl+S] Close: [Ctrl+W]") end local function enter() @@ -209,7 +207,7 @@ local function enter() component.gpu.set(1, cy + 1, text.padRight(buffer[cby + 1], w)) end setCursor(1, cby + 1) - setStatus() + setStatus("Save: [Ctrl+S] Close: [Ctrl+W]") end local function onKeyDown(char, code) @@ -237,13 +235,27 @@ local function onKeyDown(char, code) elseif keyboard.isControlDown() then local cbx, cby = getCursor() if code == keyboard.keys.s and not readonly then - local f = io.open(filename, "w") - for _, line in ipairs(buffer) do - f:write(line) - f:write("\n") + local new = not fs.exists(filename) + local f, reason = io.open(filename, "w") + if f then + local chars = 0 + for _, line in ipairs(buffer) do + f:write(line) + f:write("\n") + chars = chars + unicode.len(line) + end + f:close() + local format + if new then + format = [["%s" [New] %dL,%dC written]] + else + format = [["%s" %dL,%dC written]] + end + setStatus(string.format(format, fs.name(filename), #buffer, chars)) + else + setStatus(reason) end - f:close() - elseif code == keyboard.keys.w then + elseif code == keyboard.keys.w or code == keyboard.keys.c or code == keyboard.keys.x then -- TODO ask to save if changed running = false end @@ -278,18 +290,27 @@ do local f = io.open(filename) if f then local w, h = getSize() + local chars = 0 for line in f:lines() do table.insert(buffer, line) + chars = chars + unicode.len(line) if #buffer <= h then component.gpu.set(1, #buffer, line) end end f:close() + local format + if readonly then + format = [["%s" [readonly] %dL,%dC]] + else + format = [["%s" [New File] %dL,%dC]] + end + setStatus(string.format(format, fs.name(filename), #buffer, chars)) else table.insert(buffer, "") + setStatus(string.format([["%s" [New File] ]], fs.name(filename))) end setCursor(1, 1) - setStatus() end while running do diff --git a/assets/opencomputers/textures/items/hdd0.png b/assets/opencomputers/textures/items/hdd0.png new file mode 100644 index 0000000000000000000000000000000000000000..8922421fb1fdd1f09a192232937f2080418b0b15 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!fo^#Gp`S95do|NsAg`}Qp~H1y`pn;SN4ICkvVmMvSlyStYy zTefGdb~?}SY{O0t>16K7%I8X-eBT)^%f!Rbyq9fh@8TFI4e zs9M%^>~x;tS%)PYuWPv{E1xTU@_lExEE5kyGdJ7P$H&%t1Fd54boFyt=akR{0Ike# AR{#J2 diff --git a/assets/opencomputers/textures/items/ram32.png b/assets/opencomputers/textures/items/ram0.png similarity index 100% rename from assets/opencomputers/textures/items/ram32.png rename to assets/opencomputers/textures/items/ram0.png diff --git a/assets/opencomputers/textures/items/ram64.png b/assets/opencomputers/textures/items/ram1.png similarity index 100% rename from assets/opencomputers/textures/items/ram64.png rename to assets/opencomputers/textures/items/ram1.png diff --git a/assets/opencomputers/textures/items/ram128.png b/assets/opencomputers/textures/items/ram2.png similarity index 100% rename from assets/opencomputers/textures/items/ram128.png rename to assets/opencomputers/textures/items/ram2.png diff --git a/li/cil/oc/Config.scala b/li/cil/oc/Config.scala index 6b4bcc09d..b2fda12c1 100644 --- a/li/cil/oc/Config.scala +++ b/li/cil/oc/Config.scala @@ -42,7 +42,7 @@ object Config { // power.buffer var bufferCapacitor = 500.0 var bufferConverter = 100.0 - var bufferChargingStation = 50000.0 // TODO + var bufferChargingStation = 50000.0 // TODO implement var bufferPowerSupply = 50.0 var bufferRobot = 10000.0 @@ -71,6 +71,7 @@ object Config { var maxClipboard = 1024 var maxUsernameLength = 32 var maxUsers = 16 + var ramSizes = Array(64, 128, 256) var startupDelay = 0.25 var threads = 4 var timeout = 1.0 @@ -78,6 +79,7 @@ object Config { // server.filesystem var fileCost = 512 var bufferChanges = true + var hddSizes = Array(2048, 4096, 8192) var maxHandles = 16 var maxReadBuffer = 8 * 1024 @@ -316,6 +318,14 @@ object Config { |amounts of memory by registering an unlimited number of users. |See also: `canComputersBeOwned`.""".stripMargin) max 0 + ramSizes = (config.fetch("server.computer.ramSizes", ramSizes, + """|The sizes of the three tiers of RAM, in kilobytes. If this list is + |longer than three entries, the remaining ones will be ignored. If the + |list is shorter it will be filled up with the default values, assuming + |the given values (if any) are the lower tiers.""".stripMargin). + map(_ max 0).padTo(3, Int.MinValue), ramSizes).zipped. + map((a, b) => if (a >= 0) a else b) + startupDelay = config.fetch("server.computer.startupDelay", startupDelay, """|The time in seconds to wait after a computer has been restored before |it continues to run. This is meant to allow the world around the @@ -358,6 +368,14 @@ object Config { |since all loaded files have to be kept in memory (loaded as in when |the hard drive is in a computer).""".stripMargin) + hddSizes = (config.fetch("server.computer.hddSizes", hddSizes, + """|The sizes of the three tiers of hard drives, in kilobytes. If this + |list is longer than three entries, the remaining ones will be ignored. + |If the list is shorter it will be filled up with the default values, + |assuming the given values (if any) are the lower tiers.""".stripMargin). + map(_ max 0).padTo(3, Int.MinValue), hddSizes).zipped. + map((a, b) => if (a >= 0) a else b) + maxHandles = config.fetch("server.filesystem.maxHandles", maxHandles, """|The maximum number of file handles any single computer may have open |at a time. Note that this is *per filesystem*. Also note that this is diff --git a/li/cil/oc/Items.scala b/li/cil/oc/Items.scala index 78baf9d70..53551ef4f 100644 --- a/li/cil/oc/Items.scala +++ b/li/cil/oc/Items.scala @@ -25,14 +25,14 @@ object Items { gpu1 = new item.GraphicsCard(multi, 0) gpu2 = new item.GraphicsCard(multi, 1) gpu3 = new item.GraphicsCard(multi, 2) - hdd1 = new item.HardDiskDrive(multi, 2) - hdd2 = new item.HardDiskDrive(multi, 4) - hdd3 = new item.HardDiskDrive(multi, 8) + hdd1 = new item.HardDiskDrive(multi, 0) + hdd2 = new item.HardDiskDrive(multi, 1) + hdd3 = new item.HardDiskDrive(multi, 2) lan = new item.NetworkCard(multi) psu = new item.PowerSupply(multi) - ram1 = new item.Memory(multi, 32) - ram2 = new item.Memory(multi, 64) - ram3 = new item.Memory(multi, 128) + ram1 = new item.Memory(multi, 0) + ram2 = new item.Memory(multi, 1) + ram3 = new item.Memory(multi, 2) rs = new item.RedstoneCard(multi) wlan = new item.WirelessNetworkCard(multi) } diff --git a/li/cil/oc/common/item/Delegate.scala b/li/cil/oc/common/item/Delegate.scala index 218b2e3ab..f9afd2321 100644 --- a/li/cil/oc/common/item/Delegate.scala +++ b/li/cil/oc/common/item/Delegate.scala @@ -21,6 +21,8 @@ trait Delegate { def addInformation(item: ItemStack, player: EntityPlayer, tooltip: java.util.List[String], advanced: Boolean) {} + def getItemDisplayName(stack: ItemStack): Option[String] = None + def icon: Option[Icon] = _icon protected def icon_=(value: Icon) = _icon = Option(value) diff --git a/li/cil/oc/common/item/Delegator.scala b/li/cil/oc/common/item/Delegator.scala index 27cff5d76..0a2eb5853 100644 --- a/li/cil/oc/common/item/Delegator.scala +++ b/li/cil/oc/common/item/Delegator.scala @@ -77,6 +77,15 @@ class Delegator(id: Int) extends Item(id) { case _ => getUnlocalizedName } + override def getItemDisplayName(stack: ItemStack) = + subItem(stack) match { + case Some(subItem) => subItem.getItemDisplayName(stack) match { + case Some(name) => name + case _ => super.getItemDisplayName(stack) + } + case _ => super.getItemDisplayName(stack) + } + override def getUnlocalizedName: String = Config.namespace + "item" override def isBookEnchantable(itemA: ItemStack, itemB: ItemStack): Boolean = false diff --git a/li/cil/oc/common/item/HardDiskDrive.scala b/li/cil/oc/common/item/HardDiskDrive.scala index 36a40d7b9..1492145e4 100644 --- a/li/cil/oc/common/item/HardDiskDrive.scala +++ b/li/cil/oc/common/item/HardDiskDrive.scala @@ -6,8 +6,10 @@ import net.minecraft.client.renderer.texture.IconRegister import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack -class HardDiskDrive(val parent: Delegator, val megaBytes: Int) extends Delegate { - val unlocalizedName = "HardDiskDrive" + megaBytes + "m" +class HardDiskDrive(val parent: Delegator, val tier: Int) extends Delegate { + val unlocalizedName = "HardDiskDrive" + + val kiloBytes = Config.hddSizes(tier) override def addInformation(item: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) = { super.addInformation(item, player, tooltip, advanced) @@ -26,16 +28,26 @@ class HardDiskDrive(val parent: Delegator, val megaBytes: Int) extends Delegate val fsNbt = data.getCompoundTag("fs") if (fsNbt.hasKey("capacity.used")) { val used = fsNbt.getLong("capacity.used") - tooltip.add("Disk usage: %d/%d Byte".format(used, megaBytes * 1024 * 1024)) + tooltip.add("Disk usage: %d/%d Byte".format(used, kiloBytes * 1024)) } } } } } + override def getItemDisplayName(stack: ItemStack) = { + val localizedName = parent.getItemStackDisplayName(stack) + Some(if (kiloBytes >= 1024) { + localizedName + " (%dMB)".format(kiloBytes / 1024) + } + else { + localizedName + " (%dKB)".format(kiloBytes) + }) + } + override def registerIcons(iconRegister: IconRegister) { super.registerIcons(iconRegister) - icon = iconRegister.registerIcon(Config.resourceDomain + ":hdd" + megaBytes) + icon = iconRegister.registerIcon(Config.resourceDomain + ":hdd" + tier) } } \ No newline at end of file diff --git a/li/cil/oc/common/item/Memory.scala b/li/cil/oc/common/item/Memory.scala index 404244f83..43114020f 100644 --- a/li/cil/oc/common/item/Memory.scala +++ b/li/cil/oc/common/item/Memory.scala @@ -2,13 +2,19 @@ package li.cil.oc.common.item import li.cil.oc.Config import net.minecraft.client.renderer.texture.IconRegister +import net.minecraft.item.ItemStack -class Memory(val parent: Delegator, val kiloBytes: Int) extends Delegate { - val unlocalizedName = "Memory" + kiloBytes + "k" +class Memory(val parent: Delegator, val tier: Int) extends Delegate { + val unlocalizedName = "Memory" + + val kiloBytes = Config.ramSizes(tier) + + override def getItemDisplayName(stack: ItemStack) = + Some(parent.getItemStackDisplayName(stack) + " (%dKB)".format(kiloBytes)) override def registerIcons(iconRegister: IconRegister) { super.registerIcons(iconRegister) - icon = iconRegister.registerIcon(Config.resourceDomain + ":ram" + kiloBytes) + icon = iconRegister.registerIcon(Config.resourceDomain + ":ram" + tier) } } diff --git a/li/cil/oc/server/driver/item/FileSystem.scala b/li/cil/oc/server/driver/item/FileSystem.scala index 5d0bb85f1..92fa63f93 100644 --- a/li/cil/oc/server/driver/item/FileSystem.scala +++ b/li/cil/oc/server/driver/item/FileSystem.scala @@ -29,7 +29,7 @@ object FileSystem extends Item { case _ => null } } else Items.multi.subItem(item) match { - case Some(hdd: HardDiskDrive) => createEnvironment(item, hdd.megaBytes * 1024 * 1024) + case Some(hdd: HardDiskDrive) => createEnvironment(item, hdd.kiloBytes * 1024) case Some(disk: Disk) => createEnvironment(item, 512 * 1024) case _ => null }