Skip to content

Commit

Permalink
Merge pull request #40 from Lux-AI-Challenge/v3.0.x
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
StoneT2000 authored Aug 23, 2021
2 parents 44a236a + da1b3e2 commit f1e44ac
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 50 deletions.
34 changes: 17 additions & 17 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lux-viewer-2021",
"version": "2.2.0",
"version": "3.0.0",
"description": "",
"author": "Lux AI challenge",
"main": "index.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"@lux-ai/2021-challenge": "^2.2.0",
"@lux-ai/2021-challenge": "^3.0.0",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.11.2",
"@types/classnames": "^2.2.10",
Expand Down
59 changes: 35 additions & 24 deletions src/components/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'phaser';
import React, { KeyboardEvent, useEffect, useState } from 'react';
import React, { KeyboardEvent, useEffect, useState, version } from 'react';
import MainScene, { Frame, FrameTileData } from '../scenes/MainScene';
import { createGame } from '../game';
import {
Expand All @@ -25,6 +25,7 @@ import UploadSVG from '../icons/upload.svg';
import { parseReplayData } from '../utils/replays';
import clientConfigs from './configs.json';
import WarningsPanel from './WarningsPanel';
// import debug_replay from './replay.json';
export type GameComponentProps = {
// replayData?: any;
};
Expand All @@ -47,6 +48,8 @@ export const GameComponent = () => {
const [running, setRunning] = useState(false);
const [useKaggleReplay, setUseKaggleReplay] = useState(true);
const [playbackSpeed, _setPlaybackSpeed] = useState(1);
const [replayVersion, setReplayVersion] = useState('');
const [warningMessage, setWarningMessage] = useState('');
const setPlaybackSpeed = (speed: number) => {
if (speed >= 0.5 && speed <= 32) {
_setPlaybackSpeed(speed);
Expand Down Expand Up @@ -235,7 +238,6 @@ export const GameComponent = () => {
} else if (turn % cycleLength < 5 && turn > 5) {
idx = 6 - ((turn % cycleLength) + 2);
}
console.log({ canvasWrapper });
canvasWrapper.style.transition = `background-color linear ${
1 / main.speed
}s`;
Expand All @@ -254,28 +256,24 @@ export const GameComponent = () => {
};

/** load game given json replay data */
const loadGame = (jsonReplayData: any, skipVersionCheck = false) => {
if (!skipVersionCheck) {
const loadGame = (jsonReplayData: any) => {
let versionMisMatch = false;
let versionvals = ['x', 'x'];
setReplayVersion(jsonReplayData.version);
if (jsonReplayData.version !== undefined) {
versionvals = jsonReplayData.version.split('.');
if (
jsonReplayData.version === undefined ||
jsonReplayData.version !== clientConfigs.version
versionvals[0] !== clientConfigs.version[0] ||
versionvals[1] !== clientConfigs.version[2]
) {
if (jsonReplayData.version === undefined) {
alert('No version associated with replay data, cannot load');
return;
}
const versionvals = jsonReplayData.version.split('.');
if (
versionvals[0] !== clientConfigs.version[0] ||
versionvals[1] !== clientConfigs.version[2]
) {
alert(
`Replay file works on version ${versionvals[0]}.${versionvals[1]}.x but client is on version ${clientConfigs.version}. The visualizer will most likely not work correctly. Download an older visualizer here to watch the replay: https://github.com/Lux-AI-Challenge/LuxViewer2021/releases`
);
return;
}
versionMisMatch = true;
}
}
if (versionMisMatch) {
let warningMessage = `Replay file works on version ${versionvals[0]}.${versionvals[1]}.x but client is on version ${clientConfigs.version}. The visualizer will not be able to parse this replay file. Download an older visualizer with version ${versionvals[0]}.${versionvals[1]}.x here to watch the replay: https://github.com/Lux-AI-Challenge/LuxViewer2021/releases`;
setWarningMessage(warningMessage);
return;
}
if (game) {
game.destroy(true, false);
}
Expand Down Expand Up @@ -346,7 +344,7 @@ export const GameComponent = () => {
console.log('post message:');
console.log(event.data);
replay = parseReplayData(replay);
loadGame(replay, true);
loadGame(replay);
const el = document.getElementsByTagName('html');
if (window.innerWidth * 0.65 <= 768) {
el[0].style.fontSize = '6pt';
Expand All @@ -372,7 +370,7 @@ export const GameComponent = () => {
} else if (window.innerWidth <= 1280) {
el[0].style.fontSize = '8pt';
}
// loadGame(debug_replay);
// loadGame(parseReplayData(debug_replay));
}, []);
useEffect(() => {
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
Expand Down Expand Up @@ -447,7 +445,7 @@ export const GameComponent = () => {
<div className="Game">
<ThemeProvider theme={theme}>
<div id="content"></div>
{!isReady && (
{!isReady && warningMessage === '' && (
<div className="upload-no-replay-wrapper">
<p>Welcome to the Lux AI Season 1 Visualizer</p>
<div>
Expand All @@ -473,8 +471,21 @@ export const GameComponent = () => {
</div>
</div>
)}
{warningMessage !== '' && (
<div className="upload-no-replay-wrapper">
<p>{warningMessage}</p>
</div>
)}

<div id="version-number">
<strong>Version: </strong>
{replayVersion && (
<>
<strong>Replay Version: </strong>
{replayVersion}
<br></br>
</>
)}
<strong>Client Version: </strong>
{clientConfigs.version}
</div>
{isReady && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/configs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2.2.0"
"version": "3.0.0"
}
10 changes: 7 additions & 3 deletions src/components/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
.Game .upload-icon-no-replay {
width: 3rem;
}
.Game .upload-no-replay-wrapper > p {
padding-left: 2rem;
padding-right: 2rem;
}
.Game .upload-no-replay-wrapper > div > .upload-btn .upload-text {
margin-right: 1rem;
}
Expand Down Expand Up @@ -112,8 +116,8 @@
background-color: rgba(50, 61, 52, 0.1);
padding: 0.5rem;
border-radius: 1rem;
height: 1.5rem;
line-height: 1.5rem;
/* height: 1.5rem; */
/* line-height: 1.5rem; */
}

.Game .debug-sidetext {
Expand All @@ -139,7 +143,7 @@
.Game .warnings-button {
position: absolute;
top: 1rem;
right: 10rem;
right: 12rem;
background-color: rgba(255, 255, 255, 0.25);
border-radius: 1rem;
color: white;
Expand Down
3 changes: 2 additions & 1 deletion src/scenes/MainScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,6 @@ class MainScene extends Phaser.Scene {
if (!f) {
return;
}
console.log(`Errors on turn ${turn}`, f.errors);

const dayLength = this.luxgame.configs.parameters.DAY_LENGTH;
const cycleLength =
Expand Down Expand Up @@ -1379,6 +1378,8 @@ class MainScene extends Phaser.Scene {
lastPointerPosition = null;

update(time: number, delta: number) {
// console.log('drawing stuff');
// console.log(1 / (delta * 1e-3));
const panvelocity = 32 * Math.sqrt(this.overallScale);
const wkey = this.input.keyboard.addKey('W');
if (wkey.isDown) {
Expand Down
8 changes: 6 additions & 2 deletions src/utils/replays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ export const parseReplayData = (rawReplayData: any) => {
);
commands.push(turnCommands);
});
let width = rawReplayData.configuration.width;
let height = rawReplayData.configuration.height;
const replay = {
allCommands: commands.slice(1), // slice 1 to remove empty first entry that represents the "observation"
mapType: rawReplayData.configuration.mapType,
width: width === -1 ? undefined : width,
height: height === -1 ? undefined : height,
seed: parseInt(rawReplayData.configuration.seed),
teamDetails: [
{
name: 'team-1',
name: 'team 0',
tournamentID: '',
},
{
name: 'team-2',
name: 'team 1',
tournamentID: '',
},
],
Expand Down

0 comments on commit f1e44ac

Please sign in to comment.