diff --git a/experiments/modern/.gitignore b/experiments/modern/.gitignore new file mode 100644 index 00000000..854283ee --- /dev/null +++ b/experiments/modern/.gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +/public/skin diff --git a/experiments/modern/README.md b/experiments/modern/README.md new file mode 100644 index 00000000..9d9614c4 --- /dev/null +++ b/experiments/modern/README.md @@ -0,0 +1,68 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting + +### Analyzing the Bundle Size + +This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size + +### Making a Progressive Web App + +This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app + +### Advanced Configuration + +This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration + +### Deployment + +This section has moved here: https://facebook.github.io/create-react-app/docs/deployment + +### `npm run build` fails to minify + +This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify diff --git a/experiments/modern/package.json b/experiments/modern/package.json new file mode 100644 index 00000000..28afb04c --- /dev/null +++ b/experiments/modern/package.json @@ -0,0 +1,33 @@ +{ + "name": "modern", + "version": "0.1.0", + "private": true, + "dependencies": { + "jszip": "^3.2.1", + "react": "^16.8.6", + "react-dom": "^16.8.6", + "react-scripts": "3.0.1", + "xml-js": "^1.6.11" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/experiments/modern/public/favicon.ico b/experiments/modern/public/favicon.ico new file mode 100644 index 00000000..a11777cc Binary files /dev/null and b/experiments/modern/public/favicon.ico differ diff --git a/experiments/modern/public/index.html b/experiments/modern/public/index.html new file mode 100644 index 00000000..dd1ccfd4 --- /dev/null +++ b/experiments/modern/public/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + React App + + + +
+ + + diff --git a/experiments/modern/public/manifest.json b/experiments/modern/public/manifest.json new file mode 100644 index 00000000..1f2f141f --- /dev/null +++ b/experiments/modern/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/experiments/modern/public/skins/CornerAmp_Redux.wal b/experiments/modern/public/skins/CornerAmp_Redux.wal new file mode 100644 index 00000000..7b7f2166 Binary files /dev/null and b/experiments/modern/public/skins/CornerAmp_Redux.wal differ diff --git a/experiments/modern/src/App.css b/experiments/modern/src/App.css new file mode 100644 index 00000000..b41d297c --- /dev/null +++ b/experiments/modern/src/App.css @@ -0,0 +1,33 @@ +.App { + text-align: center; +} + +.App-logo { + animation: App-logo-spin infinite 20s linear; + height: 40vmin; + pointer-events: none; +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/experiments/modern/src/App.js b/experiments/modern/src/App.js new file mode 100644 index 00000000..56e87ea9 --- /dev/null +++ b/experiments/modern/src/App.js @@ -0,0 +1,324 @@ +import React from "react"; +import logo from "./logo.svg"; +import JSZip from "jszip"; +import "./App.css"; +import { xml2js } from "xml-js"; + +const SkinContext = React.createContext(null); + +function promisify(func) { + return function(...args) { + return new Promise((resolve, reject) => { + func(...args, (err, data) => { + if (err != null) { + reject(err); + return; + } + resolve(data); + }); + }); + }; +} + +async function getSkin() { + const resp = await fetch(process.env.PUBLIC_URL + "/CornerAmp_Redux.wal"); + const blob = await resp.blob(); + const zip = await JSZip.loadAsync(blob); + const player = zip.file("xml/player-elements.xml"); + const xml = await player.async("text"); + + const elementsDoc = await xml2js(xml, { + compact: false, + elementsKey: "children", + }); + + console.log(zip.files); + + const images = {}; + // TODO: Clearly more complicated than it needed to be. + const elements = elementsDoc.children[0].children; + for (const element of elements) { + switch (element.name) { + case "bitmap": { + const { file, gammagroup, h, id, w, x, y } = element.attributes; + // TODO: Escape file for regex + const img = zip.file(new RegExp(file, "i"))[0]; + const imgBlob = await img.async("blob"); + const imgUrl = URL.createObjectURL(imgBlob); + images[id.toLowerCase()] = { file, gammagroup, h, w, x, y, imgUrl }; + break; + } + case "truetypefont": { + console.log(element); + break; + } + default: { + console.error(`Unknonw node ${element.name}`); + } + } + } + return images; +} + +function Layout({ + id, + background, + desktopalpha, + drawBackground, + minimum_h, + maximum_h, + minimum_w, + maximum_w, + droptarget, + children, +}) { + const data = React.useContext(SkinContext); + const image = data[background]; + return ( + <> + + {children} + + ); +} + +function Layer({ id, image, children, x, y }) { + const data = React.useContext(SkinContext); + const img = data[image.toLowerCase()]; + return ( + <> + + {children} + + ); +} + +function Button({ id, image, action, x, y, downImage, tooltip, children }) { + const data = React.useContext(SkinContext); + const [down, setDown] = React.useState(false); + const imgId = down ? downImage : image; + // TODO: These seem to be switching too fast + const img = data[imgId.toLowerCase()]; + return ( +
{ + setDown(true); + document.addEventListener("mouseup", () => { + // TODO: This could be unmounted + setDown(false); + }); + }} + title={tooltip} + style={{ + position: "absolute", + top: Number(y), + left: Number(x), + backgroundPositionX: -Number(img.x), + backgroundPositionx: -Number(img.y), + width: Number(img.w), + height: Number(img.h), + backgroundImage: `url(${img.imgUrl})`, + }} + > + {children} +
+ ); +} + +function ToggleButton(props) { + return