Browse Source

Update readme with URL

master
Brandon Cornejo 7 months ago
parent
commit
2681090f5e
3 changed files with 31 additions and 79 deletions
  1. 4
    0
      README.md
  2. 0
    70
      orna-tools.py
  3. 27
    9
      templates/index.html

+ 4
- 0
README.md View File

@@ -0,0 +1,4 @@
1
+# OrnaRPG Tools
2
+
3
+Equipment combination toolkit
4
+https://orna.atr0phy.net

+ 0
- 70
orna-tools.py View File

@@ -1,70 +0,0 @@
1
-from flask import Flask, render_template, jsonify, request
2
-
3
-app = Flask(__name__)
4
-
5
-@app.route('/')
6
-def index():
7
-    return render_template('index.html')
8
-
9
-@app.route('/results', methods=['POST'])
10
-def results():
11
-    combinations = calculate_combinations(request.get_json())
12
-    return jsonify(combinations)
13
-
14
-
15
-# Data Methods
16
-def calculate_combinations(equipment, do_print=True):
17
-    # name, defense, resistance
18
-    eq_headware = equipment["head"]
19
-    eq_chestware = equipment["chest"]
20
-    eq_legwear = equipment["legs"]
21
-
22
-    # Create a list of all possible eq combinations
23
-    results = []
24
-    for hw in eq_headware:
25
-        print('Headware: {}'.format(hw))
26
-        for cw in eq_chestware:
27
-            print('Chestware: {}'.format(cw))
28
-            for lw in eq_legwear:
29
-                print('legware: {}'.format(lw))
30
-                result = {}
31
-                result["eq"] = [hw[0], cw[0], lw[0]]
32
-                result["def"] = hw[1] + cw[1] + lw[1]
33
-                result["res"] = hw[2] + cw[2] + lw[2]
34
-                results.append(result)
35
-
36
-    # Sort the combinations by combined total of def anf res
37
-    results.sort(key=lambda i: i["def"] + i["res"])
38
-
39
-    if do_print:
40
-        for result in results:
41
-            print("{} ({} def {} res) -".format(result["def"] + result["res"], result["def"], result["res"]))
42
-            for eq in result["eq"]:
43
-                print("\t{}".format(eq))
44
-
45
-    return results
46
-
47
-
48
-"""
49
-eq_headware = [
50
-    ["Ljosalfar Hood", 98, 510],
51
-    ["Kobold Hood", 0, 614],
52
-    ["Northern Cowl", 584, 130],
53
-    ["High Fomorian Hood", 487, 112]
54
-]
55
-
56
-eq_chestware = [
57
-    ["Ljosalfar Robe", 121, 528],
58
-    ["High Fomorian Garb", 544, 0],
59
-    ["Darkest Garb", 514, 169],
60
-    ["Northern Garb", 535, 119],
61
-    ["Northern Robe", 486, 108]
62
-]
63
-
64
-eq_legwear = [
65
-    ["Northern Boots", 636, 142],
66
-    ["Terra Boots", 129, 369],
67
-    ["High Fomorian Boots", 516, 0],
68
-    ["Ljosalfar Boots", 280, 280]
69
-]
70
-"""

+ 27
- 9
templates/index.html View File

@@ -24,13 +24,13 @@
24 24
         </nav>
25 25
         <div class="uk-container">
26 26
             <div id="help-container" class="uk-padding-large uk-text-center uk-text-muted uk-margin-large-left uk-margin-large-right">
27
-                <div>Use the three tabs to input your options for each equipment slot (head/chest/leg). Click the calculate button to populate a table with possible combinations. Click on the column headers to sort results. Use the green + to input additional items.</div>
27
+                <div>Use the three tabs to input your options for each equipment slot (head/chest/leg). Click the calculate button to populate a table with possible combinations. Click on the column headers to sort results.<br/><br/><strong>Ctrl+Enter</strong> adds a new row to existing table, or use the green <strong>+</strong> to input additional items.</div>
28 28
             </div>
29 29
             <div id="equipment-container" class="uk-padding-large">
30 30
                 <ul class="uk-flex-center" uk-tab>
31
-                    <li class="uk-active"><a href="">Head</a></li>
32
-                    <li><a href="">Chest</a></li>
33
-                    <li><a href="">Leg</a></li>
31
+                    <li class="uk-active" tbl="head-table"><a href="">Head</a></li>
32
+                    <li tbl="chest-table"><a href="">Chest</a></li>
33
+                    <li tbl="leg-table"><a href="">Leg</a></li>
34 34
                 </ul>
35 35
                 <ul class="uk-switcher">
36 36
                     {% for slot in ["Head", "Chest", "Leg"] %}
@@ -50,9 +50,9 @@
50 50
                                     <tbody>
51 51
                                         <tr>
52 52
                                             <td>1</td>
53
-                                            <td><input type="text" class="uk-input"/></td>
54
-                                            <td><input type="text" class="uk-input"/></td>
55
-                                            <td><input type="text" class="uk-input"/></td>
53
+                                            <td><input type="text" class="uk-input" autocomplete="off"/></td>
54
+                                            <td><input type="text" class="uk-input" autocomplete="off"/></td>
55
+                                            <td><input type="text" class="uk-input" autocomplete="off"/></td>
56 56
                                             <td><a class="uk-icon-button del-row-button" uk-icon="icon:minus-circle;ratio:1"></a></td>
57 57
                                         </tr>
58 58
                                     </tbody>
@@ -97,7 +97,7 @@
97 97
     </body>
98 98
     <script>
99 99
         // Support adding rows to the equipment tables
100
-        function addEquipmentTableRow() {
100
+        function addEquipmentTableRow(findByQuery=false) {
101 101
             let input_element = document.createElement("input");
102 102
             input_element.className="uk-input";
103 103
             input_element.type = "text";
@@ -108,7 +108,8 @@
108 108
             delete_button.setAttribute("uk-icon", "icon:minus-circle;ratio:1");
109 109
             delete_button.addEventListener("click", deleteEquipmentTableRow, false);
110 110
 
111
-            let tbody = this.parentElement.previousElementSibling.children[2];
111
+            // If called manually, find specific table, otherwise determine based on event element
112
+            let tbody = findByQuery ? document.querySelector(findByQuery) : this.parentElement.previousElementSibling.children[2];
112 113
             let new_row = tbody.insertRow(-1);
113 114
 
114 115
             // Append all of the child cells needed
@@ -117,6 +118,11 @@
117 118
             new_row.insertCell(0).appendChild(input_element.cloneNode());
118 119
             new_row.insertCell(0).appendChild(input_element.cloneNode());
119 120
             new_row.insertCell(0).appendChild(document.createTextNode(tbody.children.length))
121
+
122
+            if(findByQuery) {
123
+                // If this was a hotkey, then focus the new field
124
+                new_row.children[1].firstChild.focus();
125
+            }
120 126
         }
121 127
 
122 128
         // Support deleting rows from the equipment table
@@ -224,6 +230,7 @@
224 230
                 let input_element = document.createElement("input");
225 231
                 input_element.className="uk-input";
226 232
                 input_element.type = "text";
233
+                input_element.autocomplete = "off";
227 234
 
228 235
                 // Create the delete button
229 236
                 let delete_button = document.createElement("a");
@@ -271,6 +278,14 @@
271 278
             }
272 279
         }
273 280
 
281
+        function listenForHotkeys(e) {
282
+            if(e.ctrlKey && e.which == 13) {
283
+                // Determine the active tab
284
+                let tbl_id = "table#" + document.querySelector(".uk-active").getAttribute("tbl") + " > tbody";
285
+                addEquipmentTableRow(tbl_id);
286
+            }
287
+        }
288
+
274 289
         // Add event listeners to our table buttons
275 290
         const add_row_buttons = document.querySelectorAll("a.add-row-button");
276 291
         for(let button of add_row_buttons) {
@@ -288,6 +303,9 @@
288 303
         // Enable sorting for our results table
289 304
         var table_sort = new Tablesort(document.querySelector("table#results-table"), {descending: true});
290 305
 
306
+        // Configure keyboard hotkeys
307
+        document.onkeyup = listenForHotkeys;
308
+
291 309
         // Load any existing data from LocalStorage
292 310
         loadExistingData();
293 311
     </script>

Loading…
Cancel
Save