interim commit
This commit is contained in:
parent
d062fa0e6f
commit
8d721a88c7
20 changed files with 17329 additions and 152 deletions
|
|
@ -6,10 +6,10 @@ import {
|
|||
} from 'react-bootstrap';
|
||||
|
||||
export default ({
|
||||
prefix, singular, onChangeSuper,
|
||||
prefix, singular, onChangeSuper, prefill,
|
||||
}) => {
|
||||
const [entries, setEntries] = useState([true]);
|
||||
const [state, setState] = useState([{
|
||||
const [entries, setEntries] = useState(prefill || [true]);
|
||||
const [state, setState] = useState(prefill || [{
|
||||
ore: '',
|
||||
chance: 100,
|
||||
}]);
|
||||
|
|
|
|||
BIN
frontend/src/components/view/.ConfigCreate.jsx.swp
Normal file
BIN
frontend/src/components/view/.ConfigCreate.jsx.swp
Normal file
Binary file not shown.
BIN
frontend/src/components/view/.ConfigCreateOre.jsx.swp
Normal file
BIN
frontend/src/components/view/.ConfigCreateOre.jsx.swp
Normal file
Binary file not shown.
|
|
@ -40,13 +40,17 @@ const ConfigViewComponent = ({
|
|||
<tr>
|
||||
<th>#</th>
|
||||
<th>URL</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{configs.map((slug, idx) => (
|
||||
{configs.map(({ _id: slug, name }, idx) => (
|
||||
<tr>
|
||||
<td>{idx + 1}</td>
|
||||
<td><a href={`/?id=${slug}`}>{slug}</a></td>
|
||||
<td><a href={`/view?id=${slug}`}>{name}</a></td>
|
||||
<td>
|
||||
<a href={`/edit?id=${slug}`} className="btn btn-success">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
|
|
|||
|
|
@ -1,21 +1,24 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Accordion, Button, Container } from 'react-bootstrap';
|
||||
import {
|
||||
Accordion, Button, Container, Form,
|
||||
} from 'react-bootstrap';
|
||||
import { connect } from 'react-redux';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import { GetConfigForEdit } from '../../axios/Config/GetConfig';
|
||||
import PutConfig from '../../axios/Config/PutConfig';
|
||||
import GetConfig from '../../axios/Config/GetConfig';
|
||||
import ConfigRender from './ConfigRender';
|
||||
import ConfigRenderOre from './ConfigRenderOre';
|
||||
import ConfigRenderStone from './ConfigRenderStone';
|
||||
import PatchConfig from '../../axios/Config/PatchConfig';
|
||||
import ConfigCreateOre from './ConfigCreateOre';
|
||||
import ConfigCreateStone from './ConfigCreateStone';
|
||||
|
||||
const Configurator = ({
|
||||
mc114,
|
||||
mc114, editing, prefill,
|
||||
}) => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const [postRender, setPostRender] = useState(null);
|
||||
const [name, setName] = useState(prefill && prefill.name);
|
||||
const [oreConfigs, setOreConfigs] = useState(prefill
|
||||
? Array(prefill.json.ores.length).fill(true) : [true]);
|
||||
const [stoneConfigs, setStoneConfigs] = useState(prefill
|
||||
? Array(prefill.json.stones.length).fill(true) : [true]);
|
||||
|
||||
const [oreConfigs, setOreConfigs] = useState([true]);
|
||||
const [stoneConfigs, setStoneConfigs] = useState([true]);
|
||||
const [oreState, setOreState] = useState([{
|
||||
name: '',
|
||||
type: 'dense',
|
||||
|
|
@ -29,6 +32,7 @@ const Configurator = ({
|
|||
dimBlacklist: [],
|
||||
blockStateMatchers: [],
|
||||
}]);
|
||||
|
||||
const [stoneState, setStoneState] = useState([{
|
||||
block: '',
|
||||
maxY: -1,
|
||||
|
|
@ -38,21 +42,6 @@ const Configurator = ({
|
|||
dimBlacklist: [],
|
||||
}]);
|
||||
|
||||
if (params.has('id')) {
|
||||
if (postRender) {
|
||||
return (<ConfigRender jsonData={postRender} />);
|
||||
}
|
||||
|
||||
GetConfig(params.get('id')).then((data) => (
|
||||
setPostRender(data)
|
||||
));
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center"><h1>Loading...</h1></div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
const addOreEntry = () => {
|
||||
setOreConfigs([...oreConfigs, true]);
|
||||
};
|
||||
|
|
@ -69,6 +58,19 @@ const Configurator = ({
|
|||
setOreState(newState);
|
||||
};
|
||||
|
||||
const onSubmit = () => {
|
||||
const body = { name, json: { ores: oreState, stones: stoneState } };
|
||||
if (editing) {
|
||||
PatchConfig(prefill.id, body).then((data) => {
|
||||
window.location.href = `/view?id=${data}`;
|
||||
});
|
||||
} else {
|
||||
PutConfig(body).then((data) => {
|
||||
window.location.href = `/view?id=${data}`;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const addStoneEntry = () => {
|
||||
setStoneConfigs([...stoneConfigs, true]);
|
||||
};
|
||||
|
|
@ -85,6 +87,30 @@ const Configurator = ({
|
|||
setStoneState(newState);
|
||||
};
|
||||
|
||||
if (editing && !prefill) {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.has('id')) {
|
||||
GetConfigForEdit(params.get('id'));
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center"><h1>Loading...</h1></div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center text-danger">
|
||||
<h3>
|
||||
Missing Query Param
|
||||
{' '}
|
||||
<code>id</code>
|
||||
</h3>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div>
|
||||
|
|
@ -93,17 +119,29 @@ const Configurator = ({
|
|||
<h4>Geolosys Deposit Configurator</h4>
|
||||
</div>
|
||||
|
||||
<Container className="w-50">
|
||||
<Form.Group>
|
||||
<Form.Label>Config Name:</Form.Label>
|
||||
<Form.Control
|
||||
type="text"
|
||||
name="configName"
|
||||
value={name}
|
||||
onChange={(evt) => setName(evt.target.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
</Container>
|
||||
<Container>
|
||||
<h4>Ores</h4>
|
||||
<Accordion defaultActiveKey="0">
|
||||
{oreConfigs.map((enabled, idx) => enabled && (
|
||||
<ConfigRenderOre
|
||||
mc114={mc114}
|
||||
onEntryCreation={addOreEntry}
|
||||
onEntryDeletion={removeOreEntry}
|
||||
onConfigChange={onOreConfigChange}
|
||||
idx={idx}
|
||||
/>
|
||||
<ConfigCreateOre
|
||||
mc114={mc114}
|
||||
onEntryCreation={addOreEntry}
|
||||
onEntryDeletion={removeOreEntry}
|
||||
onConfigChange={onOreConfigChange}
|
||||
prefill={editing && prefill.json.ores[idx]}
|
||||
idx={idx}
|
||||
/>
|
||||
))}
|
||||
</Accordion>
|
||||
</Container>
|
||||
|
|
@ -112,29 +150,24 @@ const Configurator = ({
|
|||
<h4>Stones</h4>
|
||||
<Accordion defaultActiveKey="0">
|
||||
{stoneConfigs.map((enabled, idx) => enabled && (
|
||||
<ConfigRenderStone
|
||||
mc114={mc114}
|
||||
onEntryCreation={addStoneEntry}
|
||||
onEntryDeletion={removeStoneEntry}
|
||||
onConfigChange={onStoneConfigChange}
|
||||
idx={idx}
|
||||
/>
|
||||
<ConfigCreateStone
|
||||
mc114={mc114}
|
||||
onEntryCreation={addStoneEntry}
|
||||
onEntryDeletion={removeStoneEntry}
|
||||
onConfigChange={onStoneConfigChange}
|
||||
prefill={editing && prefill.json.stones[idx]}
|
||||
idx={idx}
|
||||
/>
|
||||
))}
|
||||
</Accordion>
|
||||
</Container>
|
||||
|
||||
<Button
|
||||
onClick={() => PutConfig({
|
||||
json: {
|
||||
ores: oreState,
|
||||
stones: stoneState,
|
||||
},
|
||||
}).then((data) => {
|
||||
window.location.href = `/?id=${data}`;
|
||||
})}
|
||||
onClick={onSubmit}
|
||||
variant={editing ? 'danger' : 'primary'}
|
||||
className="d-block mx-auto my-4"
|
||||
>
|
||||
Generate!
|
||||
{editing ? 'Save (Overwrites)' : 'Generate!'}
|
||||
</Button>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
|
|
@ -143,6 +176,7 @@ const Configurator = ({
|
|||
|
||||
const mapStateToProps = (state) => ({
|
||||
mc114: state.mc114,
|
||||
prefill: state.editing || null,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(Configurator);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import ExtendableInput from '../modules/Config/ExtendableInput';
|
|||
import ExtendableBiomeInput from '../modules/Config/ExtendableBiomeInput';
|
||||
|
||||
export default ({
|
||||
mc114, idx, onEntryCreation, onEntryDeletion, onConfigChange,
|
||||
mc114, idx, onEntryCreation, onEntryDeletion, onConfigChange, prefill,
|
||||
}) => {
|
||||
const [state, setState] = useState({
|
||||
const [state, setState] = useState(prefill || {
|
||||
name: '',
|
||||
depType: 'deposit',
|
||||
type: 'dense',
|
||||
|
|
@ -27,16 +27,8 @@ export default ({
|
|||
});
|
||||
|
||||
const setStateWithPropogation = (newState) => {
|
||||
const formatted = { ...newState };
|
||||
if (formatted.oreBlocks) {
|
||||
formatted.oreBlocks = formatted.oreBlocks.map((x) => [x.ore, x.chance]).flat();
|
||||
}
|
||||
if (formatted.sampleBlocks) {
|
||||
formatted.sampleBlocks = formatted.sampleBlocks.map((x) => [x.ore, x.chance]).flat();
|
||||
}
|
||||
delete formatted.depType;
|
||||
setState(newState);
|
||||
onConfigChange(idx, formatted);
|
||||
onConfigChange(idx, newState);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -125,6 +117,7 @@ export default ({
|
|||
<WeightedTextEntry
|
||||
singular={!state.depType.toLowerCase().includes('multi')}
|
||||
prefix="ore"
|
||||
prefill={prefill && prefill.oreBlocks}
|
||||
onChangeSuper={(oreBlocks) => {
|
||||
setStateWithPropogation({ ...state, oreBlocks });
|
||||
}}
|
||||
|
|
@ -139,6 +132,7 @@ export default ({
|
|||
<WeightedTextEntry
|
||||
singular={!state.depType.toLowerCase().includes('multi')}
|
||||
prefix="sample"
|
||||
prefill={prefill && prefill.sampleBlocks}
|
||||
onChangeSuper={(sampleBlocks) => {
|
||||
setStateWithPropogation({ ...state, sampleBlocks });
|
||||
}}
|
||||
|
|
@ -7,9 +7,9 @@ import {
|
|||
import ExtendableInput from '../modules/Config/ExtendableInput';
|
||||
|
||||
export default ({
|
||||
mc114, idx, onEntryCreation, onEntryDeletion, onConfigChange,
|
||||
mc114, idx, onEntryCreation, onEntryDeletion, onConfigChange, prefill,
|
||||
}) => {
|
||||
const [state, setState] = useState({
|
||||
const [state, setState] = useState(prefill || {
|
||||
block: '',
|
||||
maxY: 1,
|
||||
minY: 0,
|
||||
|
|
@ -1,15 +1,61 @@
|
|||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Container } from 'react-bootstrap';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import GetConfig from '../../axios/Config/GetConfig';
|
||||
|
||||
export default ({
|
||||
jsonData,
|
||||
}) => (
|
||||
<div>
|
||||
<h2 className="text-center mt-3">Config View</h2>
|
||||
<Container className="shadow mt-5">
|
||||
<pre>
|
||||
{JSON.stringify(jsonData.json, null, 2) }
|
||||
</pre>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
const cleanJson = (json) => {
|
||||
const formatted = { ...json.ores };
|
||||
if (formatted.oreBlocks) {
|
||||
formatted.oreBlocks = formatted.oreBlocks.map((x) => [x.ore, x.chance]).flat();
|
||||
}
|
||||
if (formatted.sampleBlocks) {
|
||||
formatted.sampleBlocks = formatted.sampleBlocks.map((x) => [x.ore, x.chance]).flat();
|
||||
}
|
||||
|
||||
delete formatted.depType;
|
||||
|
||||
return {
|
||||
ores: formatted,
|
||||
stones: json.stones,
|
||||
};
|
||||
};
|
||||
|
||||
export default () => {
|
||||
const [json, setJson] = useState(null);
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
if (!json) {
|
||||
if (params.has('id')) {
|
||||
GetConfig(params.get('id')).then((data) => (
|
||||
setJson(data)
|
||||
));
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center"><h1>Loading...</h1></div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center text-danger">
|
||||
<h3>
|
||||
Missing Query Param
|
||||
{' '}
|
||||
<code>id</code>
|
||||
</h3>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2 className="text-center mt-3">{`Viewing Config ${json.name}`}</h2>
|
||||
<Container className="shadow mt-5">
|
||||
<pre>
|
||||
{JSON.stringify(cleanJson(json.json), null, 2)}
|
||||
</pre>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue