Skip to content

Commit

Permalink
Боже, хочу сдохнуть, а не вот это вот всё
Browse files Browse the repository at this point in the history
В пизду, я не буду доделывать этот говнокод
  • Loading branch information
JoCat committed Jul 11, 2021
1 parent 0f20fd9 commit 4233c26
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 49 deletions.
2 changes: 1 addition & 1 deletion TODOLIST.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- [ ] настройка [webpack loaders](https://webpack.js.org/loaders/) [немного в electron-webpack](https://github.com/electron-userland/electron-webpack/blob/master/packages/electron-webpack/src/targets/RendererTarget.ts)
- [ ] [обфускация](https://github.com/javascript-obfuscator/javascript-obfuscator)
- [ ] уменmьшение размера электрона (пересборка?)
- [ ] уменьшение размера электрона (пересборка?)

---

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurora-launcher",
"version": "0.0.2-dev",
"version": "0.0.2",
"description": "Launcher for Minecraft",
"main": "build/main/index.js",
"scripts": {
Expand Down
43 changes: 30 additions & 13 deletions src/main/game/Starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Request } from "aurora-api"
import { StorageHelper } from "../helpers/StorageHelper"
import { HttpHelper } from "../helpers/HttpHelper"
import pMap from "p-map"
import { LogHelper } from "main/helpers/LogHelper"
const api = require("@config").api

interface ClientArgs {
Expand Down Expand Up @@ -43,7 +42,11 @@ export default class Starter {
}

async startChain(event: IpcMainEvent, clientArgs: ClientArgs) {
await this.hash(event, clientArgs)
try {
await this.hash(event, clientArgs)
} catch (error) {
return event.reply("stopGame")
}
await this.start(event, clientArgs)
}

Expand All @@ -59,16 +62,24 @@ export default class Starter {
this.gameLauncherLegacy(gameArgs, clientArgs, clientDir, assetsDir)
}

const librariesDirectory = path.resolve(clientDir, 'libraries')
const nativesDirectory = path.resolve(clientDir, 'natives')

const classpath = Starter.scanDir(librariesDirectory)
classpath.push(path.resolve(clientDir, 'minecraft.jar'))
// if (clientArgs.classPath !== undefined) {
// clientArgs.classPath.forEach((fileName) => {
// classpath.push(path.resolve(clientDir, fileName))
// })
// }
const librariesDirectory = path.join(clientDir, "libraries")
const nativesDirectory = path.join(clientDir, "natives")

const classpath: string[] = []
if (clientArgs.classPath !== undefined) {
clientArgs.classPath.forEach(fileName => {
const filePath = path.join(clientDir, fileName)
if (fs.statSync(filePath).isDirectory()) {
classpath.push(...Starter.scanDir(librariesDirectory))
} else {
classpath.push(filePath)
}
})
} else {
App.window.sendEvent("textToConsole", "classPath is empty")
console.error("classPath is empty")
return
}

const jvmArgs = []

Expand Down Expand Up @@ -116,7 +127,13 @@ export default class Starter {

const fileHashes = ((hashes as Request).data as {
hashes: any[]
}).hashes.sort((a, b) => b.size - a.size)
}).hashes
if (!fileHashes) {
App.window.sendEvent("textToConsole", `${type} not found`)
console.error(`${type} not found`)
throw undefined
}
fileHashes.sort((a, b) => b.size - a.size)
const totalSize = fileHashes.reduce((p, c) => p + c.size, 0)
let loaded = 0

Expand Down
Binary file modified src/renderer/runtime/assets/images/background.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 src/renderer/runtime/assets/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/renderer/runtime/assets/sass/main.sass
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ button
border-radius: 2px

::-webkit-scrollbar-corner
display: none
display: none

[disabled]
opacity: 0.75
4 changes: 2 additions & 2 deletions src/renderer/runtime/components/TitleBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default Vue.extend({
},
title: {
show: true,
text: 'AuroraLauncher dev build v0.0.1'
text: 'AuroraLauncher dev build v0.0.2'
},
user: {
show: false,
Expand Down Expand Up @@ -130,4 +130,4 @@ export default Vue.extend({
})
}
})
</script>
</script>
57 changes: 37 additions & 20 deletions src/renderer/runtime/scenes/ServerPanel.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="block-center">
<h1>Привет {{username}}</h1>
<h2>Выбранный сервер: {{selectedServer.title}}</h2>
<button @click="startGame">Играть</button>
<h1>Привет {{ username }}</h1>
<h2>Выбранный сервер: {{ selectedServer.title }}</h2>
<button @click="startGame" :disabled="gameStarted">Играть</button>
<div class="progress" v-show="showProgress">
<div class="progress-line"></div>
</div>
Expand Down Expand Up @@ -51,47 +51,64 @@
</style>

<script lang="ts">
import Vue from 'vue'
import Game from '@scripts/Game'
import ServerPanel from '@scripts/ServerPanel'
import { Launcher } from '@Launcher'
import Vue from "vue"
import Game from "@scripts/Game"
import ServerPanel from "@scripts/ServerPanel"
import { Launcher } from "@Launcher"
export default Vue.extend({
data() {
return {
console: '',
console: "",
showProgress: false,
selectedServer: JSON.parse(localStorage.getItem('selectedProfile') as string),
selectedServer: JSON.parse(
localStorage.getItem("selectedProfile") as string
),
selectedProfile: {},
username: localStorage.getItem('username')
username: localStorage.getItem("username"),
gameStarted: false
}
},
methods: {
startGame() {
Game.start(this.selectedProfile, this.textToConsole, this.progress)
this.gameStarted = true
Game.start(
this.selectedProfile,
this.textToConsole,
this.progress,
() => (this.gameStarted = false)
)
},
textToConsole(string: string) {
this.console += string
const consoleEl = document.querySelector('.console')!
const consoleEl = document.querySelector(".console")!
// Если не оборачивать в setImmediate, то оно прокручивает не до конца
setImmediate(() => {consoleEl.scrollTop = consoleEl.scrollHeight})
setImmediate(() => {
consoleEl.scrollTop = consoleEl.scrollHeight
})
},
progress(data: any) {
const progressEl = document.querySelector('.progress-line') as HTMLElement
const progressEl = document.querySelector(
".progress-line"
) as HTMLElement
const total = data.total
const loaded = data.loaded
const percent = (loaded / total * 100)
const percent = (loaded / total) * 100
progressEl.style.width = percent + "%"
this.showProgress = percent < 100
const infoEl = document.querySelector('.info') as HTMLElement
infoEl.innerHTML = `Загружено ${bytesToSize(loaded)} из ${bytesToSize(total)}`
const infoEl = document.querySelector(".info") as HTMLElement
infoEl.innerHTML = `Загружено ${bytesToSize(
loaded
)} из ${bytesToSize(total)}`
}
},
async mounted() {
this.selectedProfile = JSON.parse(await ServerPanel.getProfile(this.selectedServer.profileUUID))
Launcher.$emit('showHistoryBackBtn')
this.selectedProfile = JSON.parse(
await ServerPanel.getProfile(this.selectedServer.profileUUID)
)
Launcher.$emit("showHistoryBackBtn")
}
})
Expand All @@ -102,4 +119,4 @@ function bytesToSize(bytes: number): string {
if (i === 0) return `${bytes} ${sizes[i]})`
return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`
}
</script>
</script>
28 changes: 17 additions & 11 deletions src/renderer/scripts/Game.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import { ipcRenderer } from 'electron'
import { ipcRenderer } from "electron"

export default class Game {
/**
* Start the game
* @param csl Print to console wrapper
*/
static async start(profile: any, csl: (string: string) => void, progress: (data: object) => void) {
ipcRenderer.send('startGame', {
static async start(
profile: any,
csl: (string: string) => void,
progress: (data: object) => void,
callback: () => void
) {
ipcRenderer.send("startGame", {
...profile,
username: localStorage.getItem('username'),
userUUID: localStorage.getItem('userUUID'),
accessToken: localStorage.getItem('accessToken'),
username: localStorage.getItem("username"),
userUUID: localStorage.getItem("userUUID"),
accessToken: localStorage.getItem("accessToken")
})

ipcRenderer.on('textToConsole', (_e, string: string) => {
ipcRenderer.on("textToConsole", (_e, string: string) => {
csl(string)
})

ipcRenderer.on('loadProgress', (_e, data: object) => {
ipcRenderer.on("loadProgress", (_e, data: object) => {
progress(data)
})

ipcRenderer.once('stopGame', () => {
ipcRenderer.removeAllListeners('textToConsole')
ipcRenderer.once("stopGame", () => {
ipcRenderer.removeAllListeners("textToConsole")
callback()
})
}
}
}

0 comments on commit 4233c26

Please sign in to comment.