Skip to content

Commit

Permalink
[client] MACROS (#23)
Browse files Browse the repository at this point in the history
Macros: save, edit, and delete. They're stored in your browser.
Relates to #8
  • Loading branch information
juharris authored Jun 19, 2020
1 parent 610607b commit b83300b
Show file tree
Hide file tree
Showing 12 changed files with 797 additions and 66 deletions.
2 changes: 1 addition & 1 deletion server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='switch-remoteplay-server',
version='0.4.0',
version='0.5.0',
packages=find_packages(),
url='https://github.com/juharris/switch-remoteplay',
license='MIT',
Expand Down
2 changes: 1 addition & 1 deletion website-client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
rules: {
'comma-dangle': ['off', 'ignore'],
'comma-spacing': ["error", { "before": false, "after": true }],
indent: ['error', 'tab'],
indent: ['error', 'tab', { SwitchCase: 1 }],
'no-tabs': 0,
'operator-linebreak': ['off'],
quotes: ['off'],
Expand Down
2 changes: 1 addition & 1 deletion website-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "switch-rp-client",
"version": "0.4.0",
"version": "0.5.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.10.0",
Expand Down
2 changes: 2 additions & 0 deletions website-client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import blue from '@material-ui/core/colors/blue'
import CssBaseline from '@material-ui/core/CssBaseline'
import { createMuiTheme, createStyles, ThemeProvider, withStyles, WithStyles } from '@material-ui/core/styles'
import React from 'react'
Expand All @@ -10,6 +11,7 @@ import PlayGame from './components/PlayGame'
const theme = createMuiTheme({
palette: {
type: 'dark',
primary: blue,
},
})

Expand Down
46 changes: 23 additions & 23 deletions website-client/src/components/Controller/Controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const styles = () => createStyles({
class Controller extends React.Component<any> {
render(): React.ReactNode {
const { classes } = this.props
const controllerState: ControllerState = this.props.controllerState || new ControllerState()
const controllerState: ControllerState | undefined = this.props.controllerState

return (
<div className={classes.controller}>
Expand All @@ -26,7 +26,7 @@ class Controller extends React.Component<any> {
<div
className={
cssClasses.LargeButton +
(controllerState.l.isPressed ? " " + cssClasses.Pressed : "")
(controllerState?.l?.isPressed ? " " + cssClasses.Pressed : "")
}
>
<p>L</p>
Expand All @@ -35,15 +35,15 @@ class Controller extends React.Component<any> {
<div
className={
cssClasses.SmallButton +
(controllerState.zl.isPressed ? " " + cssClasses.Pressed : "")
(controllerState?.zl?.isPressed ? " " + cssClasses.Pressed : "")
}
>
<p>ZL</p>
</div>
<div
className={
cssClasses.Symbol +
(controllerState.minus.isPressed ? " " + cssClasses.PressedAlt : "")
(controllerState?.minus?.isPressed ? " " + cssClasses.PressedAlt : "")
}
>
{/* Slightly wider than a typical minus. */}
Expand All @@ -52,22 +52,22 @@ class Controller extends React.Component<any> {
</div>
</div>
<Joystick
x={controllerState.leftStick.horizontalValue}
y={controllerState.leftStick.verticalValue}
pressed={controllerState.leftStick.isPressed}
x={controllerState?.leftStick?.horizontalValue || 0}
y={controllerState?.leftStick?.verticalValue || 0}
pressed={controllerState?.leftStick?.isPressed}
/>
<Diamond
buttons={[
{ symbol: "▶", pressed: controllerState.arrowRight.isPressed },
{ symbol: "▼", pressed: controllerState.arrowDown.isPressed },
{ symbol: "▲", pressed: controllerState.arrowUp.isPressed },
{ symbol: "◀", pressed: controllerState.arrowLeft.isPressed },
{ symbol: "▶", pressed: controllerState?.arrowRight?.isPressed },
{ symbol: "▼", pressed: controllerState?.arrowDown?.isPressed },
{ symbol: "▲", pressed: controllerState?.arrowUp?.isPressed },
{ symbol: "◀", pressed: controllerState?.arrowLeft?.isPressed },
]}
/>
<div
className={
cssClasses.Symbol + " " + cssClasses.capture +
(controllerState.capture.isPressed ? " " + cssClasses.PressedAlt : "")
(controllerState?.capture?.isPressed ? " " + cssClasses.PressedAlt : "")
}
>
<p></p>
Expand All @@ -81,7 +81,7 @@ class Controller extends React.Component<any> {
<div
className={
cssClasses.LargeButton +
(controllerState.r.isPressed ? " " + cssClasses.Pressed : "")
(controllerState?.r?.isPressed ? " " + cssClasses.Pressed : "")
}
>
<p>R</p>
Expand All @@ -90,15 +90,15 @@ class Controller extends React.Component<any> {
<div
className={
cssClasses.Symbol +
(controllerState.plus.isPressed ? " " + cssClasses.PressedAlt : "")
(controllerState?.plus?.isPressed ? " " + cssClasses.PressedAlt : "")
}
>
<p>+</p>
</div>
<div
className={
cssClasses.SmallButton +
(controllerState.zr.isPressed ? " " + cssClasses.Pressed : "")
(controllerState?.zr?.isPressed ? " " + cssClasses.Pressed : "")
}
>
<p>ZR</p>
Expand All @@ -107,21 +107,21 @@ class Controller extends React.Component<any> {
</div>
<Diamond
buttons={[
{ symbol: "a", pressed: controllerState.a.isPressed },
{ symbol: "b", pressed: controllerState.b.isPressed },
{ symbol: "x", pressed: controllerState.x.isPressed },
{ symbol: "y", pressed: controllerState.y.isPressed },
{ symbol: "a", pressed: controllerState?.a?.isPressed },
{ symbol: "b", pressed: controllerState?.b?.isPressed },
{ symbol: "x", pressed: controllerState?.x?.isPressed },
{ symbol: "y", pressed: controllerState?.y?.isPressed },
]}
/>
<Joystick
x={controllerState.rightStick.horizontalValue}
y={controllerState.rightStick.verticalValue}
pressed={controllerState.rightStick.isPressed}
x={controllerState?.rightStick?.horizontalValue || 0}
y={controllerState?.rightStick?.verticalValue || 0}
pressed={controllerState?.rightStick?.isPressed}
/>
<div
className={
cssClasses.Symbol + " " + cssClasses.home +
(controllerState.home.isPressed ? " " + cssClasses.PressedAlt : "")
(controllerState?.home?.isPressed ? " " + cssClasses.PressedAlt : "")
}
>
<p></p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import { ControllerState } from '../ControllerState'
import { parseCommand } from '../parse-command'

describe('parseCommand', () => {
it('tap button', () => {
let c1, c2
for (const buttonName of [
'l', 'zl',
'r', 'zr',
'a', 'b', 'x', 'y',
'minus', 'plus',
'home', 'capture',

]) {
c1 = new ControllerState();
(c1 as any)[buttonName].isPressed = true
c2 = new ControllerState()
expect(parseCommand(`${buttonName}`)).toStrictEqual([c1, c2])
}

c1 = new ControllerState()
c1.leftStick.isPressed = true
c2 = new ControllerState()
expect(parseCommand(`l_stick`)).toStrictEqual([c1, c2])

c1 = new ControllerState()
c1.rightStick.isPressed = true
c2 = new ControllerState()
expect(parseCommand(`r_stick`)).toStrictEqual([c1, c2])

c1 = new ControllerState()
c1.arrowDown.isPressed = true
c2 = new ControllerState()
expect(parseCommand(`down`)).toStrictEqual([c1, c2])

c1 = new ControllerState()
c1.arrowUp.isPressed = true
c2 = new ControllerState()
expect(parseCommand(`up`)).toStrictEqual([c1, c2])

c1 = new ControllerState()
c1.arrowRight.isPressed = true
c2 = new ControllerState()
expect(parseCommand(`right`)).toStrictEqual([c1, c2])

c1 = new ControllerState()
c1.arrowLeft.isPressed = true
c2 = new ControllerState()
expect(parseCommand(`left`)).toStrictEqual([c1, c2])
})

it('push button', () => {
let c = new ControllerState()
for (const buttonName of [
'l', 'zl',
'r', 'zr',
'a', 'b', 'x', 'y',
'minus', 'plus',
'home', 'capture',

]) {
(c as any)[buttonName].isPressed = true
expect(parseCommand(`${buttonName} d`)).toStrictEqual([c])

c = new ControllerState()
expect(parseCommand(`${buttonName} u`)).toStrictEqual([c])
}

c = new ControllerState()
c.leftStick.isPressed = true
expect(parseCommand(`l_stick d`)).toStrictEqual([c])
c = new ControllerState()
expect(parseCommand(`l_stick u`)).toStrictEqual([c])

c.rightStick.isPressed = true
expect(parseCommand(`r_stick d`)).toStrictEqual([c])
c = new ControllerState()
expect(parseCommand(`r_stick u`)).toStrictEqual([c])

c = new ControllerState()
c.arrowDown.isPressed = true
expect(parseCommand(`down d`)).toStrictEqual([c])
c = new ControllerState()
expect(parseCommand(`down u`)).toStrictEqual([c])

c.arrowUp.isPressed = true
expect(parseCommand(`up d`)).toStrictEqual([c])
c = new ControllerState()
expect(parseCommand(`up u`)).toStrictEqual([c])

c.arrowRight.isPressed = true
expect(parseCommand(`right d`)).toStrictEqual([c])
c = new ControllerState()
expect(parseCommand(`right u`)).toStrictEqual([c])

c.arrowLeft.isPressed = true
expect(parseCommand(`left d`)).toStrictEqual([c])
c = new ControllerState()
expect(parseCommand(`left u`)).toStrictEqual([c])
})

it('move sticks', () => {
let c = new ControllerState()

c.leftStick.verticalValue = -1
expect(parseCommand(`s l up`)).toStrictEqual([c])
c.leftStick.verticalValue = 1
expect(parseCommand(`s l down`)).toStrictEqual([c])
c.leftStick.verticalValue = 0
c.leftStick.horizontalValue = -1
expect(parseCommand(`s l left`)).toStrictEqual([c])
c.leftStick.horizontalValue = 1
expect(parseCommand(`s l right`)).toStrictEqual([c])
c.leftStick.horizontalValue = 0
expect(parseCommand(`s l center`)).toStrictEqual([c])

c.leftStick.horizontalValue = -1
expect(parseCommand(`s l h min`)).toStrictEqual([c])
c.leftStick.horizontalValue = 1
expect(parseCommand(`s l h max`)).toStrictEqual([c])
c.leftStick.horizontalValue = 0
expect(parseCommand(`s l h center`)).toStrictEqual([c])
c.leftStick.verticalValue = 1
expect(parseCommand(`s l v min`)).toStrictEqual([c])
c.leftStick.verticalValue = -1
expect(parseCommand(`s l v max`)).toStrictEqual([c])
c.leftStick.verticalValue = 0
expect(parseCommand(`s l v center`)).toStrictEqual([c])

c.leftStick.horizontalValue = 0.5
expect(parseCommand(`s l h 0.5`)).toStrictEqual([c])
c.leftStick.horizontalValue = -0.5
expect(parseCommand(`s l h -0.5`)).toStrictEqual([c])
c.leftStick.horizontalValue = -1
expect(parseCommand(`s l h -1`)).toStrictEqual([c])
c.leftStick.horizontalValue = 1
expect(parseCommand(`s l h +1`)).toStrictEqual([c])
c.leftStick.horizontalValue = 1
expect(parseCommand(`s l h 1`)).toStrictEqual([c])
c.leftStick.horizontalValue = 0
expect(parseCommand(`s l h 0`)).toStrictEqual([c])
c.leftStick.verticalValue = 0.5
expect(parseCommand(`s l v 0.5`)).toStrictEqual([c])
c.leftStick.verticalValue = -0.5
expect(parseCommand(`s l v -0.5`)).toStrictEqual([c])
c.leftStick.verticalValue = -1
expect(parseCommand(`s l v -1`)).toStrictEqual([c])
c.leftStick.verticalValue = 1
expect(parseCommand(`s l v +1`)).toStrictEqual([c])
c.leftStick.verticalValue = 1
expect(parseCommand(`s l v 1`)).toStrictEqual([c])
c.leftStick.verticalValue = 0
expect(parseCommand(`s l v 0`)).toStrictEqual([c])
c.leftStick.horizontalValue = 0.5
c.leftStick.verticalValue = -1
expect(parseCommand(`s l hv 0.5 -1`)).toStrictEqual([c])
c.leftStick.horizontalValue = -0.5
c.leftStick.verticalValue = 1
expect(parseCommand(`s l hv -0.5 1`)).toStrictEqual([c])
c.leftStick.horizontalValue = 0
c.leftStick.verticalValue = 0.5
expect(parseCommand(`s l hv 0 .5`)).toStrictEqual([c])


c = new ControllerState()
c.rightStick.verticalValue = -1
expect(parseCommand(`s r up`)).toStrictEqual([c])
c.rightStick.verticalValue = 1
expect(parseCommand(`s r down`)).toStrictEqual([c])
c.rightStick.verticalValue = 0
c.rightStick.horizontalValue = -1
expect(parseCommand(`s r left`)).toStrictEqual([c])
c.rightStick.horizontalValue = 1
expect(parseCommand(`s r right`)).toStrictEqual([c])
c.rightStick.horizontalValue = 0
expect(parseCommand(`s r center`)).toStrictEqual([c])

c.rightStick.horizontalValue = -1
expect(parseCommand(`s r h min`)).toStrictEqual([c])
c.rightStick.horizontalValue = 1
expect(parseCommand(`s r h max`)).toStrictEqual([c])
c.rightStick.horizontalValue = 0
expect(parseCommand(`s r h center`)).toStrictEqual([c])
c.rightStick.verticalValue = 1
expect(parseCommand(`s r v min`)).toStrictEqual([c])
c.rightStick.verticalValue = -1
expect(parseCommand(`s r v max`)).toStrictEqual([c])
c.rightStick.verticalValue = 0
expect(parseCommand(`s r v center`)).toStrictEqual([c])

c.rightStick.horizontalValue = 0.5
expect(parseCommand(`s r h 0.5`)).toStrictEqual([c])
c.rightStick.horizontalValue = 0
c.rightStick.verticalValue = 0.5
expect(parseCommand(`s r v 0.5`)).toStrictEqual([c])
c.rightStick.verticalValue = -0.5
expect(parseCommand(`s r v -0.5`)).toStrictEqual([c])
c.rightStick.verticalValue = -1
expect(parseCommand(`s r v -1`)).toStrictEqual([c])
c.rightStick.verticalValue = 0
expect(parseCommand(`s r v 0`)).toStrictEqual([c])
c.rightStick.horizontalValue = 0.5
c.rightStick.verticalValue = -1
expect(parseCommand(`s r hv 0.5 -1`)).toStrictEqual([c])
c.rightStick.horizontalValue = -0.5
c.rightStick.verticalValue = 1
expect(parseCommand(`s r hv -0.5 1`)).toStrictEqual([c])
})


it('unrecognized', () => {
expect(parseCommand('junk')).toStrictEqual([new ControllerState()])
})

it('combined', () => {
const c = new ControllerState()
c.a.isPressed = c.b.isPressed = true
expect(parseCommand('a d&b d')).toStrictEqual([c])
})
})
Loading

0 comments on commit b83300b

Please sign in to comment.