Skip to content

Commit

Permalink
fix #77
Browse files Browse the repository at this point in the history
  • Loading branch information
izure committed May 12, 2021
1 parent dcaa584 commit 470d895
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Main/IPC/GameProject/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function handler(directoryPath: string, config: Engine.GameProject.
const projectDirName = parseProperty(PROJECT_DIRECTORY_NAME, config)
const projectDirPath = path.resolve(directoryPath, projectDirName)

const projectEnsure = await ensureProject(projectDirPath, config)
const projectEnsure = await ensureProject(projectDirPath, config, false)
if (!projectEnsure.success) {
return projectEnsure as Engine.GameProject.CreateProjectFail
}
Expand Down
13 changes: 7 additions & 6 deletions src/Main/IPC/GameProject/ensureProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ interface FileWriteQueue {
content: string|((path?: string) => Promise<void>)
}

async function ensureRequireModules(projectDirPath: string): Promise<Engine.ModuleSystem.InstallSuccess|Engine.ModuleSystem.InstallFail> {
async function ensureRequireModules(projectDirPath: string, forceUpdate: boolean = false): Promise<Engine.ModuleSystem.InstallSuccess|Engine.ModuleSystem.InstallFail> {
try {
const command = forceUpdate ? 'npm update' : 'npm i'
const spawner = new ProcessSpawner({ shell: true, cwd: projectDirPath })
await spawner.spawn('npm i', { writeStream: writeToRenderer('ensure-require-modules') })
await spawner.spawn(command, { writeStream: writeToRenderer('ensure-require-modules') })
} catch(reason) {
return {
success: false,
Expand Down Expand Up @@ -194,7 +195,7 @@ async function ensureBaseFile(projectDirPath: string, config: Engine.GameProject
}
}

export async function handler(directoryPath: string, config: Engine.GameProject.Config): Promise<Engine.GameProject.CreateProjectSuccess|Engine.GameProject.CreateProjectFail> {
export async function handler(directoryPath: string, config: Engine.GameProject.Config, forceUpdate: boolean): Promise<Engine.GameProject.CreateProjectSuccess|Engine.GameProject.CreateProjectFail> {
// 디렉토리 생성하기
const dirs = [
path.resolve(directoryPath, PROJECT_EXTEND_DIRECTORY_NAME),
Expand Down Expand Up @@ -230,7 +231,7 @@ export async function handler(directoryPath: string, config: Engine.GameProject.
}

// 종속 모듈 설치
const moduleInstall = await ensureRequireModules(directoryPath)
const moduleInstall = await ensureRequireModules(directoryPath, forceUpdate)
if (!moduleInstall.success) {
return moduleInstall as Engine.GameProject.CreateProjectFail
}
Expand All @@ -245,7 +246,7 @@ export async function handler(directoryPath: string, config: Engine.GameProject.
}

export function ipc(): void {
ipcMain.handle('ensure-project', async (e: IpcMainInvokeEvent, directoryPath: string, config: Engine.GameProject.Config): Promise<Engine.GameProject.CreateProjectSuccess|Engine.GameProject.CreateProjectFail> => {
return await handler(directoryPath, config)
ipcMain.handle('ensure-project', async (e: IpcMainInvokeEvent, directoryPath: string, config: Engine.GameProject.Config, forceUpdate: boolean): Promise<Engine.GameProject.CreateProjectSuccess|Engine.GameProject.CreateProjectFail> => {
return await handler(directoryPath, config, forceUpdate)
})
}
38 changes: 20 additions & 18 deletions src/Renderer/components/Manager/Restructure/Main.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<template>
<v-card flat :loading="true">
<v-card-title>프로젝트 재구성 중 ( ╯°□°)╯ ┻━━┻</v-card-title>
<v-card-subtitle>게임 엔진 버전에 맞지 않거나 일부 파일이 누락된 오류를 바로 잡습니다.</v-card-subtitle>
<v-card-text>
<p>
일반적으로 이 작업은 프로젝트를 열었을 때, 자동으로 진행됩니다.
<br>
이 작업은 게임을 빌드할 시 오류가 없도록 도와줄 것입니다.
</p>
<p>
하지만 모든 오류 해결을 보장해준다는 의미는 아닙니다.
<br>
프로젝트 디렉토리의 구조를 임의로 변경하지 마십시오. 어디까지나 관리부주의는 사용자의 책임에 있습니다.
</p>
<shell-channel-component channel="ensure-require-modules" />
</v-card-text>
</v-card>
<v-card flat :loading="true">
<v-card-title>프로젝트 재구성 중 ( ╯°□°)╯ ┻━━┻</v-card-title>
<v-card-subtitle>게임 엔진 버전에 맞지 않거나 일부 파일이 누락된 오류를 바로 잡습니다.</v-card-subtitle>
<v-card-text>
<p>
일반적으로 이 작업은 프로젝트를 열었을 때 자동으로 진행되지만, 성능을 위해 일부 작업을 무시합니다.
<br>
재구성은 무시된 작업까지 강제로 수행합니다.
<br>
이 작업은 몇 분이 걸릴 수 있습니다.
</p>
<p>
하지만 모든 오류 해결을 보장해준다는 의미는 아닙니다.
<br>
프로젝트 디렉토리의 구조를 임의로 변경하지 마십시오. 어디까지나 관리부주의는 사용자의 책임에 있습니다.
</p>
<shell-channel-component channel="ensure-require-modules" />
</v-card-text>
</v-card>
</template>

<script lang="ts">
Expand Down Expand Up @@ -48,7 +50,7 @@ export default class RestructureComponent extends Vue {
}
private async restructureProject(config: Engine.GameProject.Config): Promise<Engine.GameProject.CreateProjectSuccess|Engine.GameProject.CreateProjectFail> {
return await ipcRenderer.invoke('ensure-project', this.cwd, config)
return await ipcRenderer.invoke('ensure-project', this.cwd, config, true)
}
async created(): Promise<void> {
Expand Down
5 changes: 4 additions & 1 deletion src/Template/Game/BASE_ACTOR.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Phaser from 'phaser'
import { Actor } from '@eriengine/plugin-actor'

import BaseScene from '@/BaseScene'

{{ DATA_LISTS }}
{{ STORAGE_LISTS }}

Expand Down Expand Up @@ -38,8 +40,9 @@ interface ActorStorage {
export default abstract class BaseActor extends Actor {

protected __scripts: Map<string, ScriptCallback[]> = new Map
scene!: BaseScene

constructor(scene: Phaser.Scene, x: number, y: number, texture: string|Phaser.Textures.Texture, frame?: string|number) {
constructor(scene: BaseScene, x: number, y: number, texture: string|Phaser.Textures.Texture, frame?: string|number) {
super(scene, x, y, texture, frame)
this.attachCollideEvent()
this.generateSkill(Skills)
Expand Down
24 changes: 12 additions & 12 deletions src/Template/Game/BASE_SCENE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export default class BaseScene extends Phaser.Scene {

private static ApplicationId: string = '{{ APPLICATION_ID }}'

protected actor!: ActorPlugin
protected isometric!: IsometricScenePlugin
protected cursor!: IsometricCursorPlugin
protected select!: IsometricSelectPlugin
protected dialogue!: DialoguePlugin
protected modal!: ModalPlugin
protected fow!: FogOfWarPlugin
actor!: ActorPlugin
isometric!: IsometricScenePlugin
cursor!: IsometricCursorPlugin
select!: IsometricSelectPlugin
dialogue!: DialoguePlugin
modal!: ModalPlugin
fow!: FogOfWarPlugin

protected __scripts: Map<string, ScriptCallback[]> = new Map
protected __map: SceneMap = { side: 2000, walls: [], floors: [] }
Expand Down Expand Up @@ -239,7 +239,7 @@ export default class BaseScene extends Phaser.Scene {
* @param key 게임 데이터를 저장할 키 값입니다.
* @param data 저장할 게임 데이터입니다.
*/
protected async setSaveData(key: string, data: Types.Json): Promise<SaveData> {
async setSaveData(key: string, data: Types.Json): Promise<SaveData> {
key = this.saveKey(key)
const date: number = Date.now()
const thumbnail: string = await this.createThumbnail()
Expand Down Expand Up @@ -284,7 +284,7 @@ export default class BaseScene extends Phaser.Scene {
* 해당 키에 게임 데이터가 저장되어있는지 여부를 반환합니다.
* @param key 게임 데이터를 저장할 키 값입니다.
*/
protected async hasSaveData(key: string): Promise<boolean> {
async hasSaveData(key: string): Promise<boolean> {
key = this.saveKey(key)
const item: unknown = await localforage.getItem(key)
if (!this.isSaveData(item)) {
Expand All @@ -297,7 +297,7 @@ export default class BaseScene extends Phaser.Scene {
* 저장된 게임 데이터를 반환합니다. 저장된 값이 없다면 에러를 발생시킵니다.
* @param key 게임 데이터를 저장하는데 사용된 키 값입니다.
*/
protected async getSaveData(key: string): Promise<SaveData> {
async getSaveData(key: string): Promise<SaveData> {
key = this.saveKey(key)
const savedata: unknown = await localforage.getItem(key)
if (savedata === null) {
Expand All @@ -313,15 +313,15 @@ export default class BaseScene extends Phaser.Scene {
* 저장된 게임 데이터를 삭제합니다.
* @param key 게임 데이터를 저장하는데 사용된 키 값입니다.
*/
protected async removeSaveData(key: string): Promise<void> {
async removeSaveData(key: string): Promise<void> {
key = this.saveKey(key)
await localforage.removeItem(key)
}

/**
* 저장된 모든 게임 데이터를 삭제합니다.
*/
protected async clearSaveData(): Promise<void> {
async clearSaveData(): Promise<void> {
const keys: string[] = await this.saveKeys()
for (const key of keys) {
this.removeSaveData(key)
Expand Down

0 comments on commit 470d895

Please sign in to comment.