changeset 6:2fb901161013

s/Chest/Container/g
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Jan 2011 05:43:16 +0200
parents af0b958a6e17
children 6ff1ee9122b2
files index.php
diffstat 1 files changed, 113 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Mon Jan 10 05:08:49 2011 +0200
+++ b/index.php	Mon Jan 10 05:43:16 2011 +0200
@@ -1,5 +1,5 @@
 <?
-$pageTitle = "Pupunen BatMUD Chest Command Creator ALPHA";
+$pageTitle = "Pupunen BatMUD Container Command Creator ALPHA";
 $pageIndex = "index.php";
 require "mcommon.inc.php";
 
@@ -235,17 +235,17 @@
      <tr>
       <td><input type="button" value=" Delete " onclick="deleteItems(this.form);" /></td>
       <td><input type="button" value=" Add new " onclick="addItems(this.form);" disabled="disabled" /></td>
-      <td style="width: 60%; text-align: right;"><input id="move_button" type="button" value=" Move to chest " onclick="moveItems(this.form);" /></td>
+      <td style="width: 60%; text-align: right;"><input id="move_button" type="button" value=" Move to container " onclick="moveItems(this.form);" /></td>
      </tr>
     </table>
    </td>
 
-   <td id="chest_editor">
-    <h2>Editing chest "<span id="curr_name"></span>" - <span id="curr_info"></span></h2>
-    <? printOptionSelect("curr_chest", 10, TRUE); ?>
+   <td id="container_editor">
+    <h2>Editing container "<span id="curr_name"></span>" - <span id="curr_info"></span></h2>
+    <? printOptionSelect("curr_container", 10, TRUE); ?>
     <table class="buttons">
      <tr>
-      <td><input type="button" value=" Remove selected " onclick="chestRemoveItems(this.form);" /></td>
+      <td><input type="button" value=" Remove selected " onclick="containerRemoveItems(this.form);" /></td>
      </tr>
     </table>
    </td>
@@ -253,22 +253,22 @@
 
   <tr>
    <td>
-    <h2>Create / edit a chest</h2>
+    <h2>Create / edit a container</h2>
 <?
-printInputField("chest_name", "Identifier/name", 15);
-printInputField("chest_slots", "Number of slots", 5);
+printInputField("container_name", "Identifier/name", 15);
+printInputField("container_slots", "Number of slots", 5);
  ?>
-    <input type="button" value=" Create " onclick="chestCreate(this.form);" id="create_button" />
+    <input type="button" value=" Create " onclick="containerCreate(this.form);" id="create_button" />
    </td>
 
-   <td id="chest_list_editor">
-    <h2>Defined chests</h2>
-    <? printOptionSelect("chest_list", 5, FALSE); ?>
+   <td id="container_list_editor">
+    <h2>Defined containers</h2>
+    <? printOptionSelect("container_list", 5, FALSE); ?>
     <table class="buttons">
      <tr>
-      <td><input type="button" value=" Switch to " onclick="chestEdit(this.form);" /></td>
-      <td><input type="button" value=" Delete " onclick="chestDelete(this.form);" /></td>
-      <td><input type="button" value=" Edit " onclick="chestEditProps(this.form);" disabled="disabled" /></td>
+      <td><input type="button" value=" Switch to " onclick="containerEdit(this.form);" /></td>
+      <td><input type="button" value=" Delete " onclick="containerDelete(this.form);" /></td>
+      <td><input type="button" value=" Edit " onclick="containerEditProps(this.form);" disabled="disabled" /></td>
      </tr>
     </table> 
    </td>
@@ -286,8 +286,12 @@
 <div id="options_batmud" class="options">
   <? printInputField("cmd_delim", "Command delimiter", 15, ";"); ?><br />
   <? printInputField("cmd_prefix", "Command name prefix", 15, "mcp"); ?><br />
+  <? printInputField("cmd_cmd", "Command", 32, "put \$1 in \$2"); ?> (<b>$1</b> = item, <b>$2</b> = container)<br />
+  <input type="checkbox" id="cmd_separate" value="true" />
+  <label for="cmd_separate">Create one command for each item, instead of a list.</label><br />
   <input type="checkbox" id="cmd_autoclose" value="true" />
-  <label for="cmd_autoclose">Add commands for automatically opening and closing each chest.</label>
+  <label for="cmd_autoclose">Add commands for automatically opening and closing each container.</label><br />
+  <br />
   <input type="button" value=" Create " onclick="createCommands('batmud');" />
 </div>
 
@@ -300,9 +304,9 @@
 
 <script type="text/javascript">
 <!--
-var curr_chest = null;
+var curr_container = null;
 
-function Chest(name, slots, items)
+function Container(name, slots, items)
 {
   this.name = name;
   this.slots = slots;
@@ -341,11 +345,11 @@
     }
   }
   
-  this.moveItemById = function(chest, id) {
+  this.moveItemById = function(container, id) {
     var item = this.getItemByIndex(id);
     if (item != null) {
       this.deleteItemById(id);
-      chest.addItem(item);
+      container.addItem(item);
       this.changed = true;
     }
   }
@@ -362,22 +366,22 @@
 -->
 <?
 
-function getChestObject($name, $slots, $items)
+function getContainerObject($name, $slots, $items)
 {
-  return "new Chest(\"".$name."\", \"".$slots."\", [".getJSArraySegment($items)."])";
+  return "new Container(\"".$name."\", \"".$slots."\", [".getJSArraySegment($items)."])";
 }
 
 $str = "";
-if (isset($data["chests"])) {
-  foreach ($data["chests"] as $chest) {
+if (isset($data["containers"])) {
+  foreach ($data["containers"] as $container) {
     if ($str != "") $str .= ", ";
-    $str .= getChestObject($chest["name"], $chest["slots"], $chest["items"]);
+    $str .= getContainerObject($container["name"], $container["slots"], $container["items"]);
   }
 }
 
 echo
-"var list_chests = [".$str."];\n".
-"var list_items = ".(isset($data["items"]) ? getChestObject("items", 10000, $data["items"]) : "null").";\n";
+"var list_containers = [".$str."];\n".
+"var list_items = ".(isset($data["items"]) ? getContainerObject("items", 10000, $data["items"]) : "null").";\n";
 ?>
 <!-- #kludge --><!--
 
@@ -407,35 +411,35 @@
     setListData("curr_items", list_items.items);
   }
 
-  // List of chests
-  var chest_list_editor = document.getElementById("chest_list_editor");
-  if (list_chests.length > 0) {
-    chest_list_editor.style.display = "block";
+  // List of containers
+  var container_list_editor = document.getElementById("container_list_editor");
+  if (list_containers.length > 0) {
+    container_list_editor.style.display = "block";
 
-    o = document.getElementById("chest_list");
+    o = document.getElementById("container_list");
     o.options.length = 0;
-    for (var i = 0; i < list_chests.length; i++) {
-      o.options[i] = new Option(list_chests[i].name +" (" + list_chests[i].items.length +" of "+ list_chests[i].slots +" items)", i, false);
+    for (var i = 0; i < list_containers.length; i++) {
+      o.options[i] = new Option(list_containers[i].name +" (" + list_containers[i].items.length +" of "+ list_containers[i].slots +" items)", i, false);
     }
   } else {
-    chest_list_editor.style.display = "none";
+    container_list_editor.style.display = "none";
   }
   
 
-  // Update current chest
-  var chest_editor = document.getElementById("chest_editor");
-  if (curr_chest != null) {
-    chest_editor.style.display = "block";
-    setHTML("curr_name", curr_chest.name);
+  // Update current container
+  var container_editor = document.getElementById("container_editor");
+  if (curr_container != null) {
+    container_editor.style.display = "block";
+    setHTML("curr_name", curr_container.name);
 
-    setHTML("curr_info", "(" + curr_chest.items.length+" / "+curr_chest.slots+" items)");
+    setHTML("curr_info", "(" + curr_container.items.length+" / "+curr_container.slots+" items)");
 
-    if (curr_chest.changed) {
-      curr_chest.changed = false;
-      setListData("curr_chest", curr_chest.items);
+    if (curr_container.changed) {
+      curr_container.changed = false;
+      setListData("curr_container", curr_container.items);
     }
   } else {
-    chest_editor.style.display = "none";
+    container_editor.style.display = "none";
   }
 }
 
@@ -457,11 +461,11 @@
 }
 
 
-// Create a new chest, set current chest to it
-function chestCreate(f)
+// Create a new container, set current container to it
+function containerCreate(f)
 {
-  var name = f.elements['chest_name'].value;
-  var slots = parseInt(f.elements['chest_slots'].value, 10);
+  var name = f.elements['container_name'].value;
+  var slots = parseInt(f.elements['container_slots'].value, 10);
 
   if (isNaN(slots) || slots < 1) {
     statusMsg("Number of slots not set or is invalid.");
@@ -469,85 +473,85 @@
   }
 
   if (name == "") {
-    statusMsg("Empty chest name "+name+".");
+    statusMsg("Empty container name "+name+".");
     return;
   }
 
   if (name.match(/[^a-z0-9_]/)) {
-    statusMsg("Invalid chest name, only lower case alphanumerics and underscore are allowed.");
+    statusMsg("Invalid container name, only lower case alphanumerics and underscore are allowed.");
     return;
   }
   
-  for (var i = 0; i < list_chests.length; i++) {
-    if (list_chests[i].name == name) {
-      statusMsg("Chest with identifier '<b>"+name+"</b>' already exists!");
+  for (var i = 0; i < list_containers.length; i++) {
+    if (list_containers[i].name == name) {
+      statusMsg("Container with identifier '<b>"+name+"</b>' already exists!");
       return;
     }
   }
 
-  curr_chest = new Chest(name, slots, []);
-  list_chests.push(curr_chest);
+  curr_container = new Container(name, slots, []);
+  list_containers.push(curr_container);
 
   clearForm(f);
-  statusMsg("OK, created new chest '<b>"+name+"</b>' with <b>"+slots+"</b> slots.");
+  statusMsg("OK, created new container '<b>"+name+"</b>' with <b>"+slots+"</b> slots.");
   updatePage();
 }
 
 
-function chestCheckSelected(f)
+function containerCheckSelected(f)
 {
-  var id = f.elements['chest_list'].selectedIndex;
+  var id = f.elements['container_list'].selectedIndex;
   
-  if (id < 0 || id >= list_chests.length) {
-    statusMsg("Invalid chest, internal error!");
+  if (id < 0 || id >= list_containers.length) {
+    statusMsg("Invalid container, internal error!");
     return -1;
   }
 
-  return {id: id, chest: list_chests[id]};
+  return {id: id, container: list_containers[id]};
 }
 
 
-// Delete a chest from chest list
-function chestDelete(f)
+// Delete a container from container list
+function containerDelete(f)
 {
-  var ret = chestCheckSelected(f);
-  if (ret.id < 0 || ret.chest == null) return;
+  var ret = containerCheckSelected(f);
+  if (ret.id < 0 || ret.container == null) return;
 
-  var name = ret.chest.name;
-  var len = ret.chest.items.length;
+  var name = ret.container.name;
+  var len = ret.container.items.length;
 
-  var answer = confirm("Really delete selected chest '"+name+"' and move "+len+" items back to pool?");
+  var answer = confirm("Really delete selected container '"+name+"' and move "+len+" items back to pool?");
   if (!answer) {
     statusMsg("Delete operation cancelled.");
     return;
   }
 
-  if (curr_chest == ret.chest)
-    curr_chest = null;
+  if (curr_container == ret.container)
+    curr_container = null;
 
   for (var i = 0; i < len; i++)
-    ret.chest.moveItemById(list_items, i);
+    ret.container.moveItemById(list_items, i);
 
-  list_chests.splice(ret.id, 1);
+  list_containers.splice(ret.id, 1);
       
   if (len > 0) {
-    statusMsg("Deleted chest '"+name+"', "+len+" items returned to pool.");
+    statusMsg("Deleted container '"+name+"', "+len+" items returned to pool.");
   } else {
-    statusMsg("Deleted empty chest '"+name+"'.");
+    statusMsg("Deleted empty container '"+name+"'.");
   }
   updatePage();
 }
 
 
-// Change currently edited chest to another
-function chestEdit(f)
+// Change currently edited container to another
+function containerEdit(f)
 {
-  var ret = chestCheckSelected(f);
-  if (ret.id < 0 || ret.chest == null) return;
+  var ret = containerCheckSelected(f);
+  if (ret.id < 0 || ret.container == null) return;
 
-  curr_chest = ret.chest;
-  curr_chest.changed = true;
-  statusMsg("Switched to chest '"+ret.chest.name+"'.");
+  curr_container = ret.container;
+  curr_container.changed = true;
+  statusMsg("Switched to container '"+ret.container.name+"'.");
   updatePage();
 }
 
@@ -589,8 +593,8 @@
 
 function moveItems(f)
 {
-  if (curr_chest == null) {
-    statusMsg("No chest selected, cannot move items.");
+  if (curr_container == null) {
+    statusMsg("No container selected, cannot move items.");
     return;
   }
   
@@ -600,40 +604,40 @@
     statusMsg("No items selected for deletion.");
     return;
   } else {
-    if (curr_chest.getSpace() < selected.length) {
-      statusMsg("Not enough space! "+ selected.length +" items, only "+ curr_chest.getSpace() +" slots available!");
+    if (curr_container.getSpace() < selected.length) {
+      statusMsg("Not enough space! "+ selected.length +" items, only "+ curr_container.getSpace() +" slots available!");
       return;
     }
   
     for (var i = 0; i < selected.length; i++)
-      list_items.moveItemById(curr_chest, selected[i]);
+      list_items.moveItemById(curr_container, selected[i]);
 
     list_items.flush();
     updatePage();
-    statusMsg("Moved " + selected.length + " items to current chest.");
+    statusMsg("Moved " + selected.length + " items to current container.");
   }
 }
 
 
-function chestRemoveItems(f)
+function containerRemoveItems(f)
 {
-  if (curr_chest == null) {
+  if (curr_container == null) {
     statusMsg("Internal error.");
     return;
   }
   
-  var selected = getSelectedItems(f.elements['curr_chest']);
+  var selected = getSelectedItems(f.elements['curr_container']);
   
   if (selected.length == 0) {
     statusMsg("No items selected for deletion.");
     return;
   } else {
     for (var i = 0; i < selected.length; i++)
-      curr_chest.moveItemById(list_items, selected[i]);
+      curr_container.moveItemById(list_items, selected[i]);
 
-    curr_chest.flush();
+    curr_container.flush();
     updatePage();
-    statusMsg("Removed " + selected.length + " from current chest.");
+    statusMsg("Removed " + selected.length + " from current container.");
   }
 }
 
@@ -654,27 +658,27 @@
 
 function createCommands(mode)
 {
-  if (list_chests.length == 0) {
-    statusMsg("No chest configurations defined!");
+  if (list_containers.length == 0) {
+    statusMsg("No container configurations defined!");
     return;
   }
 
 
   var str = "";
-  for (var i = 0; i < list_chests.length; i++) {
-    var chest = list_chests[i];
+  for (var i = 0; i < list_containers.length; i++) {
+    var container = list_containers[i];
     var s = "";
     var counts = [];
     var curr = [];
 
-    for (var n = 0; n < chest.items.length; n++) {
-      var cnt = chest.getCountByName(chest.items[n]);
-      counts[chest.items[n]] = cnt;
-      curr[chest.items[n]] = 1;
+    for (var n = 0; n < container.items.length; n++) {
+      var cnt = container.getCountByName(container.items[n]);
+      counts[container.items[n]] = cnt;
+      curr[container.items[n]] = 1;
     }
 
-    for (var n = 0; n < chest.items.length; n++) {
-      var item = chest.items[n];
+    for (var n = 0; n < container.items.length; n++) {
+      var item = container.items[n];
       if (mode == "batmud") {
         if (s != "") s += ",";
         s += item;
@@ -691,10 +695,10 @@
       var prefix = document.getElementById("cmd_prefix").value;
       if (delim == "") delim = ";";
 
-      str += "command "+prefix+chest.name+" ";
-      if (opt) str += "open "+chest.name+delim;
-      str += "put "+s+" in "+chest.name;
-      if (opt) str += delim+"close "+chest.name;
+      str += "command "+prefix+container.name+" ";
+      if (opt) str += "open "+container.name+delim;
+      str += "put "+s+" in "+container.name;
+      if (opt) str += delim+"close "+container.name;
       str += "\n";
     }
   }