Skip to content

Commit

Permalink
add asset appender
Browse files Browse the repository at this point in the history
  • Loading branch information
izure1 committed Dec 21, 2021
1 parent f03b68a commit c19b2fa
Show file tree
Hide file tree
Showing 19 changed files with 1,157 additions and 116 deletions.
Binary file added build/additional/FreeAssets/Kenny.zip
Binary file not shown.
664 changes: 601 additions & 63 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eriengine",
"version": "1.0.0-alpha.31",
"version": "1.0.0-alpha.32",
"private": true,
"scripts": {
"lint": "vue-cli-service lint",
Expand All @@ -23,9 +23,11 @@
"@eriengine/plugin-spatial-audio": "^1.0.2",
"@vue/composition-api": "^1.4.1",
"add-filename-increment": "^1.0.0",
"adm-zip": "^0.5.9",
"an-array-of-english-words": "2.0.0",
"animejs": "^3.2.1",
"ansi-to-html": "^0.6.14",
"archiver": "^5.3.0",
"betterbacks": "0.0.0-beta.1",
"chokidar": "^3.5.2",
"command-exists": "^1.2.9",
Expand Down Expand Up @@ -66,7 +68,9 @@
},
"devDependencies": {
"@mdi/font": "^5.8.55",
"@types/adm-zip": "^0.4.34",
"@types/animejs": "^3.1.2",
"@types/archiver": "^5.1.1",
"@types/cross-spawn": "^6.0.2",
"@types/crypto-js": "^4.0.1",
"@types/deepmerge": "^2.2.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Const/FileSystem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ declare namespace Engine {
interface showItemSuccess extends FileSystemState, Engine.ActionSuccessState {}
interface showItemFail extends Engine.ActionFailState {}

interface ArchiveSuccess extends FileSystemState, Engine.ActionSuccessState {}
interface ArchiveFail extends Engine.ActionFailState {}

interface UnzipSuccess extends FileTranslate, Engine.ActionSuccessState {}
interface UnzipFail extends Engine.ActionFailState {}

interface FileFilter {
name: string
extensions: string[]
Expand Down
53 changes: 53 additions & 0 deletions src/Main/IPC/FileSystem/archive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ipcMain, IpcMainInvokeEvent } from 'electron'
import fs from 'fs-extra'
import archiver from 'archiver'

interface ArchiveOption {
file: string
name: string
}

function archive(srcFiles: ArchiveOption[], dist: string): Promise<string> {
return new Promise((resolve, reject) => {
const output = fs.createWriteStream(dist)
const archive = archiver('zip', {
zlib: { level: 9 }
})

output.on('end', resolve)
archive.on('error', reject)
archive.pipe(output)

srcFiles.forEach(({ file, name }) => {
archive.file(file, { name })
})

archive.finalize()
})
}

export async function handler(srcFiles: ArchiveOption[], dist: string): Promise<Engine.FileSystem.ArchiveSuccess|Engine.FileSystem.ArchiveFail> {
try {
await archive(srcFiles, dist)
} catch (reason) {
const { message } = reason as Error
return {
success: false,
name: '압축 실패',
message
}
}

return {
success: true,
name: '압축 성공',
message: '압축을 성공했습니다',
path: dist
}
}

export function ipc(): void {
ipcMain.handle('archive', async (e: IpcMainInvokeEvent, srcFiles: ArchiveOption[], dist: string): Promise<Engine.FileSystem.ArchiveSuccess|Engine.FileSystem.ArchiveFail> => {
return await handler(srcFiles, dist)
})
}
52 changes: 52 additions & 0 deletions src/Main/IPC/FileSystem/unzip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ipcMain, IpcMainInvokeEvent } from 'electron'
import fs from 'fs-extra'
import Zip from 'adm-zip'

function unzip(src: string, dist: string, overwrite: boolean): Promise<string> {
return new Promise((resolve, reject) => {
if (!fs.existsSync(src)) {
const err = new Error(`The '${src}' file not exists.`)
reject(err)
}
// todo: adm-zip 패키지에 매개변수 3개를 사용할 경우, 비동기 사용에 오류가 있음.
// 버그가 수정되기 전까지 비동기 사용 금지
// https://github.com/cthackers/adm-zip/issues/407
// new Zip(src).extractAllToAsync(dist, overwrite, (err) => {
// if (err) reject(err)
// else resolve(dist)
// })
try {
new Zip(src).extractAllTo(dist, overwrite)
resolve(src)
} catch (reason) {
reject(reason)
}
})
}

export async function handler(src: string, dist: string, overwrite: boolean): Promise<Engine.FileSystem.UnzipSuccess|Engine.FileSystem.UnzipFail> {
try {
await unzip(src, dist, overwrite)
} catch (reason) {
const { message } = reason as Error
return {
success: false,
name: '압축 해제 실패',
message
}
}

return {
success: true,
name: '압축 해제',
message: '압축을 해제했습니다',
src,
dist
}
}

export function ipc(): void {
ipcMain.handle('unzip', async (e: IpcMainInvokeEvent, src: string, dist: string, overwrite: boolean = false): Promise<Engine.FileSystem.UnzipSuccess|Engine.FileSystem.UnzipFail> => {
return await handler(src, dist, overwrite)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class PreviewAudioVisualizer extends Phaser.GameObjects.Text {
if (!this.beat) {
return
}
console.log(123)
const { x, y } = this
this.beat.setPosition(x, y)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default class SceneInputComponent extends Vue {
private lastSpreadRepeat: number = 5
private component<T extends Vue>(refName: string): T {
console.log(this.$refs[refName])
return this.$refs[refName] as T
}
Expand Down
10 changes: 10 additions & 0 deletions src/Renderer/components/Manager/Engine/Home/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
flat
tile
>
<v-subheader>현재 버전: {{ engineVersion }}</v-subheader>
<v-card-title>프로젝트</v-card-title>
<v-card-subtitle>현재 프로젝트의 간략한 정보입니다</v-card-subtitle>
<engine-home-information-component />
Expand Down Expand Up @@ -104,6 +105,15 @@ export default class EngineHomeComponent extends Vue {
]
private toolLists: LinkList[] = [
{
subheader: '공용',
lists: [
{
text: '무료 에셋 추가',
uri: '/manager/tool/asset-appender'
}
]
},
{
subheader: '아티스트',
lists: [
Expand Down
5 changes: 5 additions & 0 deletions src/Renderer/components/Manager/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ export default class ProjectFileListComponent extends Vue {
description: '타일의 견본 레이어를 생성합니다',
path: '/manager/tool/isometrical-layer'
},
{
name: '무료 에셋 추가',
description: '인터넷에 공개된 무료 에셋을 자동으로 프로젝트에 추가합니다',
path: '/manager/tool/asset-appender'
}
]
}
]
Expand Down
68 changes: 68 additions & 0 deletions src/Renderer/components/Manager/Tool/AssetAppender.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<v-card
flat
tile
>
<v-card-title>무료 에셋 추가</v-card-title>
<v-card-subtitle>인터넷에 공개된 무료 에셋을 자동으로 프로젝트에 추가하거나, 스토어로 이동할 수 있습니다.</v-card-subtitle>
<v-card-text>
<v-alert
type="info"
class="text-caption"
>
아래 공개된 에셋은 퍼블릭 도메인의 에셋으로써, 창작자가 권리를 포기하고 무료 배포한 에셋입니다.
<br>
하지만 이러한 권리는 변경되었을 수 있으므로, 상세 내용은 스토어에서 직접 확인하십시오.
</v-alert>
<v-container class="py-10">
<v-row>
<asset-appender-card
v-for="(card, i) in list"
:key="`card-${i}`"
:namespace="card.namespace"
:subtitle="card.subtitle"
:source="card.source"
:title="card.title"
:color="card.color"
:logo="card.logo"
:url="card.url"
class="mx-5"
/>
</v-row>
</v-container>
</v-card-text>
</v-card>
</template>

<script lang="ts">
import path from 'path'
import { defineComponent, ref } from '@vue/composition-api'
import AssetAppenderCard, { Card } from './AssetAppenderCard.vue'
export default defineComponent({
components: {
AssetAppenderCard
},
setup() {
const isProduction = process.env.NODE_ENV === 'production'
const resourcesPath = isProduction ? process.resourcesPath : path.resolve(process.cwd(), 'build')
console.log(resourcesPath)
const list = ref<Card[]>([
{
logo: 'https://www.kenney.nl/data/img/logo.png',
title: 'Kenny Isometric Tiles',
subtitle: 'Kenny.nl에서 제공한 무료 에셋을 프로젝트에 추가합니다.',
source: path.resolve(resourcesPath, 'additional', 'FreeAssets', 'Kenny.zip'),
namespace: 'Kenny-isometric-tiles',
url: 'https://www.kenney.nl/',
color: '#2ECC92',
}
])
return {
list
}
},
})
</script>
Loading

0 comments on commit c19b2fa

Please sign in to comment.