Brandon Cornejo
5 years ago
commit
b9ef801f77
3 changed files with 338 additions and 0 deletions
@ -0,0 +1,70 @@ |
|||||
|
from flask import Flask, render_template, jsonify, request |
||||
|
|
||||
|
app = Flask(__name__) |
||||
|
|
||||
|
@app.route('/') |
||||
|
def index(): |
||||
|
return render_template('index.html') |
||||
|
|
||||
|
@app.route('/results', methods=['POST']) |
||||
|
def results(): |
||||
|
combinations = calculate_combinations(request.get_json()) |
||||
|
return jsonify(combinations) |
||||
|
|
||||
|
|
||||
|
# Data Methods |
||||
|
def calculate_combinations(equipment, do_print=True): |
||||
|
# name, defense, resistance |
||||
|
eq_headware = equipment["head"] |
||||
|
eq_chestware = equipment["chest"] |
||||
|
eq_legwear = equipment["legs"] |
||||
|
|
||||
|
# Create a list of all possible eq combinations |
||||
|
results = [] |
||||
|
for hw in eq_headware: |
||||
|
print('Headware: {}'.format(hw)) |
||||
|
for cw in eq_chestware: |
||||
|
print('Chestware: {}'.format(cw)) |
||||
|
for lw in eq_legwear: |
||||
|
print('legware: {}'.format(lw)) |
||||
|
result = {} |
||||
|
result["eq"] = [hw[0], cw[0], lw[0]] |
||||
|
result["def"] = hw[1] + cw[1] + lw[1] |
||||
|
result["res"] = hw[2] + cw[2] + lw[2] |
||||
|
results.append(result) |
||||
|
|
||||
|
# Sort the combinations by combined total of def anf res |
||||
|
results.sort(key=lambda i: i["def"] + i["res"]) |
||||
|
|
||||
|
if do_print: |
||||
|
for result in results: |
||||
|
print("{} ({} def {} res) -".format(result["def"] + result["res"], result["def"], result["res"])) |
||||
|
for eq in result["eq"]: |
||||
|
print("\t{}".format(eq)) |
||||
|
|
||||
|
return results |
||||
|
|
||||
|
|
||||
|
""" |
||||
|
eq_headware = [ |
||||
|
["Ljosalfar Hood", 98, 510], |
||||
|
["Kobold Hood", 0, 614], |
||||
|
["Northern Cowl", 584, 130], |
||||
|
["High Fomorian Hood", 487, 112] |
||||
|
] |
||||
|
|
||||
|
eq_chestware = [ |
||||
|
["Ljosalfar Robe", 121, 528], |
||||
|
["High Fomorian Garb", 544, 0], |
||||
|
["Darkest Garb", 514, 169], |
||||
|
["Northern Garb", 535, 119], |
||||
|
["Northern Robe", 486, 108] |
||||
|
] |
||||
|
|
||||
|
eq_legwear = [ |
||||
|
["Northern Boots", 636, 142], |
||||
|
["Terra Boots", 129, 369], |
||||
|
["High Fomorian Boots", 516, 0], |
||||
|
["Ljosalfar Boots", 280, 280] |
||||
|
] |
||||
|
""" |
@ -0,0 +1,7 @@ |
|||||
|
Click==7.0 |
||||
|
Flask==1.1.1 |
||||
|
itsdangerous==1.1.0 |
||||
|
Jinja2==2.11.1 |
||||
|
MarkupSafe==1.1.1 |
||||
|
pkg-resources==0.0.0 |
||||
|
Werkzeug==0.16.1 |
@ -0,0 +1,261 @@ |
|||||
|
<!doctype html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<title>Orna Tools - atr0phy.net</title> |
||||
|
|
||||
|
<meta charset="utf-8"> |
||||
|
<meta name="viewport" contents="width=device-width, initial-scale=1"> |
||||
|
|
||||
|
<!-- <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"> --> |
||||
|
|
||||
|
<!-- UIkit CSS --> |
||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/css/uikit.min.css" /> |
||||
|
|
||||
|
<!-- UIkit JS --> |
||||
|
<script src="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/js/uikit.min.js"></script> |
||||
|
<script src="https://cdn.jsdelivr.net/npm/uikit@3.2.4/dist/js/uikit-icons.min.js"></script> |
||||
|
<script src="https://cdn.jsdelivr.net/combine/npm/tablesort@5.2.0,npm/tablesort@5.2.0/src/sorts/tablesort.number.min.js"></script> |
||||
|
</head> |
||||
|
<body> |
||||
|
<nav class="uk-navbar-container" uk-navbar> |
||||
|
<div class="uk-navbar-center"> |
||||
|
<a href="" class="uk-navbar-item uk-logo">Orna Tools</a> |
||||
|
</div> |
||||
|
</nav> |
||||
|
<div class="uk-container"> |
||||
|
<div id="equipment-container" class="uk-padding-large"> |
||||
|
<ul class="uk-flex-center" uk-tab> |
||||
|
<li class="uk-active"><a href="">Head</a></li> |
||||
|
<li><a href="">Chest</a></li> |
||||
|
<li><a href="">Leg</a></li> |
||||
|
</ul> |
||||
|
<ul class="uk-switcher"> |
||||
|
{% for slot in ["Head", "Chest", "Leg"] %} |
||||
|
<li> |
||||
|
<div class="uk-padding-large uk-padding-remove-vertical"> |
||||
|
<table id="{{ slot | lower }}-table" class="uk-table"> |
||||
|
<caption>{{ slot }} Gear</caption> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th class="uk-table-shrink"></th> |
||||
|
<th class="uk-table-expand">Item Name</th> |
||||
|
<th class="uk-table-shrink">Defense</th> |
||||
|
<th class="uk-table-shrink">Resistance</th> |
||||
|
<th class="uk-table-shring"></th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
<tr> |
||||
|
<td>1</td> |
||||
|
<td><input type="text" class="uk-input"/></td> |
||||
|
<td><input type="text" class="uk-input"/></td> |
||||
|
<td><input type="text" class="uk-input"/></td> |
||||
|
<td><a class="uk-icon-button del-row-button" uk-icon="icon:minus-circle;ratio:1"></a></td> |
||||
|
</tr> |
||||
|
</tbody> |
||||
|
</table> |
||||
|
<div class="uk-text-center"> |
||||
|
<a id="{{ slot | lower }}-button" class="uk-icon-button add-row-button" uk-icon="icon:plus-circle;ratio:2"></a> |
||||
|
</div> |
||||
|
</div> |
||||
|
</li> |
||||
|
{% endfor %} |
||||
|
</ul> |
||||
|
</div> |
||||
|
<div class="uk-text-center uk-margin-bottom"> |
||||
|
<button id="calculate-button" class="uk-button uk-button-primary">Calculate</button> |
||||
|
</div> |
||||
|
|
||||
|
<div id="result-panel" class="uk-section"> |
||||
|
<hr class="uk-divider-icon" /> |
||||
|
<table id="results-table" class="uk-table uk-table-divider uk-table-striped uk-table-hover"> |
||||
|
<thead> |
||||
|
<th>Total</th> |
||||
|
<th>Defense</th> |
||||
|
<th>Resistance</th> |
||||
|
<th class="uk-table-expand">Head</th> |
||||
|
<th class="uk-table-expand">Chest</th> |
||||
|
<th class="uk-table-expand">Legs</th> |
||||
|
</thead> |
||||
|
<tbody></tbody> |
||||
|
</table> |
||||
|
</div> |
||||
|
</div> |
||||
|
</body> |
||||
|
<script> |
||||
|
// Support adding rows to the equipment tables |
||||
|
function addEquipmentTableRow() { |
||||
|
let input_element = document.createElement("input"); |
||||
|
input_element.className="uk-input"; |
||||
|
input_element.type = "text"; |
||||
|
|
||||
|
// Create the delete button |
||||
|
let delete_button = document.createElement("a"); |
||||
|
delete_button.className="uk-icon-button del-row-button"; |
||||
|
delete_button.setAttribute("uk-icon", "icon:minus-circle;ratio:1"); |
||||
|
delete_button.addEventListener("click", deleteEquipmentTableRow, false); |
||||
|
|
||||
|
let tbody = this.parentElement.previousElementSibling.children[2]; |
||||
|
let new_row = tbody.insertRow(-1); |
||||
|
|
||||
|
// Append all of the child cells needed |
||||
|
new_row.insertCell(0).appendChild(delete_button); |
||||
|
new_row.insertCell(0).appendChild(input_element.cloneNode()); |
||||
|
new_row.insertCell(0).appendChild(input_element.cloneNode()); |
||||
|
new_row.insertCell(0).appendChild(input_element.cloneNode()); |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(tbody.children.length)) |
||||
|
} |
||||
|
|
||||
|
// Support deleting rows from the equipment table |
||||
|
function deleteEquipmentTableRow() { |
||||
|
this.parentElement.parentElement.remove(); |
||||
|
} |
||||
|
|
||||
|
// Process results and display table |
||||
|
function processEquipmentResults(results) { |
||||
|
var results_tbody = document.querySelector("table#results-table > tbody"); |
||||
|
for(result of results) { |
||||
|
let new_row = results_tbody.insertRow(-1); |
||||
|
|
||||
|
// Append all of the child cells |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][2])); |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][1])); |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(result['eq'][0])); |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(result['res'])); |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(result['def'])); |
||||
|
new_row.insertCell(0).appendChild(document.createTextNode(result['def'] + result['res'])); |
||||
|
} |
||||
|
|
||||
|
table_sort.refresh(); |
||||
|
} |
||||
|
|
||||
|
// Send data to backend |
||||
|
function calculateEquipment() { |
||||
|
let data = gatherEquipmentData(); |
||||
|
|
||||
|
// Clear out existing table rows |
||||
|
for(let row of document.querySelectorAll("table#results-table > tbody > tr")) { |
||||
|
row.remove(); |
||||
|
} |
||||
|
|
||||
|
fetch('/results', { |
||||
|
method: 'POST', |
||||
|
headers: { 'Content-Type': 'application/json' }, |
||||
|
body: JSON.stringify(data) |
||||
|
}).then((response) => response.json()).then((data) => { |
||||
|
processEquipmentResults(data) |
||||
|
}).catch((error) => { |
||||
|
console.log(error); |
||||
|
alert("There was a problem..."); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function gatherEquipmentData() { |
||||
|
var eq_head = [], eq_chest = [], eq_legs = []; |
||||
|
|
||||
|
// Gather head gear |
||||
|
for(let row of document.querySelectorAll("table#head-table > tbody > tr")) { |
||||
|
eq_head.push([ |
||||
|
row.children[1].firstChild.value, |
||||
|
parseInt(row.children[2].firstChild.value) || 0, |
||||
|
parseInt(row.children[3].firstChild.value) || 0 |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
// Gather chest gear |
||||
|
for(let row of document.querySelectorAll("table#chest-table > tbody > tr")) { |
||||
|
eq_chest.push([ |
||||
|
row.children[1].firstChild.value, |
||||
|
parseInt(row.children[2].firstChild.value) || 0, |
||||
|
parseInt(row.children[3].firstChild.value) || 0 |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
// Gather leg gear |
||||
|
for(let row of document.querySelectorAll("table#leg-table > tbody > tr")) { |
||||
|
eq_legs.push([ |
||||
|
row.children[1].firstChild.value, |
||||
|
parseInt(row.children[2].firstChild.value) || 0, |
||||
|
parseInt(row.children[3].firstChild.value) || 0 |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
let data = { |
||||
|
"head": eq_head, |
||||
|
"chest": eq_chest, |
||||
|
"legs": eq_legs |
||||
|
}; |
||||
|
|
||||
|
return data; |
||||
|
} |
||||
|
|
||||
|
// Add event listeners to our table buttons |
||||
|
const add_row_buttons = document.querySelectorAll("a.add-row-button"); |
||||
|
for(let button of add_row_buttons) { |
||||
|
button.addEventListener("click", addEquipmentTableRow, false); |
||||
|
} |
||||
|
const del_row_buttons = document.querySelectorAll("a.del-row-button"); |
||||
|
for(let button of del_row_buttons) { |
||||
|
button.addEventListener("click", deleteEquipmentTableRow, false); |
||||
|
} |
||||
|
|
||||
|
// Add event listener to Calculate button, call backend |
||||
|
document.querySelector("#calculate-button").addEventListener("click", calculateEquipment, false); |
||||
|
|
||||
|
// Enable sorting for our results table |
||||
|
var table_sort = new Tablesort(document.querySelector("table#results-table")); |
||||
|
</script> |
||||
|
<style type="text/css"> |
||||
|
table:not(#results-table) > tbody > tr > td:first-child { |
||||
|
color: #999; |
||||
|
} |
||||
|
|
||||
|
div > a.add-row-button { |
||||
|
color: #32d296; |
||||
|
} |
||||
|
|
||||
|
table a.del-row-button { |
||||
|
color: #f0506e; |
||||
|
} |
||||
|
|
||||
|
table#results-table > tbody > tr > td:first-child { |
||||
|
font-weight: bold; |
||||
|
color: #6c9f12; |
||||
|
} |
||||
|
|
||||
|
/* Result Table from Tablesort.css */ |
||||
|
th:not(.no-sort) { |
||||
|
cursor: pointer; |
||||
|
} |
||||
|
|
||||
|
th[role=columnheader]:not(.no-sort):after { |
||||
|
content: ''; |
||||
|
float: right; |
||||
|
margin-top: 7px; |
||||
|
border-width: 0 4px 4px; |
||||
|
border-style: solid; |
||||
|
border-color: #404040 transparent; |
||||
|
visibility: hidden; |
||||
|
opacity: 0; |
||||
|
-ms-user-select: none; |
||||
|
-webkit-user-select: none; |
||||
|
-moz-user-select: none; |
||||
|
user-select: none; |
||||
|
} |
||||
|
|
||||
|
th[aria-sort=ascending]:not(.no-sort):after { |
||||
|
border-bottom: none; |
||||
|
border-width: 4px 4px 0; |
||||
|
} |
||||
|
|
||||
|
th[aria-sort]:not(.no-sort):after { |
||||
|
visibility: visible; |
||||
|
opacity: 0.4; |
||||
|
} |
||||
|
|
||||
|
th[role=columnheader]:not(.no-sort):hover:after { |
||||
|
visibility: visible; |
||||
|
opacity: 1; |
||||
|
} |
||||
|
</style> |
||||
|
</html> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue