mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-22 21:16:14 -04:00
wip
This commit is contained in:
parent
2f51f83514
commit
42abc6bc01
25 changed files with 1514 additions and 1328 deletions
|
@ -1,4 +1,4 @@
|
|||
import {Level, Palette, RawLevel} from "../types";
|
||||
import { Level, Palette, RawLevel } from "../types";
|
||||
import _backgrounds from "../data/backgrounds.json";
|
||||
import _palette from "../data/palette.json";
|
||||
// import _allLevels from "../data/levels.json";
|
||||
|
@ -12,34 +12,35 @@ const backgrounds = _backgrounds as string[];
|
|||
const palette = _palette as Palette;
|
||||
|
||||
// let allLevels = _allLevels ;
|
||||
let allLevels=null
|
||||
let allLevels = null;
|
||||
|
||||
function App() {
|
||||
const [selected, setSelected] = useState("W");
|
||||
const [applying, setApplying] = useState("");
|
||||
const [levels, setLevels] = useState([]);
|
||||
useEffect(()=>{
|
||||
fetch('http://localhost:4400/src/data/levels.json')
|
||||
.then(r=>r.json())
|
||||
.then(list=>{
|
||||
setLevels(list as RawLevel[])
|
||||
allLevels=list
|
||||
})
|
||||
},[])
|
||||
useEffect(() => {
|
||||
fetch("http://localhost:4400/src/data/levels.json")
|
||||
.then((r) => r.json())
|
||||
.then((list) => {
|
||||
setLevels(list as RawLevel[]);
|
||||
allLevels = list;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const updateLevel = (index: number, change: Partial<RawLevel>) => {
|
||||
setLevels((list) =>
|
||||
list.map((l, li) => (li === index ? { ...l, ...change } : l)),
|
||||
);
|
||||
}
|
||||
const updateLevel = (index: number, change: Partial<RawLevel>) => {
|
||||
setLevels((list) =>
|
||||
list.map((l, li) => (li === index ? { ...l, ...change } : l)),
|
||||
);
|
||||
};
|
||||
|
||||
const deleteLevel = (index: number) => {
|
||||
if (confirm("Delete level")) {
|
||||
setLevels(levels.filter((l, i) => i!==index));
|
||||
setLevels(levels.filter((l, i) => i !== index));
|
||||
}
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
if(!allLevels||JSON.stringify(allLevels) === JSON.stringify(levels)) return
|
||||
if (!allLevels || JSON.stringify(allLevels) === JSON.stringify(levels))
|
||||
return;
|
||||
const timoutId = setTimeout(() => {
|
||||
return fetch("http://localhost:4400/src/data/levels.json", {
|
||||
method: "POST",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue