add a matrix dump endpoint, and a page to display all the matrices
This commit is contained in:
		
							parent
							
								
									2d4ce38a20
								
							
						
					
					
						commit
						ae251bf830
					
				
							
								
								
									
										24
									
								
								app/app.py
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								app/app.py
									
									
									
									
									
								
							@ -4,14 +4,18 @@ from flask import Flask
 | 
			
		||||
from flask_cors import CORS
 | 
			
		||||
from flask_restx import Api, Resource
 | 
			
		||||
 | 
			
		||||
from app.functions.role_physical_attack import roll_physical_attack
 | 
			
		||||
from .functions.roll_dices import roll_dices
 | 
			
		||||
from .functions.role_physical_attack import roll_physical_attack
 | 
			
		||||
from .functions.roll_mental_attack import roll_mental_attack
 | 
			
		||||
from .functions.build_character_sheet import build_character_sheet
 | 
			
		||||
from .functions.roll_ability_scores import roll_ability_scores
 | 
			
		||||
from .functions.roll_ability_check import roll_ability_check
 | 
			
		||||
from .functions.roll_dices import roll_dices
 | 
			
		||||
from .functions.roll_encounter import roll_encounter
 | 
			
		||||
from .functions.roll_mental_attack import roll_mental_attack
 | 
			
		||||
from .functions.roll_mutations import roll_mutations
 | 
			
		||||
 | 
			
		||||
from .tables.physattack import AttackerWeaponClassMatrix, AttackerHitDiceMatrix
 | 
			
		||||
from .tables.mentattack import MentalAttackMatrix
 | 
			
		||||
 | 
			
		||||
from .models.models import dice_model, ability_model, hp_model, character_model, encounter_model, ma_model, \
 | 
			
		||||
    mutation_model, check_model, pa_model
 | 
			
		||||
from .schemas.schemas import DiceSchema, CharacterSchema, EncounterSchema, MentalAttackSchema, AbilitySchema, \
 | 
			
		||||
@ -215,5 +219,19 @@ class GenerateCharacter(Resource):
 | 
			
		||||
        return build_character_sheet(chartype), 200
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@api.route('/matrices/dump', methods=['GET'])
 | 
			
		||||
class DumpMatrices(Resource):
 | 
			
		||||
    def get(self):
 | 
			
		||||
        awc_table = AttackerWeaponClassMatrix().get_matrix().to_json(orient='index')
 | 
			
		||||
        ahd_table = AttackerHitDiceMatrix().get_matrix().to_json(orient='index')
 | 
			
		||||
        mat_table = MentalAttackMatrix().get_matrix().to_json(orient='index')
 | 
			
		||||
 | 
			
		||||
        return {
 | 
			
		||||
            "Weapon Attack Table": awc_table,
 | 
			
		||||
            "Non-Weapon Attack Table": ahd_table,
 | 
			
		||||
            "Mental Attack Table": mat_table
 | 
			
		||||
        }, 200
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    app.run()
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										98
									
								
								web/display_tables.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								web/display_tables.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,98 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
    <title>Table View</title>
 | 
			
		||||
    <style>
 | 
			
		||||
        table {
 | 
			
		||||
            border-collapse: collapse;
 | 
			
		||||
            width: 100%;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        th, td {
 | 
			
		||||
            text-align: left;
 | 
			
		||||
            padding: 8px;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        tr:nth-child(even){background-color: #f2f2f2}
 | 
			
		||||
    </style>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
    <table id="yield-table">
 | 
			
		||||
        <thead></thead>
 | 
			
		||||
        <tbody></tbody>
 | 
			
		||||
    </table>
 | 
			
		||||
 | 
			
		||||
    <script>
 | 
			
		||||
 | 
			
		||||
        function createTable(data) {
 | 
			
		||||
            const table = document.createElement('table');
 | 
			
		||||
 | 
			
		||||
            // Get all row and column indexes
 | 
			
		||||
            const colIndexes = Object.keys(data[Object.keys(data)[0]]);
 | 
			
		||||
            const rowIndexes = Object.keys(data);
 | 
			
		||||
 | 
			
		||||
            const thead = document.createElement('thead');
 | 
			
		||||
            const hRow = document.createElement('tr');
 | 
			
		||||
 | 
			
		||||
            // Empty cell in the top-left corner
 | 
			
		||||
            hRow.appendChild(document.createElement('th'));
 | 
			
		||||
 | 
			
		||||
            colIndexes.forEach(colIndex => {
 | 
			
		||||
                const cell = document.createElement('th');
 | 
			
		||||
                cell.textContent = colIndex;
 | 
			
		||||
                hRow.appendChild(cell);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            thead.appendChild(hRow);
 | 
			
		||||
            table.appendChild(thead);
 | 
			
		||||
 | 
			
		||||
            const tbody = document.createElement('tbody');
 | 
			
		||||
 | 
			
		||||
            rowIndexes.forEach(rowIndex => {
 | 
			
		||||
                const tRow = document.createElement('tr');
 | 
			
		||||
 | 
			
		||||
                const rowHeader = document.createElement('th');
 | 
			
		||||
                rowHeader.textContent = rowIndex;
 | 
			
		||||
                tRow.appendChild(rowHeader);
 | 
			
		||||
 | 
			
		||||
                colIndexes.forEach(colIndex => {
 | 
			
		||||
                    const cell = document.createElement('td');
 | 
			
		||||
                    cell.textContent = data[rowIndex][colIndex];
 | 
			
		||||
                    tRow.appendChild(cell);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                tbody.appendChild(tRow);
 | 
			
		||||
            });
 | 
			
		||||
            table.appendChild(tbody);
 | 
			
		||||
 | 
			
		||||
            return table;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        function parseAndRenderData(data) {
 | 
			
		||||
            for (const [tableName, tableData] of Object.entries(data)) {
 | 
			
		||||
                // Parse JSON into object
 | 
			
		||||
                const parsedData = JSON.parse(tableData);
 | 
			
		||||
 | 
			
		||||
                const tableTitle = document.createElement('H2');
 | 
			
		||||
                tableTitle.innerHTML = tableName;
 | 
			
		||||
                document.body.appendChild(tableTitle);
 | 
			
		||||
 | 
			
		||||
                // Create table and header
 | 
			
		||||
                const table = createTable(parsedData);
 | 
			
		||||
 | 
			
		||||
                // Append table to the body of the HTML
 | 
			
		||||
                document.body.appendChild(table);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        document.addEventListener('DOMContentLoaded', function () {
 | 
			
		||||
            fetch('https://gammaworld.gmgauthier.com/matrices/dump')
 | 
			
		||||
                .then(response => response.json())
 | 
			
		||||
                .then(data => {
 | 
			
		||||
                    parseAndRenderData(data)
 | 
			
		||||
                });
 | 
			
		||||
        });
 | 
			
		||||
    </script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
@ -21,6 +21,7 @@
 | 
			
		||||
    <button id="physicalattack">Physical Attack!</button>
 | 
			
		||||
    <button id="mentalattack">Mental Attack!</button>
 | 
			
		||||
    <button id="chargen">Characters</button>
 | 
			
		||||
    <button id="tables">Show Tables</button>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<hr/>
 | 
			
		||||
@ -30,6 +31,10 @@
 | 
			
		||||
    document.addEventListener('DOMContentLoaded', function () {
 | 
			
		||||
        loadContent("intro.html");
 | 
			
		||||
 | 
			
		||||
        document.getElementById("tables").addEventListener("click", function () {
 | 
			
		||||
            loadContent("display_tables.html?t=" + new Date().getTime());
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        document.getElementById("dieroller").addEventListener("click", function () {
 | 
			
		||||
            loadContent("rolldice.html?t=" + new Date().getTime());
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user