annotate index.php @ 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
2 $pageTitle = "Pupunen BatMUD Container Command Creator ALPHA";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 $pageIndex = "index.php";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 require "mcommon.inc.php";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
6
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
7 // Multi-stack item fixups
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
8 $fixItemTable = array(
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
9 "(purple|green) gloves" => 'a ${1} glove',
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
10 "heavy black metal rings" => "a heavy black metal ring",
5
af0b958a6e17 Bugfix.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
11 "bracelet mades of green crystal" => "bracelet made of green crystal",
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
12 "white cloth packs for holding salves" => "white cloth pack for holding salves",
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
13 );
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
14
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
15
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
16 $fixNumbers = array(
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
17 "one" => 1, "two" => 2, "three" => 3, "four" => 4,
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
18 "five" => 5, "six" => 6, "seven" => 7, "eight" => 8,
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
19 "nine" => 9, "ten" => 10
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
20 );
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
21
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
22
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 function getJSArraySegment($arr)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 $str = "";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 foreach ($arr as $item) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 if ($str != "") $str .= ", ";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 if (is_array($item))
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 $str .= "[".getJSArraySegment($item)."]";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 else
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 $str .= "\"".addslashes($item)."\"";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 return $str;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
37 function printInputField($id, $label, $len, $value = "")
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
39 echo "<label for=\"".$id."\">".htmlentities($label).": </label>".
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
40 "<input type=\"text\" name=\"".$id."\" maxlength=\"".$len.
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
41 "\" size=\"".$len."\" id=\"".$id."\" value=\"".htmlentities($value)."\" />\n";
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
42 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45 function printOptionSelect($id, $size, $multi = FALSE)
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
46 {
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47 echo "<select ".($multi ? " multiple=\"multiple\"" : "")." size=\"".$size."\" id=\"".$id."\"><option></option></select>";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
51 if (isset($_POST["mode"])) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
52 $formMode = intval($_POST["mode"]);
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
53 } else
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
54 $formMode = 0;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
55
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
56
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
57 printPageHeader($pageTitle, "
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
58 <style type=\"text/css\">
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59 <!--
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
60 .buttons { width: 100%; }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
61 div.options { display: none; border: 1px solid white; padding: 1em; }
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
62
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
63 select { width: 100%; }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
64
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
65 #commands { display: none; position: fixed; top: 2em; left: 2em; background: black; padding: 1em; z-index: 15; }
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
67 #status { position: absolute; bottom: 1em; right: 1em; left: 1em; padding: 1pt; margin: 2pt; border: 1px solid white; }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
68 -->
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
69 </style>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
70 ");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 echo "<h1>".$pageTitle."</h1>\n";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
73
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
74 /*
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
75 * Initial mode, request item listing
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
76 */
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 if ($formMode == 0) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 ?>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 <noscript>
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
80 <p>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 <b>This application REQUIRES JavaScript to be enabled!</b>
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
82 </p>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 </noscript>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 <p>
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
85 <form action"<? echo $pageIndex; ?>" method="post">
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
86 <input type="hidden" value="YToxOntzOjU6Iml0ZW1zIjthOjQ3OntpOjA7czozODoiVGhlIHN0YWZmIG9mIExlcmV0aGluIGxhYmVsZWQgYXMgfEdncnwiO2k6MTtzOjM1OiJzd2lybGVkIGdyZWVuIHZlc3QgbGFiZWxlZCBhcyAoR2dyKSI7aToyO3M6Njk6ImEgd2VsbC1jcmFmdGVkIHBhaXIgb2Ygc3R1ZC1jb3ZlcmVkIGxlYXRoZXIgbGVnZ2luZ3MgbGFiZWxlZCBhcyAoR2dyKSI7aTozO3M6NTU6IlJpbmcgb2Ygd2lzZG9tIFtNYWRlIGJ5OiBOdWFuZV0gbGFiZWxlZCBhcyA2d2lzMWhwci9nZ3IiO2k6NDtzOjU0OiJzaGluaW5nIHJpbmcgY3JhZnRlZCBvdXQgb2YgbW9vbnN0b25lIGxhYmVsZWQgYXMgKEdncikiO2k6NTtzOjUxOiJHcmlteSBncmVhdCBjbG9hayBvZiB0cnVlIHNvcmNlcmVyIGxhYmVsZWQgYXMgfEdncnwiO2k6NjtzOjI5OiJhIGJsYWNrIGhvb2QgbGFiZWxlZCBhcyB8R2dyfCI7aTo3O3M6Mzg6InRoZSB0b21lIG9mIGtub3dsZWRnZSBsYWJlbGVkIGFzIChHZ3IpIjtpOjg7czo1MzoiaGVhdnkgdGFiYXJkIHdpdGggYSBjaGFsaWNlIGVuc2lnbmlhIGxhYmVsZWQgYXMgKEdncikiO2k6OTtzOjQ3OiJkYXJrIGdyZXkgYW5kIHdoaXRlIHBsYWlkIGtpbHQgbGFiZWxlZCBhcyAoR2dyKSI7aToxMDtzOjM4OiJzdHJvbmcgc2FwcGhpcmUgYm9vdHMgbGFiZWxlZCBhcyAoR2dyKSI7aToxMTtzOjI3OiJzdW4gYW11bGV0IGxhYmVsZWQgYXMgKEdncikiO2k6MTI7czo0MDoiQW5jaWVudCBCcmFjZXJzIG9mIFh6dWkgbGFiZWxlZCBhcyAoR2dyKSI7aToxMztzOjQyOiJnbGl0dGVyaW5nIGxlZyBwcm90ZWN0b3JzIGxhYmVsZWQgYXMgKEdncikiO2k6MTQ7czo0OToiYSBicmFjZWxldCBtYWRlIG9mIGdyZWVuIGNyeXN0YWwgbGFiZWxlZCBhcyAoR2dyKSI7aToxNTtzOjQ5OiJhIGJyYWNlbGV0IG1hZGUgb2YgZ3JlZW4gY3J5c3RhbCBsYWJlbGVkIGFzIChHZ3IpIjtpOjE2O3M6NDU6ImEgcmVpbmZvcmNlZCBicm9uemUgYnJhY2VsZXQgbGFiZWxlZCBhcyAoR2dyKSI7aToxNztzOjQyOiJ0aGUgQnJhY2VsZXRzIG9mIERhcmtuZXNzIGxhYmVsZWQgYXMgKEdncikiO2k6MTg7czozNDoiVGlidXJjaW8ncyBhbXVsZXQgbGFiZWxlZCBhcyAoR2dyKSI7aToxOTtzOjQ5OiJuZWNrbGFjZSBtYWRlIG91dCBvZiBzaGFycCBmYW5ncyBsYWJlbGVkIGFzIChHZ3IpIjtpOjIwO3M6NjI6ImEgZ2xpbW1lcmluZyBsZWF0aGVyIGJlbHQgd2l0aCBnZW0gZGVjb3JhdGlvbiBsYWJlbGVkIGFzIChHZ3IpIjtpOjIxO3M6NDE6ImEgaGVhdnkgYmxhY2sgbWV0YWwgcmluZyBsYWJlbGVkIGFzIChHZ3IpIjtpOjIyO3M6NDE6ImEgaGVhdnkgYmxhY2sgbWV0YWwgcmluZyBsYWJlbGVkIGFzIChHZ3IpIjtpOjIzO3M6NDU6IkRlbW9uaWMgUmluZyBvZiBJbnZpc2liaWxpdHkgbGFiZWxlZCBhcyAoR2dyKSI7aToyNDtzOjMxOiJhIHB1cnBsZSBnbG92ZSBsYWJlbGVkIGFzIChHZ3IpIjtpOjI1O3M6MzE6ImEgcHVycGxlIGdsb3ZlIGxhYmVsZWQgYXMgKEdncikiO2k6MjY7czozMDoiYSBncmVlbiBnbG92ZSBsYWJlbGVkIGFzIChHZ3IpIjtpOjI3O3M6MzA6ImEgZ3JlZW4gZ2xvdmUgbGFiZWxlZCBhcyAoR2dyKSI7aToyODtzOjQzOiJhIHBhaXIgb2YgYmxhY2sgYm9vdHMgbGFiZWxlZCBhcyB8R2dyTXVycml8IjtpOjI5O3M6NzI6IkEgYmVhdXRpZnVsIHJvc2FyeSBlbmZvbGRlZCB3aXRoIHdoaXRlIG1pc3QgbGFiZWxlZCBhcyB8R2dyTXVycml8IChob2x5KSI7aTozMDtzOjgyOiJhIHNtYWxsIHJpbmcgYmVhcmluZyB0aGUgZW1ibGVtIG9mIHRoZSBidW5ueSBbTWFkZSBieTogS2lvbWV0XSBsYWJlbGVkIGFzIDZ3aXMyaW50IjtpOjMxO3M6NjE6ImEgdmlhbCBjb250YWluaW5nIHRoZSB0ZWFycyBvZiBPeHRvdGggbGFiZWxlZCBhcyAoR2dyKSAoaG9seSkiO2k6MzI7czo0NDoiQSBsZWF0aGVyIHBvdWNoIGxhYmVsZWQgYXMgdjQgKHF1YXJ0ZXIgZnVsbCkiO2k6MzM7czo0Mzoic2xlZXZlcyBvZiBtb29taW4gZW11bHNpb24gbGFiZWxlZCBhcyAoR2dyKSI7aTozNDtzOjMzOiJhIGdyZWVuIGhlYWRiYW5kIGxhYmVsZWQgYXMgKEdncikiO2k6MzU7czozNDoiQ2FwZSBvZiBLbm93bGVkZ2UgbGFiZWxlZCBhcyAoR2dyKSI7aTozNjtzOjU0OiJUaGUgZ2xlYW1pbmcgYmx1ZSBjb2xsYXIgb2YgQmVuZ2Fsb3JlIGxhYmVsZWQgYXMgKEdncikiO2k6Mzc7czo1MToiZ29sZGVuIGJlbHQgb2YgRmFpciBSaXZlci1EYXVnaHRlciBsYWJlbGVkIGFzIChHZ3IpIjtpOjM4O3M6NDI6ImEgYmxhY2sgY2xvYWsgKGV2aWwgZ2xvdykgbGFiZWxlZCBhcyB8R2dyfCI7aTozOTtzOjM1OiJSaW5nIG9mIHRoZSBNZWR1c2EgbGFiZWxlZCBhcyAoR2dyKSI7aTo0MDtzOjQ0OiJBIGxvdyB3aWRlLWJyaW1tZWQgaGF0IGxhYmVsZWQgYXMgfEdnck11cnJpfCI7aTo0MTtzOjEzOiJhIHN0ZXRob3Njb3BlIjtpOjQyO3M6NjY6ImEgc2hpbW1lcmluZyBibHVlIGJyZWFzdHBsYXRlIG1hZGUgb2YgcXVhcnR6IGxhYmVsZWQgYXMgfEdnck11cnJpfCI7aTo0MztzOjUzOiJhIHBhaXIgb2YgcHVyZSB3aGl0ZSBmbG93aW5nIHNsZWV2ZXMgbGFiZWxlZCBhcyAoR2dyKSI7aTo0NDtzOjQzOiJSZWRmYW5nIEJlYWRzIG9mIElyb24gV2lsbCBsYWJlbGVkIGFzIChHZ3IpIjtpOjQ1O3M6NTk6Ik5vdmEgQXJjYW51bSwgTWVsa2lvcidzIGJvb2sgb2YgbmVjcm9tYW5jeSBsYWJlbGVkIGFzIChHZ3IpIjtpOjQ2O3M6NDQ6ImEgcGFpciBvZiBzaG9ydCBncmVlbiBib290cyBsYWJlbGVkIGFzIChHZ3IpIjt9fQ==" name="data" />
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
87 <input type="hidden" value="2" name="mode" />
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 First, you should provide a list of equipments you wish to manage.
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 Just plain copy &amp; paste of an inventory listing is enough.
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
90 You can also test with pre-defined equipments,
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
91 <input type="submit" value=" Test " /> by clicking the button.
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
92 </form>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 </p>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 <p>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 <b>Stacks of items are not supported, and few other things may cause problems too.</b>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 </p>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 <form action="<? echo $pageIndex; ?>" method="post">
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
98 <p>
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
99 <textarea name="data" cols="100" rows="20"></textarea>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 <input type="hidden" value="1" name="mode" />
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
101 </p>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 <div class="icenter">
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 <input type="submit" value=" Submit " />
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 </div>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 </form>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 <?
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 }
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
108
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
109 /*
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
110 * Parse and validate item
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
111 */
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 else if ($formMode == 1) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 if (isset($_POST["data"])) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 $formData = stripslashes($_POST["data"]);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 $postData = explode("\n", $formData);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 $data = array();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 $ignored = array();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
120 function addItems($num, $desc)
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
121 {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
122 global $data;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
123 for ($i = 0; $i < $num; $i++)
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
124 $data["items"][] = $desc;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
125 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
126
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 foreach ($postData as $line) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 // Trim whitespace
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 $str = trim($line);
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
130 if ($str == "") continue;
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
132 // Strip glows and counters from item "handle"
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
133 if (preg_match("/^(.+?)\s+(<.+? glow>|\(\d+\/\d+\)|\[\d+\/\d+\])$/", $str, $m))
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
134 $str = $m[1];
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
136 // Discard multi-item lines
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
137 if (preg_match("/^(many|two|three|four|five|six|seven|eight|nine|ten)\s+(.+?)( labeled as .+|)$/", $str, $m)) {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
138 if (!isset($fixNumbers[$m[1]])) {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
139 $ignored[$str] = "Unparsed stack of many";
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
140 } else {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
141 $n = $fixNumbers[$m[1]];
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
142 $changed = 0;
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
143 foreach ($fixItemTable as $pat => $rep) {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
144 if ($pat[0] == "*") {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
145 if (substr($pat, 1) == $m[2]) {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
146 $res = $rep;
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
147 $changed = 1;
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
148 }
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
149 } else {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
150 $res = preg_replace("/".$pat."/", $rep, $m[2], -1, &$changed);
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
151 }
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
152 if ($changed > 0) {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
153 addItems($n, $res.$m[3]);
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
154 break;
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
155 }
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
156 }
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
157 if ($changed == 0) {
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
158 $ignored[$str] = "Unsupported item stack";
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
159 }
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
160 }
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
161 } else
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
162 addItems(1, $str);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 if (count($ignored) > 0) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 ?>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 <p>Item data processed. Following lines <b>were not accepted</b>:</p>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 <table>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 <tr><th>Item</th><th>Reason</th></tr>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 <?
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 foreach ($ignored as $name => $reason) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 echo " <tr><td>".htmlentities($name)."</td><td>".htmlentities($reason)."</td></tr>\n";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 }
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
174
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
175 $encData = base64_encode(serialize($data));
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 ?>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 </table>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 <form action="<? echo $pageIndex; ?>" method="post">
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
180 <input type="hidden" value="<? echo $encData ?>" name="data" />
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 <input type="hidden" value="2" name="mode" />
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
182 <?
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
183 // echo "<textarea name=\"data\" cols=\"100\" rows=\"20\">".$encData."</textarea>\n";
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
184 ?>
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
185 <br />
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 <input type="submit" value=" Continue " />
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 </form>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 <?
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 } else
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 $formMode = 3;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 } else {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 $errorMsg = "No item data provided.";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 $errorSet = TRUE;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 }
3
aeb37c6b16fd Fixes, also added integrated test data.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
195 } // formMode == 1
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
197
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
198 /*
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
199 * Unserialize data from previous step
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
200 */
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 if ($formMode == 2) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 if (isset($_POST["data"])) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 $formData = base64_decode($_POST["data"]);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 $data = @unserialize($formData);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 $formMode = 3;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 if ($data === FALSE) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 $errorMsg = "Could not unserialize data, internal error.";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 $errorSet = TRUE;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
213
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
214 /*
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
215 * Interactive editor mode begins here
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
216 */
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
217 if ($data !== FALSE && $formMode == 3) {
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 ?>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 <form id="done" action="<? echo $pageIndex; ?>" method="post">
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
220 <p id="create_buttons">
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
221 <input type="button" value=" Create BatMUD Commands " onclick="createInit('batmud');" />
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
222 <!-- <input type="button" value=" Create TinyFugue Macros " onclick="createInit('tf');" />
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
223 -->
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
224 <input type="button" value=" Create SAVEBLOB " onclick="createInit('save');" />
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 </p>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
226
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
227
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 <table>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 <tr>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
230
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 <td>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 <h2>Items pool</h2>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
233 <? printOptionSelect("curr_items", 10, TRUE); ?>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
234 <table class="buttons">
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
235 <tr>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
236 <td><input type="button" value=" Delete " onclick="deleteItems(this.form);" /></td>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
237 <td><input type="button" value=" Add new " onclick="addItems(this.form);" disabled="disabled" /></td>
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
238 <td style="width: 60%; text-align: right;"><input id="move_button" type="button" value=" Move to container " onclick="moveItems(this.form);" /></td>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
239 </tr>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 </table>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 </td>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
242
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
243 <td id="container_editor">
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
244 <h2>Editing container "<span id="curr_name"></span>" - <span id="curr_info"></span></h2>
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
245 <? printOptionSelect("curr_container", 10, TRUE); ?>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
246 <table class="buttons">
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
247 <tr>
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
248 <td><input type="button" value=" Remove selected " onclick="containerRemoveItems(this.form);" /></td>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
249 </tr>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
250 </table>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 </td>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 </tr>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
253
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 <tr>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 <td>
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
256 <h2>Create / edit a container</h2>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 <?
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
258 printInputField("container_name", "Identifier/name", 15);
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
259 printInputField("container_slots", "Number of slots", 5);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 ?>
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
261 <input type="button" value=" Create " onclick="containerCreate(this.form);" id="create_button" />
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 </td>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
263
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
264 <td id="container_list_editor">
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
265 <h2>Defined containers</h2>
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
266 <? printOptionSelect("container_list", 5, FALSE); ?>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
267 <table class="buttons">
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
268 <tr>
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
269 <td><input type="button" value=" Switch to " onclick="containerEdit(this.form);" /></td>
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
270 <td><input type="button" value=" Delete " onclick="containerDelete(this.form);" /></td>
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
271 <td><input type="button" value=" Edit " onclick="containerEditProps(this.form);" disabled="disabled" /></td>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
272 </tr>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
273 </table>
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 </td>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
275
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 </tr>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 </table>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 </form>
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
279
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
280 <div id="commands">
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
281 <textarea id="command_data" cols="80" rows="10"></textarea>
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
282 <br />
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
283 <input type="button" value=" Close " onclick="viewCommands(false, '');" />
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
284 </div>
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
285
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
286 <div id="options_batmud" class="options">
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
287 <? printInputField("cmd_delim", "Command delimiter", 15, ";"); ?><br />
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
288 <? printInputField("cmd_prefix", "Command name prefix", 15, "mcp"); ?><br />
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
289 <? printInputField("cmd_cmd", "Command", 32, "put \$1 in \$2"); ?> (<b>$1</b> = item, <b>$2</b> = container)<br />
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
290 <input type="checkbox" id="cmd_separate" value="true" />
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
291 <label for="cmd_separate">Create one command for each item, instead of a list.</label><br />
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
292 <input type="checkbox" id="cmd_autoclose" value="true" />
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
293 <label for="cmd_autoclose">Add commands for automatically opening and closing each container.</label><br />
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
294 <br />
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
295 <input type="button" value=" Create " onclick="createCommands('batmud');" />
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
296 </div>
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
297
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
298 <div id="options_tf" class="options">
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
299 <input type="button" value=" Create " onclick="createCommands('tf');" />
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
300 </div>
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
301
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
302
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
303 <div id="status">&nbsp;</div>
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
304
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 <script type="text/javascript">
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 <!--
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
307 var curr_container = null;
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
309 function Container(name, slots, items)
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 this.name = name;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 this.slots = slots;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 this.items = items;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 this.changed = true;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
316 this.getCountByName = function(n) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
317 var cnt = 0;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
318 for (var i = 0; i < this.items.length; i++) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
319 if (this.items[i] == n) cnt++;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
320 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
321 return cnt;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
322 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
323
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 this.getSpace = function() {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 return this.slots - this.items.length;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 this.addItem = function(item) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 this.changed = true;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 return this.items.push(item);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 this.deleteItemById = function(id) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 this.changed = true;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 delete this.items[id];
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 this.flush = function() {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 this.changed = true;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 for (var i = 0; i < this.items.length; i++) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 if (this.items[i] == undefined) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 this.items.splice(i, 1);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 i -= 1;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
348 this.moveItemById = function(container, id) {
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 var item = this.getItemByIndex(id);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 if (item != null) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 this.deleteItemById(id);
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
352 container.addItem(item);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 this.changed = true;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 this.getItemId = function(item) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 return this.items.indexOf(item);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 this.getItemByIndex = function(id) {
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
362 if (id < 0 || id >= this.items.length) return null;
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 return this.items[id];
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 -->
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 <?
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
369 function getContainerObject($name, $slots, $items)
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
371 return "new Container(\"".$name."\", \"".$slots."\", [".getJSArraySegment($items)."])";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 $str = "";
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
375 if (isset($data["containers"])) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
376 foreach ($data["containers"] as $container) {
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 if ($str != "") $str .= ", ";
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
378 $str .= getContainerObject($container["name"], $container["slots"], $container["items"]);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 echo
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
383 "var list_containers = [".$str."];\n".
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
384 "var list_items = ".(isset($data["items"]) ? getContainerObject("items", 10000, $data["items"]) : "null").";\n";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 ?>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 <!-- #kludge --><!--
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 function setHTML(id, str)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 var o = document.getElementById(id);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 if (o != null)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 o.innerHTML = str;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 function setListData(id, list)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 var o = document.getElementById(id);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 o.options.length = 0;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 for (var i = 0; i < list.length; i++) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 o.options[i] = new Option(list[i], i, false, false);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 // Update the form data
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 function updatePage()
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 // List of items
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
409 if (list_items != null && list_items.changed) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
410 list_items.changed = false;
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 setListData("curr_items", list_items.items);
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
412 }
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
414 // List of containers
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
415 var container_list_editor = document.getElementById("container_list_editor");
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
416 if (list_containers.length > 0) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
417 container_list_editor.style.display = "block";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
419 o = document.getElementById("container_list");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 o.options.length = 0;
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
421 for (var i = 0; i < list_containers.length; i++) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
422 o.options[i] = new Option(list_containers[i].name +" (" + list_containers[i].items.length +" of "+ list_containers[i].slots +" items)", i, false);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 } else {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
425 container_list_editor.style.display = "none";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
429 // Update current container
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
430 var container_editor = document.getElementById("container_editor");
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
431 if (curr_container != null) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
432 container_editor.style.display = "block";
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
433 setHTML("curr_name", curr_container.name);
4
563783b8cd22 Show current item amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
434
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
435 setHTML("curr_info", "(" + curr_container.items.length+" / "+curr_container.slots+" items)");
4
563783b8cd22 Show current item amounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
436
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
437 if (curr_container.changed) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
438 curr_container.changed = false;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
439 setListData("curr_container", curr_container.items);
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
440 }
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 } else {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
442 container_editor.style.display = "none";
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 // Output status message
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 function statusMsg(msg)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 var o = document.getElementById("status");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 o.innerHTML = msg;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 // Clear values of a given form
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 function clearForm(f)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 for (var i = 0; i < f.elements.length; i++) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 var e = f.elements[i];
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 if (e.type.toLowerCase() == "text") e.value = "";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
464 // Create a new container, set current container to it
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
465 function containerCreate(f)
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
467 var name = f.elements['container_name'].value;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
468 var slots = parseInt(f.elements['container_slots'].value, 10);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
470 if (isNaN(slots) || slots < 1) {
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
471 statusMsg("Number of slots not set or is invalid.");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 if (name == "") {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
476 statusMsg("Empty container name "+name+".");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 }
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
479
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
480 if (name.match(/[^a-z0-9_]/)) {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
481 statusMsg("Invalid container name, only lower case alphanumerics and underscore are allowed.");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
482 return;
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
483 }
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
485 for (var i = 0; i < list_containers.length; i++) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
486 if (list_containers[i].name == name) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
487 statusMsg("Container with identifier '<b>"+name+"</b>' already exists!");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
492 curr_container = new Container(name, slots, []);
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
493 list_containers.push(curr_container);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 clearForm(f);
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
496 statusMsg("OK, created new container '<b>"+name+"</b>' with <b>"+slots+"</b> slots.");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 updatePage();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
501 function containerCheckSelected(f)
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
502 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
503 var id = f.elements['container_list'].selectedIndex;
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
504
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
505 if (id < 0 || id >= list_containers.length) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
506 statusMsg("Invalid container, internal error!");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
507 return -1;
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
508 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
509
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
510 return {id: id, container: list_containers[id]};
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
511 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
512
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
513
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
514 // Delete a container from container list
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
515 function containerDelete(f)
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
517 var ret = containerCheckSelected(f);
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
518 if (ret.id < 0 || ret.container == null) return;
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
519
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
520 var name = ret.container.name;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
521 var len = ret.container.items.length;
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
522
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
523 var answer = confirm("Really delete selected container '"+name+"' and move "+len+" items back to pool?");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
524 if (!answer) {
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
525 statusMsg("Delete operation cancelled.");
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
526 return;
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
527 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
528
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
529 if (curr_container == ret.container)
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
530 curr_container = null;
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
531
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
532 for (var i = 0; i < len; i++)
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
533 ret.container.moveItemById(list_items, i);
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
534
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
535 list_containers.splice(ret.id, 1);
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
536
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
537 if (len > 0) {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
538 statusMsg("Deleted container '"+name+"', "+len+" items returned to pool.");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
539 } else {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
540 statusMsg("Deleted empty container '"+name+"'.");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
541 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
542 updatePage();
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
543 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
544
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
545
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
546 // Change currently edited container to another
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
547 function containerEdit(f)
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
548 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
549 var ret = containerCheckSelected(f);
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
550 if (ret.id < 0 || ret.container == null) return;
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
551
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
552 curr_container = ret.container;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
553 curr_container.changed = true;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
554 statusMsg("Switched to container '"+ret.container.name+"'.");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 updatePage();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 function getSelectedItems(items)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 var selected = [];
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 if (items != null) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 for (var i = 0; i < items.length; i++)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 if (items[i].selected) selected.push(items[i].value);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 return selected;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 function deleteItems(f)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 var selected = getSelectedItems(f.elements['curr_items']);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 if (selected.length == 0) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 statusMsg("No items selected for deletion.");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 } else {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 var answer = confirm("Really delete selected items?");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 if (!answer) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 statusMsg("Delete operation cancelled.");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 for (var i = 0; i < selected.length; i++)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 list_items.deleteItemById(selected[i]);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 list_items.flush();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 updatePage();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 statusMsg("Deleted "+selected.length+" items.");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 function moveItems(f)
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
596 if (curr_container == null) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
597 statusMsg("No container selected, cannot move items.");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 var selected = getSelectedItems(f.elements['curr_items']);
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 if (selected.length == 0) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 statusMsg("No items selected for deletion.");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 } else {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
607 if (curr_container.getSpace() < selected.length) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
608 statusMsg("Not enough space! "+ selected.length +" items, only "+ curr_container.getSpace() +" slots available!");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 for (var i = 0; i < selected.length; i++)
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
613 list_items.moveItemById(curr_container, selected[i]);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 list_items.flush();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 updatePage();
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
617 statusMsg("Moved " + selected.length + " items to current container.");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
622 function containerRemoveItems(f)
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
624 if (curr_container == null) {
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 statusMsg("Internal error.");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
629 var selected = getSelectedItems(f.elements['curr_container']);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 if (selected.length == 0) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 statusMsg("No items selected for deletion.");
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 return;
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 } else {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 for (var i = 0; i < selected.length; i++)
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
636 curr_container.moveItemById(list_items, selected[i]);
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
638 curr_container.flush();
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 updatePage();
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
640 statusMsg("Removed " + selected.length + " from current container.");
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
644 var edit_modes = ['batmud', 'tf', 'save'];
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
645
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
646 function createInit(mode)
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
647 {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
648 for (i = 0; i < edit_modes.length; i++) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
649 var o = document.getElementById("options_"+edit_modes[i]);
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
650 if (o != null) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
651 o.style.display = (edit_modes[i] == mode) ? "block" : "none";
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
652 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
653 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
654 if (mode == "save")
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
655 createCommands(mode);
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
656 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
657
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
658
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
659 function createCommands(mode)
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
660 {
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
661 if (list_containers.length == 0) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
662 statusMsg("No container configurations defined!");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
663 return;
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
664 }
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
665
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
666
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
667 var str = "";
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
668 for (var i = 0; i < list_containers.length; i++) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
669 var container = list_containers[i];
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
670 var s = "";
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
671 var counts = [];
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
672 var curr = [];
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
673
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
674 for (var n = 0; n < container.items.length; n++) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
675 var cnt = container.getCountByName(container.items[n]);
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
676 counts[container.items[n]] = cnt;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
677 curr[container.items[n]] = 1;
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
678 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
679
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
680 for (var n = 0; n < container.items.length; n++) {
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
681 var item = container.items[n];
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
682 if (mode == "batmud") {
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
683 if (s != "") s += ",";
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
684 s += item;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
685 if (counts[item] > 1) {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
686 s += " " + curr[item];
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
687 curr[item]++;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
688 }
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
689 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
690 }
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
691
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
692 if (mode == "batmud") {
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
693 var opt = document.getElementById("cmd_autoclose").checked;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
694 var delim = document.getElementById("cmd_delim").value;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
695 var prefix = document.getElementById("cmd_prefix").value;
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
696 if (delim == "") delim = ";";
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
697
6
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
698 str += "command "+prefix+container.name+" ";
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
699 if (opt) str += "open "+container.name+delim;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
700 str += "put "+s+" in "+container.name;
2fb901161013 s/Chest/Container/g
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
701 if (opt) str += delim+"close "+container.name;
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
702 str += "\n";
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
703 }
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
704 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
705
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
706 viewCommands(true, str);
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
707 }
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
708
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
709 function viewCommands(state, str)
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
710 {
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
711 var o = document.getElementById("commands");
2
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
712 o.style.display = state ? "block" : "none";
666d475c8f92 Fixes, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
713 var o = document.getElementById("command_data");
1
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
714 o.innerHTML = str;
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
715 }
77d78ef45ed2 Lots of work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
716
0
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717 updatePage();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 -->
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 </script>
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 <?
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 if ($errorSet) {
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 echo "<h2>An error occured</h2>\n".
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 "<p>".$errorMsg."</p>";
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 }
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 printPageFooter();
332b25bb4e36 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 ?>