Skip to content
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

Enable battletrack #79

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "battletrack"]
path = client/battletrack
url = [email protected]:n8kim1/battletrack.git
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"tauri-build": "npm run build && npm run tauri-pack",
"electron-watch": "concurrently --kill-others \"npm run watch\" \"wait-on http://localhost:3000 && electron .\"",
"electron-pack": "cross-env USE_HARD_LINKS=false CSC_IDENTITY_AUTO_DISCOVERY=false NODE_ENV=production electron-builder build --publish never",
"electron-build": "npm run build && npm run electron-pack"
"electron-build": "npm run build && npm run electron-pack",
"battletrack-watch": "cross-env NODE_ENV=development webpack serve --config webpack-battletrack.config.js --mode development --env dev"
},
"build": {
"asar": false,
Expand Down
41 changes: 22 additions & 19 deletions client/src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ import { ConfigPage } from '../../client-config'
import { UpdateWarning } from './update-warning'
import Game from '../../playback/Game'

export const fetchTournamentPage = (tournamentSource: string, rawGames: JsonTournamentGame[]) => {
fetch(tournamentSource)
.then((response) => response.text())
.then((text) => {
const data = JSON.parse(text)
const newGames = data.results as JsonTournamentGame[]
rawGames.push(...newGames)

if (data.next) {
fetchTournamentPage(data.next, rawGames)
}
})
}

export const Sidebar: React.FC = () => {
const { width, height } = useWindowDimensions()
const [page, setPage] = usePage()
Expand All @@ -40,32 +54,21 @@ export const Sidebar: React.FC = () => {
const [localTournament] = useSearchParamBool('localTournament', false)

const [tournamentSource, setTournamentSource] = useSearchParamString('tournamentSource', '')
const fetchTournamentPage = (tournamentSource: string, rawGames: JsonTournamentGame[]) => {
fetch(tournamentSource)
.then((response) => response.text())
.then((text) => {
const data = JSON.parse(text)
const newGames = data.results as JsonTournamentGame[]
rawGames.push(...newGames)

if (data.next) {
fetchTournamentPage(data.next, rawGames)
} else {
context.setState((prevState) => ({
...prevState,
tournament: new Tournament(rawGames),
loadingRemoteContent: ''
}))
}
})
const loadTournamentPage = (tournamentSource: string, rawGames: JsonTournamentGame[]) => {
fetchTournamentPage(tournamentSource, rawGames)
context.setState((prevState) => ({
...prevState,
tournament: new Tournament(rawGames),
loadingRemoteContent: ''
}))
}
React.useEffect(() => {
if (tournamentSource) {
context.setState((prevState) => ({
...prevState,
loadingRemoteContent: 'tournament'
}))
fetchTournamentPage(tournamentSource, [])
loadTournamentPage(tournamentSource, [])
setPage(PageType.TOURNAMENT)
}
}, [tournamentSource])
Expand Down
10 changes: 6 additions & 4 deletions client/src/playback/Match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export default class Match {
/**
* Change the rounds current turn to the current turn + delta.
*/
public stepTurn(delta: number, rerender: boolean = true): void {
this.jumpToTurn(this.currentTurn.turnNumber + delta, rerender)
public stepTurn(delta: number, rerender: boolean = true, headless: boolean = false): void {
this.jumpToTurn(this.currentTurn.turnNumber + delta, rerender, headless)
}

/**
Expand All @@ -175,7 +175,7 @@ export default class Match {
/**
* Sets the current turn to the turn at the given turn number.
*/
public jumpToTurn(turnNumber: number, rerender: boolean = true): void {
public jumpToTurn(turnNumber: number, rerender: boolean = true, headless: boolean = false): void {
if (!this.game.playable) return

turnNumber = Math.max(0, Math.min(turnNumber, this.deltas.length))
Expand Down Expand Up @@ -209,7 +209,9 @@ export default class Match {
}

this.currentTurn = updatingTurn
publishEvent(EventType.TURN_PROGRESS, {})
if (!headless) {
publishEvent(EventType.TURN_PROGRESS, {})
}
if (rerender) this.rerender()
}
}
69 changes: 69 additions & 0 deletions client/webpack-battletrack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')

module.exports = (env) => {
const development = env.dev

var config = {
entry: './battletrack/src/app.tsx',
target: 'web',
devtool: development ? 'source-map' : undefined,
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
assert: require.resolve('assert/')
}
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: [/node_modules/, /src-tauri/, /packaged-client/],
loader: 'ts-loader'
},
{
test: /\.css$/,
exclude: [/node_modules/, /src-tauri/, /packaged-client/],
use: ['style-loader', 'css-loader', 'postcss-loader']
},
{
test: /\.(png|jpg|jpeg|gif|svg|ttf|otf|woff|woff2|eot)$/,
exclude: [/node_modules/, /src-tauri/, /packaged-client/],
loader: 'url-loader'
}
]
},
devServer: {
compress: true,
hot: true,
port: 3000,
static: {
directory: path.join(__dirname, '/src')
}
},
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
favicon: './icons/icon.ico'
}),
new webpack.LoaderOptionsPlugin({
minimize: !development,
debug: development
}),
new webpack.ProvidePlugin({
process: 'process/browser'
}),
new CopyPlugin({
patterns: [{ from: 'src/static', to: 'static' }]
})
]
}

return config
}