Skip to content

Commit

Permalink
Spot sync and added game page (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor authored Oct 13, 2024
1 parent e6d71e9 commit 39b3a70
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 64 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
"electron-log": "^4.4.6",
"electron-updater": "^4.6.5",
"history": "^5.3.0",
"kaplay": "^3001.0.0-beta.3",
"lokijs": "^1.5.12",
"moment": "^2.30.1",
"react": "^18.0.0",
Expand Down
14 changes: 10 additions & 4 deletions src/api/nodes/NodeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const NodeController = {
* @returns {object} node - the newly created node
* @permission {Modification}
*/
createNode(
async createNode(
nodeType,
nodeTitle,
parentId = ``,
Expand All @@ -56,7 +56,7 @@ const NodeController = {
token: localStorage.getItem(`trelloToken`),
};

return ipcRenderer.sendSync(
const test = await ipcRenderer.invoke(
'api:createNode',
nodeType,
nodeTitle,
Expand All @@ -65,18 +65,24 @@ const NodeController = {
trelloData,
trelloAuth,
);
console.log(test);

Check warning on line 68 in src/api/nodes/NodeController.jsx

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Unexpected console statement
return test;
},

deleteNode(nodeId, parentId) {
ipcRenderer.sendSync('api:deleteNode', nodeId, parentId);
},

updateNodeProperty(propertyToUpdate, nodeId, newValue) {
const trelloAuth = {
updateNodeProperty(propertyToUpdate, nodeId, newValue, shouldSync = true) {
let trelloAuth = {
key: localStorage.getItem(`trelloKey`),
token: localStorage.getItem(`trelloToken`),
};

if (!shouldSync) {
trelloAuth = null;
}

return ipcRenderer.sendSync(
'api:updateNodeProperty',
propertyToUpdate,
Expand Down
52 changes: 36 additions & 16 deletions src/components/NodeModal/NodeModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function NodeModal({
iterations,
node,
parents,
syncTrelloCard,
updateNodeProperty,
visible,
}) {
Expand Down Expand Up @@ -53,6 +54,9 @@ function NodeModal({
[node?.id, updateNodeProperty],
);

const trelloToken = localStorage.getItem('trelloToken');
const trelloKey = localStorage.getItem(`trelloKey`);

return node ? (
<Modal
title={
Expand Down Expand Up @@ -137,22 +141,38 @@ function NodeModal({
updateNodeProperty('notes', node.id, value, true);
}}
/>
<div>Iteration</div>
<Select
style={{ width: 200 }}
value={node.iterationId}
onChange={onChangeIteration}
>
<Option style={{ width: '100%' }} key={0} value={0}>
<span style={{ whiteSpace: 'normal' }}>Backlog</span>
</Option>
{iterations &&
Object.values(iterations).map((item) => (
<Option style={{ width: '100%' }} key={item.id} value={item.id}>
<span style={{ whiteSpace: 'normal' }}>{item.title}</span>
</Option>
))}
</Select>
<div>
<div>Iteration</div>
<Select
style={{ width: 200 }}
value={node.iterationId}
onChange={onChangeIteration}
>
<Option style={{ width: '100%' }} key={0} value={0}>
<span style={{ whiteSpace: 'normal' }}>Backlog</span>
</Option>
{iterations &&
Object.values(iterations).map((item) => (
<Option
style={{ width: '100%' }}
key={item.id}
value={item.id}
>
<span style={{ whiteSpace: 'normal' }}>{item.title}</span>
</Option>
))}
</Select>
{trelloKey && trelloToken && node.trello && (
<Button
style={{ marginLeft: `150px` }}
onClick={() => {
syncTrelloCard(node);
}}
>
Trello Sync
</Button>
)}
</div>
</TabPane>
<TabPane
style={{ margin: '0 10px 0 0' }}
Expand Down
10 changes: 8 additions & 2 deletions src/layouts/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
BarChartOutlined,
DesktopOutlined, ExpandOutlined,
DesktopOutlined,
ExpandOutlined,
FileOutlined,
PlayCircleOutlined,
PlusSquareFilled,
SettingOutlined,
TableOutlined
TableOutlined,
} from '@ant-design/icons';
import { Layout, Menu } from 'antd';
import React, { useState } from 'react';
Expand Down Expand Up @@ -59,6 +61,10 @@ function loadSidebarComponents(pathname, setShowModal) {
<Link to={`/projectSettings/${currentProject}`} />
Settings
</Menu.Item>
<Menu.Item icon={<PlayCircleOutlined />}>
<Link to={`/game/${currentProject}`} />
Game
</Menu.Item>
</>
);
}
Expand Down
26 changes: 20 additions & 6 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ app
});
ipcMain.handle('api:getProjectState', getProjectState);
ipcMain.handle('api:setProjectState', setProjectState);
ipcMain.handle('api:createNode', createNode);
ipcMain.handle('api:initializeProjectState', initializeProjectState);
})
.catch(console.log);
Expand Down Expand Up @@ -373,10 +374,18 @@ ipcMain.on('api:getNode', (event, nodeId) => {
event.returnValue = NodeService.getNodesWithQuery(currentLokiService, nodeId);
});

ipcMain.on(
'api:createNode',
(event, nodeType, nodeTitle, parentId, iterationId, trelloData, trelloAuth) => {
event.returnValue = NodeService.createNode(
const createNode = async (
event,
nodeType,
nodeTitle,
parentId,
iterationId,
trelloData,
trelloAuth,
) => {
try {
// Await the result of the createNode call
const result = await NodeService.createNode(
currentLokiService,
nodeType,
nodeTitle,
Expand All @@ -385,8 +394,13 @@ ipcMain.on(
trelloData,
trelloAuth,
);
},
);

console.log('Node created:', result);
return result;
} catch (error) {
console.error('Error creating node:', error);
}
};

ipcMain.on('api:deleteNode', (event, nodeId, parentId) => {
NodeService.deleteNode(currentLokiService, nodeId, parentId);
Expand Down
126 changes: 126 additions & 0 deletions src/pages/Game/Game.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import React, { Component } from 'react';
import { ipcRenderer } from 'electron';
import kaplay from 'kaplay';

import Layout from '../../layouts/App';

class SheetPage extends Component {
constructor(props) {
super(props);

this.currentProject = localStorage.getItem('currentProject');
this.trelloToken = localStorage.getItem('trelloToken');
this.trelloKey = `eeccec930a673bbbd5b6142ff96d85d9`;
this.authLink = `https://trello.com/1/authorize?expiration=30days&scope=read,write&response_type=token&key=${this.trelloKey}`;

this.state = {
lokiLoaded: false,
nodes: {},
};
}

componentDidMount() {
const newState = ipcRenderer.sendSync(
'api:initializeProjectState',
this.projectName,
);

this.setState({
...this.state,
...newState,
});
}

playGame = () => {
// Input handling and basic player movement

// Start kaboom
kaplay({
width: 640,
height: 640,
font: 'sans-serif',
canvas: document.querySelector('#mycanvas'),
background: [0, 0, 255],
});
setGravity(2400);
setBackground(0, 0, 0);

loadSprite(
'bean',
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAn5JREFUaIHdm7txAkEMhnUMBUAFEEPmcUgHhHRBQXThkA4IGTKIoQLoAEcw60PS6XkP/zNO7Nt/95O099hdV5Co2WTx9LS/PS5V1FhKhZt6QTlFBSHEJBOUkicAbugugEtZ4M3QUtjVbq32Pmz3quu14GpoCawFlJM0CFJ4FXQTcDQspqYASMDF0BxwG7B1UfBh0H0DLoXBN4E3QlPAXcOW0oKPOLMhAFPiqpOMxtCANXMczfTQgAF0Y/uIghWYe5R4gkX5Up6S+S2CxjrQvjVRPpS0/i9vNbQE2ALb5BnlLwVn797l4A7bfQgwNSju917fut7Q3C0+CpbzjAwoVkklH5lp6fy73s8h11jacX/nxj8C0H8TX+/n94+mjbYP63VU1bw40Uy3/TyuD9JaGVKxNzJK8+kS5tOluk3bopI39iz3SEEsAZJkm/LlKnU2WTxFmc4o9yZPSzVJfAGQ8qYaRYLXvaK8MR/sd6o5vdqt3QPMCqqm/djbgeSlQjog7jUywv8lE7SnQ42n9gtLKjd0prLeF0zP6aHrAzrj46Jv+veZxpI4vj0uVcQmXFsV4p3nt8elQjOtBWhzSkT0NQLI2/HvWlSAyDk99Bsat06W9pz++foO89qcjmFeAEWmPSXet00A12qop8SjsxOpP9BYtrue29rgSRb7w15OsBL3ZHtzOqLtI6bSB3R0tqnBR11fSrpPjd68PLuWmdNBux1E3ZxT9qejwa07pmpoAP9Zk+zNPq4P7hFsPnMiHRQ3sCxf90EbgG4OzHHighh6jgwg92ikRBEH5wCSjknW1bfzoekHYrPV6ingl7qEt34kDepkP0DMgkfqiklf/4fjF/Soc3nSQqqQAAAAAElFTkSuQmCC',
);

scene('nogamepad', () => {
add([
text('Gamepad not found.\nConnect a gamepad and press a button!', {
width: width() - 80,
align: 'center',
}),
pos(center()),
anchor('center'),
]);
onGamepadConnect(() => {
go('game');
});
});

scene('game', () => {
const player = add([
pos(center()),
anchor('center'),
sprite('bean'),
area(),
body(),
]);

// platform
add([
pos(0, height()),
anchor('botleft'),
rect(width(), 140),
area(),
body({ isStatic: true }),
]);

onGamepadButtonPress((b) => {
debug.log(b);
});

onGamepadButtonPress(['south', 'west'], () => {
player.jump();
});

onGamepadStick('left', (v) => {
player.move(v.x * 400, 0);
});

onGamepadDisconnect(() => {
go('nogamepad');
});
});

if (getGamepads().length > 0) {
go('game');
} else {
go('nogamepad');
}
};

render() {
const { lokiLoaded } = this.state;

return lokiLoaded ? (
<Layout>
<h1 style={{ fontSize: 50 }}>{this.currentProject}'s Game</h1>
<button onClick={this.playGame}>Play Game</button>
<canvas id="mycanvas" width="320" height="240" />
</Layout>
) : (
<Layout>
<h1>Loading...</h1>
</Layout>
);
}
}

export default SheetPage;
Loading

0 comments on commit 39b3a70

Please sign in to comment.