diff --git a/index.html b/index.html
index 7da6916..7847576 100644
--- a/index.html
+++ b/index.html
@@ -4,7 +4,7 @@
-
FF8 Q+Z Card
+ FF8 Card Manip
diff --git a/src/components/RngCalculator.jsx b/src/components/RngCalculator.jsx
index f29ddf7..cd1a600 100644
--- a/src/components/RngCalculator.jsx
+++ b/src/components/RngCalculator.jsx
@@ -3,51 +3,62 @@ import PropTypes from 'prop-types';
import { useState } from 'react';
import { IconPhoto, IconMessageCircle, IconSettings } from '@tabler/icons-react';
-export function RngCalculator(props) {
- const [rngValue, setRngValue] = useState({});
- const configData = props.data;
- const makeid = (length) => {
- // https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
- var result = '';
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- var charactersLength = characters.length;
- for (var i = 0; i < length; i++) {
- result += characters.charAt(Math.floor(Math.random() *
- charactersLength));
+const CalculateBaseValues = (configData) => {
+ // Calculate base values
+ let basevalues = {
+ q: 0,
+ z: 0
+ }
+
+ for (let config of configData) {
+ let isQuistis = config.button;
+ if (config.baseValue != -1) {
+ basevalues[isQuistis ? 'q' : 'z'] += config.baseValue;
}
- return result;
}
- const ProcessCategory = (category, topLabel) => {
- return (<>
- {category.label}
- {Object.prototype.hasOwnProperty.call(category, 'subCategories') ? category.subCategories.map((subcategory) => ProcessSubCategory(subcategory, category.baseCountPage || "", category.label, topLabel)) : ""}
- >)
+ return basevalues;
+}
+
+const makeid = (length) => {
+ // https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
+ var result = '';
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ var charactersLength = characters.length;
+ for (var i = 0; i < length; i++) {
+ result += characters.charAt(Math.floor(Math.random() *
+ charactersLength));
}
+ return result;
+}
- const ProcessSubCategory = (subcategory, baseCountPage, catLabel, topLabel) => {
- let label = subcategory.label || "";
- catLabel = `${topLabel}-${catLabel}`;
+const sumValues = obj => Object.values(obj).reduce((a, b) => a + b, 0);
- switch (subcategory.type.toLowerCase()) {
- case 'buttons':
- return CreateButtons(subcategory.value, label, catLabel);
- case 'radiobutton':
- return CreateRadioButtons(subcategory.value, label, catLabel);
- case 'list':
- return CreateList(subcategory.value, label, catLabel, subcategory.times || 1);
+export function RngCalculator(props) {
+ const configData = props.data;
+ let bases = CalculateBaseValues(configData);
+
+ const [qRngValue, setQRngValue] = useState({ 'q-basevalue': bases.q });
+ const [zRngValue, setZRngValue] = useState({ 'z-basevalue': bases.z });
+
+ const setRngValue = (rngName, val, isQuistis) => {
+ if (isQuistis) {
+ setQRngValue(prevState => ({ ...prevState, [rngName]: val }));
+ } else {
+ setZRngValue(prevState => ({ ...prevState, [rngName]: val }));
}
+ console.log(val);
}
- const CreateButtons = (data, label, catLabel) => {
+ const CreateButtons = (data, label, catLabel, isQuistis) => {
let rngName = btoa(`${catLabel}-${label}`)
return (
setRngValue(prevState => ({ ...prevState, [rngName]: val.reduce((a, c) => { return a + parseInt(c) }, 0) }))}
+ onChange={(val) => setRngValue(rngName, val.reduce((a, c) => { return a + parseInt(c) }, 0), isQuistis)}
>
{data.map((button) => {
@@ -58,12 +69,12 @@ export function RngCalculator(props) {
);
}
- const CreateRadioButtons = (data, label, catLabel) => {
+ const CreateRadioButtons = (data, label, catLabel, isQuistis) => {
let rngName = btoa(`${catLabel}-${label}`)
return (
setRngValue(prevState => ({ ...prevState, [rngName]: parseInt(val) }))}
+ onChange={(val) => setRngValue(rngName, parseInt(val), isQuistis)}
>
{data.map((button) => {
@@ -74,34 +85,61 @@ export function RngCalculator(props) {
);
}
- const CreateList = (data, label, catLabel, times) => {
+ const ProcessCategory = (category, topLabel, isQuistis) => {
+ return (
+ <>
+ {category.label}
+ {Object.prototype.hasOwnProperty.call(category, 'subCategories') ? category.subCategories.map((subcategory) => ProcessSubCategory(subcategory, category.baseCountPage || "", category.label, topLabel, isQuistis)) : ""}
+ >
+ )
+ }
+
+ const ProcessSubCategory = (subcategory, baseCountPage, catLabel, topLabel, isQuistis) => {
+ let label = subcategory.label || "";
+
+ catLabel = `${topLabel}-${catLabel}`;
+
+ switch (subcategory.type.toLowerCase()) {
+ case 'buttons':
+ return CreateButtons(subcategory.value, label, catLabel, isQuistis);
+ case 'radiobutton':
+ return CreateRadioButtons(subcategory.value, label, catLabel, isQuistis);
+ case 'list':
+ return CreateList(subcategory.value, label, catLabel, subcategory.times || 1, isQuistis);
+ }
+ }
+
+ const CreateList = (data, label, catLabel, times, isQuistis) => {
let rngName = btoa(`${catLabel}-${label}`)
let elements = [];
- for (let i = 1; i < times; i++) {
+ for (let i = 1; i <= times; i++) {
let rngNameTimes = `${rngName}-${i}`;
elements.push(