Skip to content

fix: Battletv , score #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/map-designer/src/Parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export class Parameters {

static mapTileHalfHeight = 200;

static mapTileOffsetX = 200;
static mapTileOffsetX = 250;

static mapTileOffsetY = 256;
static mapTileOffsetY = 260;

static totalCoins = 6000;

Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/scenes/TileMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export class TileMap extends Phaser.Scene {
onComplete: () => bombSprite.destroy(),
});
}
tower.healthBar.setHp(newTowerHp);
tower.setHp(newTowerHp);
troop.attack(tower.x, tower.y);
},
);
Expand Down
Binary file modified public/assets/tower1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/assets/tower2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/assets/tower3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/deltaMap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/BattleTV/BattleTV.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}

.automatch {
background-color: antiquewhite;
background-color: rgba(92, 129, 136, 0.37) !important;
}

.item .picholder {
Expand Down
17 changes: 12 additions & 5 deletions src/components/BattleTV/BattleTV.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ function getIcon(loggedInUser: User, match: Match) {
return styles.battlecardwin;
} else if (match.matchVerdict == Verdict.Player2) {
return styles.battlecardlose;
} else if (match.matchVerdict == Verdict.Success) {
return styles.battlecardwin;
} else if (match.matchVerdict == Verdict.Failure) {
return styles.battlecardlose;
}
} else {
// user is PLAYER2
Expand Down Expand Up @@ -110,12 +114,15 @@ function PaginatedItems() {
) : (
currentItems &&
currentItems.map((match: Match) => (
<div
className={styles.item + getMatchMode(match)}
key={match.id}
>
<div className={styles.item} key={match.id}>
<div
className={styles.item + ' ' + getIcon(loggedInUser, match)}
className={
styles.item +
' ' +
getIcon(loggedInUser, match) +
' ' +
getMatchMode(match)
}
>
<span className={styles.username}>
<div className={styles.picholder}>
Expand Down
186 changes: 76 additions & 110 deletions src/components/Editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Editor from './EditorTypes';
import styles from './style.module.css';
import { useRef, useEffect, useState } from 'react';
import { useRef, useEffect } from 'react';
import * as monaco from 'monaco-editor';
import {
MonacoLanguageClient,
Expand Down Expand Up @@ -57,7 +57,6 @@ buildWorkerDefinition(

export default function CodeEditor(props: Editor.Props): JSX.Element {
const divCodeEditor = useRef<HTMLDivElement>(null);
let editor: monaco.editor.IStandaloneCodeEditor;
const userCode: string =
props.page == 'Dashboard'
? useAppSelector(UserCode)
Expand All @@ -66,11 +65,6 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
const theme: string = useAppSelector(Theme);
const autocomplete: boolean = useAppSelector(Autocomplete);
const dispatch: React.Dispatch<unknown> = useAppDispatch();
const [workspace, setWorkspace] = useState<Editor.Workspace>({
filepath: '',
folderpath: '',
});
const [currWebsocket, setCurrWebSocket] = useState<WebSocket>();

const keyboardHandler = useAppSelector(KeyboardHandler);

Expand All @@ -94,9 +88,9 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
aliases: ['Java', 'java'],
});

function createLanguageClient(
const createLanguageClient = (
transports: MessageTransports,
): MonacoLanguageClient {
): MonacoLanguageClient => {
return new MonacoLanguageClient({
name: 'Code Editor Language Client',
clientOptions: {
Expand All @@ -112,49 +106,18 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
},
},
});
}

useEffect(() => {
if (!autocomplete) return;
const url = `${lspUrl}/${
props.language == 'c_cpp' ? 'cpp' : props.language
}`;
const wsClient = new WebSocket(url);
setCurrWebSocket(wsClient);
wsClient.onopen = () => {
const updater = {
operation: 'fileUpdate',
code: userCode,
};
wsClient.send(JSON.stringify(updater));

const filePathRequest = {
operation: 'getAbsPath',
};
wsClient.send(JSON.stringify(filePathRequest));
const socket = toSocket(wsClient);
const reader = new WebSocketMessageReader(socket);
reader.listen((message: Message) => {
const fileInfo = message as Message & Editor.Workspace;
setWorkspace({
filepath: fileInfo.filepath,
folderpath: fileInfo.folderpath,
});
reader.dispose();
});
};
return () => {
wsClient?.close(1000);
};
}, [props.language, autocomplete]);
};

useEffect(() => {
if (!divCodeEditor.current) return;
editor = monaco.editor.create(divCodeEditor.current, {
const createEditor = (
divref: HTMLDivElement,
workspace: Editor.Workspace | null,
websocket: WebSocket | null,
) => {
const editor = monaco.editor.create(divref, {
model: monaco.editor.createModel(
userCode,
language == 'c_cpp' ? 'cpp' : language,
monaco.Uri.parse(workspace.filepath),
monaco.Uri.parse(workspace != null ? workspace.filepath : ''),
),
fontSize: fontSize,
cursorStyle:
Expand All @@ -181,37 +144,13 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
enabled: true,
},
});

let languageClient: MonacoLanguageClient;
if (workspace.filepath != '' && currWebsocket != undefined) {
MonacoServices.install({
workspaceFolders: [
{
uri: Uri.parse(workspace.folderpath),
name: 'parse folder',
index: 1,
},
],
});

const socket = toSocket(currWebsocket);
const reader = new WebSocketMessageReader(socket);
const writer = new WebSocketMessageWriter(socket);
languageClient = createLanguageClient({
reader,
writer,
});
languageClient.start();
reader.onClose(() => languageClient.stop());
}

editor.onDidChangeModelContent(() => {
if (currWebsocket != undefined) {
if (websocket != null) {
const currUpdater = {
operation: 'fileUpdate',
code: editor.getValue(),
};
currWebsocket.send(JSON.stringify(currUpdater));
websocket.send(JSON.stringify(currUpdater));
}
const codeNlanguage: CodeAndLanguage = {
currentUserCode: editor.getValue(),
Expand Down Expand Up @@ -263,46 +202,73 @@ export default function CodeEditor(props: Editor.Props): JSX.Element {
},
);

return editor;
};

useEffect(() => {
if (!divCodeEditor.current) return;
let languageClient: MonacoLanguageClient;
let editor: monaco.editor.IStandaloneCodeEditor;
let wsClient: WebSocket;
if (autocomplete) {
const url = `${lspUrl}/${
props.language == 'c_cpp' ? 'cpp' : props.language
}`;
wsClient = new WebSocket(url);
wsClient.onopen = () => {
const updater = {
operation: 'fileUpdate',
code: userCode,
};
wsClient.send(JSON.stringify(updater));
const filePathRequest = {
operation: 'getAbsPath',
};
wsClient.send(JSON.stringify(filePathRequest));
const socket = toSocket(wsClient);
const filePathMessageReader = new WebSocketMessageReader(socket);
filePathMessageReader.listen((message: Message) => {
const fileInfo = message as Message & Editor.Workspace;
const workspace: Editor.Workspace = {
filepath: fileInfo.filepath,
folderpath: fileInfo.folderpath,
};
filePathMessageReader.dispose();
editor = createEditor(
divCodeEditor.current as HTMLDivElement,
workspace,
wsClient,
);
MonacoServices.install({
workspaceFolders: [
{
uri: Uri.parse(workspace.folderpath),
name: 'Workspace',
index: 1,
},
],
});
const newSocket = toSocket(wsClient);
const writer = new WebSocketMessageWriter(newSocket);
const reader = new WebSocketMessageReader(newSocket);
languageClient = createLanguageClient({
reader,
writer,
});
languageClient.start();
reader.onClose(() => languageClient.stop());
});
};
} else {
editor = createEditor(divCodeEditor.current, null, null);
}
return () => {
languageClient?.stop();
monaco.editor.getModels().forEach(model => model.dispose());
editor?.dispose();
wsClient?.close(1000);
};
}, [
fontSize,
theme,
language,
keyboardHandler,
props.page,
workspace,
currWebsocket,
]);

const userCodeChangeHandler = () => {
const codeNlanguage: CodeAndLanguage = {
currentUserCode: editor.getValue(),
currentUserLanguage: language,
};
dispatch(updateUserCode(codeNlanguage));
};

const dailyChallengeCodechange = () => {
const codeNlanguage: CodeAndLanguage = {
currentUserCode: editor.getValue(),
currentUserLanguage: language,
};
dispatch(changeDcCode(codeNlanguage));
};
}, [fontSize, theme, language, keyboardHandler, props.page, autocomplete]);

return (
<div
className={styles.Editor}
ref={divCodeEditor}
onChange={
props.page == 'Dashboard'
? userCodeChangeHandler
: dailyChallengeCodechange
}
></div>
);
return <div className={styles.Editor} ref={divCodeEditor}></div>;
}
2 changes: 1 addition & 1 deletion src/components/Home/AboutGame/AboutGame.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styles from './AboutGame.module.css';
import { Container, Row, Col } from 'react-bootstrap';
import mapimg from './../../../../src/assets/renderer.jpeg';
import mapimg from './../../../../src/assets/deltaMap.png';

export default function AboutGame(): JSX.Element {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Leaderboard/DailyLeaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function PaginatedItems() {
{' ' + row.userName.substring(0, 10)}
</div>
</td>
<td className={styles.score}>{row.score}</td>
<td className={styles.score}>{row.score.toFixed(2)}</td>
</tr>
))}
</tbody>
Expand Down
Loading