first commit

This commit is contained in:
MeowcaTheoRange 2022-06-18 17:01:43 -05:00
commit c7fb4bc50e
4 changed files with 436 additions and 0 deletions

BIN
assets/ProFontWindows.ttf Normal file

Binary file not shown.

64
index.html Normal file
View file

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dice Tool</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
<body>
<div class="headerBar">
<div style="float: left; text-align: left;">
Dice Tool
</div>
<div style="float: right; text-align: right;">
<button class="material-icons" onclick="rollAllDie(cont)">shuffle</button>
<button class="material-icons" onclick="if (confirm('Are you sure you want to remove everything?')) $('.content').find('.die').remove()">cancel</button>
</div>
</div>
<div class="fab">
<button class="material-icons" title="Add Dice" onclick="addDie(cont);">add_circle</button>
<button class="material-icons" title="Add Counter" onclick="addDie(cont, 1, 'Counter', true);">pin</button>
<button class="material-icons" title="Add Bag" onclick="addDieBag(cont);">create_new_folder</button>
</div>
<div class="content dropHere" ondrop="drop(event)" ondragover="allowDrop(event)">
<div>
</div>
</div>
<templates>
<template id="dieUI">
<div class="die rollable{IS_COUNTER}" id="{RAND_ID}" draggable="true" ondragstart="drag(event)">
<div>
<span class="material-icons icon ident">casino</span><input class="title" placeholder="Name" type="text" value="{TITLE_DIE}" />
<button class="material-icons icon indi neg" onclick="tp(this).remove()">delete</button><br />
<div class="hideIfCounter"><button class="material-icons icon indi pos" title="Roll die" onclick="rollDie(ht(tpp(this)))">shuffle</button></div>
</div>
<div style="text-align: right;">
<button class="material-icons icon" onclick="changeVal(ht($(this)), -1)">remove</button>
<button class="material-icons icon" onclick="changeVal(ht($(this)), 1)">add</button>
<span class="hideIfCounter"><button class="material-icons icon" title="Cut die to value" onclick="cutVal(ht(tp(this)))">content_cut</button></span><br />
<span><h2 class="die-value">{DIE_VALUE}</h2><span class="hideIfCounter"> / <input class="die-sides" type="number" min="1" max="10000" value="{DIE_SIDES}" /></span></span>
</div>
</div>
</template>
<template id="dieBagUI">
<div class="die bag" id="{RAND_ID}" draggable="true" ondragstart="drag(event)">
<div>
<span class="material-icons icon ident">folder</span><input class="title" placeholder="Name" type="text" value="{TITLE_DIE}" />
<button class="material-icons icon indi neg" onclick="if (confirm('Are you sure you want to remove this bag?')) tp(this).remove()">delete</button><br />
<button class="material-icons icon indi pos" title="Roll all dies inside" onclick="rollAllDie(ht(tp(this)))">shuffle</button>
<button class="material-icons icon indi pos" title="Add Dice" onclick="addDie(tp(this).find('.dropHere').get(0))">add_circle</button>
<button class="material-icons icon indi pos" title="Add Counter" onclick="addDie(tp(this).find('.dropHere').get(0), 1, 'Counter', true)">pin</button>
<button class="material-icons icon indi pos" title="Add Bag" onclick="addDieBag(tp(this).find('.dropHere').get(0))">create_new_folder</button>
</div>
<div class="dropHere"></div>
</div>
</template>
</templates>
<script src="script.js"></script>
</body>
</html>

65
script.js Normal file
View file

@ -0,0 +1,65 @@
var cont = document.querySelector(".content > div");
var dieTemp = document.querySelector("template#dieUI");
var dieBagTemp = document.querySelector("template#dieBagUI");
var ids = {
die: 0,
bag: 0
};
function addDie(ctx, int, name, count) {
ctx.innerHTML += dieTemp.innerHTML
.replace("{RAND_ID}", "die" + ids.die)
.replace("{TITLE_DIE}", name ?? "")
.replace("{DIE_SIDES}", int ?? "6")
.replace("{IS_COUNTER}", count ? " counter" : "")
.replace("{DIE_VALUE}", Math.round(Math.random() * ((int ?? 6) - 1)) + 1);
ids.die++;
}
function addDieBag(ctx) {
ctx.innerHTML += dieBagTemp.innerHTML
.replace("{RAND_ID}", "dieBag" + ids.bag)
.replace("{TITLE_DIE}", "");
ids.bag++;
}
function rollDie(thisObj) {
var val = thisObj.querySelector('.die-value');
var sides = thisObj.querySelector('.die-sides');
val.innerHTML = Math.round(Math.random() * (sides.value - 1)) + 1;
}
function rollAllDie(ctx) {
var allDies = ctx.querySelectorAll(".rollable");
console.log(allDies, ctx);
allDies.forEach((v) => {
rollDie(v);
})
}
function cutVal(thisObj) {
var val = thisObj.parentElement.querySelector('.die-value');
var sides = thisObj.parentElement.querySelector('.die-sides');
sides.value = val.innerHTML;
}
function changeVal(thisObj, int) {
var val = thisObj.parentElement.querySelector('.die-value');
val.innerHTML = parseInt(val.innerHTML) + int;
}
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("element", ev.target.id);
}
function drop(ev) {
if (!ev.target.classList.contains("dropHere")) return;
ev.preventDefault();
var data = ev.dataTransfer.getData("element");
ev.target.appendChild(document.getElementById(data));
}
var tp = (t) => {return $(t).parent().parent()};
var tpp = (t) => {return $(t).parent().parent().parent()};
var ht = (t) => {return t.get(0)};

307
style.css Normal file
View file

@ -0,0 +1,307 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap');
@font-face {
font-family: 'PFW';
src: url('assets/ProFontWindows.ttf');
}
:root {
--mainColor: #f80;
--mainColorThemed: #fdb;
--mainColorThemedLight: #fed;
--mainFG: #000;
--mainFGDark: #FFF;
--mainFGTP: #0002;
--mainFGDarkTP: #FFF2;
--mainFGTP4: #0008;
--mainFGDarkTP4: #FFF8;
--negColor: #f00;
--negColorThemed: #fbb;
--negColorThemedLight: #fdd;
--posColor: #f80;
--posColorThemed: #ffd0a0;
--material-outline-boxshadow: #0004 0 0 4px;
--material-outline-border: none;
}
* {
font-family: 'PFW', 'Roboto', 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
transition: background-color 0.25s;
}
@media (prefers-color-scheme: dark) {
:root {
--mainColorThemed: #840;
--mainColorThemedLight: #420;
--mainFG: #FFF;
--mainFGDark: #000;
--mainFGTP: #FFF2;
--mainFGDarkTP: #0002;
--mainFGTP4: #FFF8;
--mainFGDarkTP4: #0008;
--negColorThemed: #800;
--negColorThemedLight: #400;
--posColorThemed: #840;
--posColorThemedLight: #630;
--material-outline-boxshadow: none;
--material-outline-border: var(--mainFGTP) 1px solid;
}
}
body {padding:0;margin:0;background-color:var(--mainColorThemedLight);}
.headerBar {
width: 100%;
height: 56px;
z-index: 9;
display: inline-grid;
grid-template-columns: auto auto;
grid-template-rows: 40px;
position: fixed;
-webkit-user-select: none;
user-select: none;
top: 0;
background-color: var(--mainColorThemed);
box-shadow: var(--material-outline-boxshadow);
border-bottom: var(--material-outline-border);
line-height: 40px;
color: var(--mainFG);
font-size: 24px;
font-weight: bold;
padding: 8px 16px;
box-sizing: border-box;
transition: box-shadow 0.25s, background-color 0.25s;
}
.fab {
position: fixed;
z-index: 9;
background-color: var(--mainColorThemed);
border-radius: 64px;
height: 64px;
width: 192px;
right: 32px;
bottom: 32px;
display: grid;
overflow: hidden;
user-select: none;
grid-template-columns: auto auto auto;
box-shadow: #0004 0 0 4px 0;
}
.fab button {
border: none;
background-color: transparent;
color: var(--mainFG);
font-size: 32px;
}
.fab button:hover {
background-color: var(--mainFGTP);
}
.fab button:active {
transition: none;
background-color: var(--mainColor);
}
.headerBar button {
height: 40px;
background-color: transparent;
padding: 4px; margin: 0;
margin-left: 8px;
color: var(--mainFG);
border: none;
border-radius: 40px;
transition: background 0.25s;
}
.headerBar button:hover {
background-color: var(--mainFGTP);
}
.content {
background-color: var(--mainColorThemedLight);
color: var(--mainFG);
height: calc(100vh - 56px);
margin-top: 56px;
overflow-y: auto;
box-sizing: border-box;
padding: 0 64px;
padding-bottom: 64px;
}
templates, template {
display: none;
}
div.die {
width: 100%;
border: var(--material-outline-border);
box-shadow: var(--material-outline-boxshadow);
color: var(--mainFG);
margin: 16px 0;
border-radius: 8px;
padding: 16px;
padding-bottom: 8px;
box-sizing: border-box;
display: grid;
grid-template-columns: auto auto;
animation-name: horizontal-shaking;
animation-duration: 0.25s;
}
.counter .hideIfCounter {
display: none;
}
div.bag {
grid-template-columns: auto;
grid-template-rows: auto auto;
height: max-content;
}
div.die > div {
user-select: none;
}
div.bag > div.dropHere {
border: var(--mainFGTP) 1px solid;
border-radius: 4px;
padding: 16px;
padding-bottom: 64px;
}
div.bag > div.dropHere:empty {
padding: 32px;
}
div.die h2 {
padding: 0; margin: 0;
display: inline-block;
}
div.die input {
border-radius: 4px;
padding: 4px;
margin: 0;
font-size: 16px;
margin-bottom: 8px;
background-color: var(--mainFGDarkTP4);
border: 1px solid var(--mainFGTP);
color: var(--mainFG);
outline: none;
transition: border 0.25s, border-radius 0.25s, background-color 0.25s;
vertical-align: middle;
}
div.die .die-value {
vertical-align: middle;
}
div.die input.die-sides {
vertical-align: baseline;
width: 48px;
height: 24px;
}
div.die input.title {
padding: 8px;
}
div.die input:focus {
background-color: var(--mainFGTP);
border: 1px solid var(--mainFG);
}
div.die input.title:not(:placeholder-shown) {
border: none;
border-radius: 0;
background-color: transparent;
}
div.die input.title:not(:placeholder-shown):hover {
border-bottom: 1px solid var(--mainFG);
}
div.die button {
border-radius: 4px;
padding: 8px;
margin: 0;
font-size: 12px;
background-color: transparent;
border: 1px solid var(--mainFGTP);
color: var(--mainFG);
outline: none;
transition: background-color 0.25s;
}
div.die button.icon {
margin-bottom: 8px;
font-size: 19px;
vertical-align: middle;
}
div.die button:hover {
background-color: var(--mainFGTP);
}
div.die button:active {
border: 1px solid var(--mainFG);
}
.indi.neg {
background-color: var(--negColorThemed);
}
.indi.neg:hover {
background-color: var(--negColorThemedLight);
}
.indi.pos {
background-color: var(--posColorThemed);
}
.ident {
font-size: 19px;
vertical-align: top;
margin: 6px;
margin-right: 8px;
}
@media (max-width: 675px) {
div.content {
padding: 0 16px;
}
}
@media (min-width: 875px) {
div.content {
padding: 0 20%;
}
}
@media (min-width: 1200px) {
div.content {
padding: 0 10%;
padding-top: 16px;
padding-bottom: 16px;
overflow-y: auto;
}
div.content > div {
column-count: 2;
}
div.die {
break-inside: avoid-column;
list-style-type: none;
margin-top: 0;
border: var(--mainFGTP) 1px solid;
box-shadow: none;
}
div.bag {
column-span: all;
margin-top: 16px;
}
div.bag div.dropHere {
column-count: 2;
}
}
@media (min-width: 1775px) {
div.content > div {
column-count: 3;
}
}