Skip to content

Commit

Permalink
[2.0.0-alpha.2] Merge pull request #10 from bridge-core/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Joelant05 authored Feb 13, 2021
2 parents 5199aac + 9482689 commit b83f09b
Show file tree
Hide file tree
Showing 27 changed files with 312 additions and 26 deletions.
2 changes: 2 additions & 0 deletions data/preset/entity/panda/en_US.lang
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
item.spawn_egg.entity.{{PROJECT_PREFIX}}:{{IDENTIFIER}}.name=Spawn {{IDENTIFIER_NAME}}
entity.{{PROJECT_PREFIX}}:{{IDENTIFIER}}.name={{IDENTIFIER_NAME}}
29 changes: 24 additions & 5 deletions data/schema/manifest/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
"description": "This is a short description of the pack. It will appear in the game below the name of the pack."
},
"uuid": {
"$ref": "../general/uuid.json",
"anyOf": [
{
"$ref": "../general/uuid.json"
},
{
"type": "string"
}
],
"description": "This is a special type of identifier that uniquely identifies this pack from any other pack."
},
"version": {
Expand Down Expand Up @@ -83,8 +90,14 @@
"type": "string"
},
"uuid": {
"type": "string",
"$ref": "../general/uuid.json"
"anyOf": [
{
"$ref": "../general/uuid.json"
},
{
"type": "string"
}
],
},
"verison": {
"$ref": "#/definitions/triple_integer"
Expand All @@ -101,8 +114,14 @@
"required": ["uuid", "version"],
"properties": {
"uuid": {
"type": "string",
"$ref": "../general/uuid.json",
"anyOf": [
{
"$ref": "../general/uuid.json"
},
{
"type": "string"
}
],
"description": "This is the unique identifier of the pack that this pack depends on. It needs to be the exact same UUID that the pack has defined in the header section of it's manifest file."
},
"version": {
Expand Down
2 changes: 1 addition & 1 deletion data/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
5 changes: 4 additions & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { WindowResize } from '@/components/Common/WindowResize'
import { InstallApp } from '@/components/App/Install'
import { LanguageManager } from '@/components/Languages/LanguageManager'
import { ProjectManager } from './components/Projects/ProjectManager'
import { ContextMenu } from './components/ContextMenu/ContextMenu'

export class App {
public static toolbar = new Toolbar()
Expand All @@ -57,6 +58,7 @@ export class App {
public readonly projectManager = Vue.observable(new ProjectManager(this))
public readonly extensionLoader = new ExtensionLoader()
public readonly windowResize = new WindowResize()
public readonly contextMenu = new ContextMenu()

protected languageManager = new LanguageManager()
protected installApp = new InstallApp()
Expand Down Expand Up @@ -124,7 +126,7 @@ export class App {
this.themeManager.updateTheme()

// Set language
if (typeof settingsState.general.locale === 'string')
if (typeof settingsState?.general?.locale === 'string')
selectLanguage(settingsState?.general?.locale)
else {
// Set language based off of browser language
Expand Down Expand Up @@ -153,6 +155,7 @@ export class App {
// Try setting up the file system
const fileHandle = await setupFileSystem(this.instance)
if (!fileHandle) return this.instance.windows.loadingWindow.close()

this.instance.fileSystem.setup(fileHandle)

// Load settings
Expand Down
12 changes: 12 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<WelcomeScreen v-else />
<!-- -->
</v-main>

<ContextMenu v-if="contextMenu" :contextMenu="contextMenu" />
</v-app>
</template>

Expand All @@ -32,21 +34,31 @@ import TabBar from './components/TabSystem/TabBar.vue'
import { platform } from './utils/os'
import { TabSystemMixin } from '@/components/Mixins/TabSystem'
import WelcomeScreen from '@/components/TabSystem/WelcomeScreen'
import ContextMenu from '@/components/ContextMenu/ContextMenu.vue'
import { App } from '@/App'
export default Vue.extend({
name: 'App',
mixins: [TabSystemMixin],
mounted() {
App.getApp().then(app => {
this.contextMenu = app.contextMenu
})
},
components: {
Sidebar,
Toolbar,
WindowRenderer,
TabBar,
WelcomeScreen,
ContextMenu,
},
data: () => ({
isMacOs: platform() === 'darwin',
contextMenu: null,
}),
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/appVersion.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2.0.0-alpha.0"
"version": "2.0.0-alpha.2"
}
7 changes: 6 additions & 1 deletion src/components/Compiler/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ export class Compiler extends Signal<void> {
if (entry.kind !== 'file' || entry.name === '.DS_Store') continue

const file = await entry.getFile()
const config = JSON5.parse(await file.text())
let config
try {
config = JSON5.parse(await file.text())
} catch {
continue
}

actionManager.create({
icon: config.icon,
Expand Down
18 changes: 18 additions & 0 deletions src/components/ContextMenu/ContextMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ActionManager } from '../Actions/ActionManager'

export class ContextMenu {
protected isVisible = false
protected actionManager: ActionManager | undefined = undefined
protected position = {
x: 0,
y: 0,
}

show(event: MouseEvent, actionManager: ActionManager) {
this.position.x = event.clientX
this.position.y = event.clientY
this.actionManager = actionManager

this.isVisible = true
}
}
66 changes: 66 additions & 0 deletions src/components/ContextMenu/ContextMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<v-menu
v-if="isVisible"
v-model="isVisible"
:position-x="contextMenu.position.x"
:position-y="contextMenu.position.y"
rounded="lg"
absolute
offset-y
>
<v-list dense>
<v-list-item
v-for="action in contextMenu.actionManager.state"
:key="action.id"
origin="center center"
transition="scale-transition"
@click="action.trigger()"
>
<v-list-item-icon class="mr-2">
<v-icon color="primary">{{ action.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-action class="ma-0">{{
t(action.name)
}}</v-list-item-action>
</v-list-item>
</v-list>
</v-menu>
</template>

<script>
import { TranslationMixin } from '@/utils/locales'
export default {
name: 'ContextMenu',
mixins: [TranslationMixin],
props: {
contextMenu: Object,
},
data: () => ({
shouldRender: false,
timeoutId: 0,
}),
computed: {
isVisible: {
set(val) {
this.contextMenu.isVisible = val
},
get() {
return this.contextMenu.isVisible
},
},
},
watch: {
isVisible() {
if (!this.isVisible) {
this.timeoutId = setTimeout(
() => (this.shouldRender = false),
500
)
} else {
this.shouldRender = true
clearTimeout(this.timeoutId)
}
},
},
}
</script>
18 changes: 18 additions & 0 deletions src/components/ContextMenu/showContextMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { App } from '@/App'
import { IActionConfig } from '../Actions/Action'
import { ActionManager } from '../Actions/ActionManager'

export async function showContextMenu(
event: MouseEvent,
actions: IActionConfig[]
) {
event.preventDefault()
event.stopImmediatePropagation()

const app = await App.getApp()
const actionManager = new ActionManager(app)

actions.forEach(action => actionManager.create(action))

app.contextMenu.show(event, actionManager)
}
7 changes: 6 additions & 1 deletion src/components/Data/JSONDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export namespace JSONDefaults {
schema: await entry
.getFile()
.then(file => file.text())
.then(json5.parse),
.then(json5.parse)
.catch(() => {
throw new Error(
`Failed to load schema "${currentPath}"`
)
}),
}
} else {
promises.push(loadStaticSchemas(entry, currentPath))
Expand Down
1 change: 0 additions & 1 deletion src/components/Extensions/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { App } from '@/App'
import { loadScripts } from './Scripts/loadScripts'
import { ExtensionViewer } from '../Windows/ExtensionStore/Extension'
import { ExtensionStoreWindow } from '../Windows/ExtensionStore/ExtensionStore'
import json5 from 'json5'
import { iterateDir } from '@/utils/iterateDir'

export class Extension {
Expand Down
7 changes: 6 additions & 1 deletion src/components/Extensions/Themes/ThemeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ export class ThemeManager extends EventDispatcher<'light' | 'dark'> {
disposables?: IDisposable[]
) {
const file = await fileHandle.getFile()
const themeDefinition = json5.parse(await file.text())
let themeDefinition
try {
themeDefinition = json5.parse(await file.text())
} catch {
throw new Error(`Failed to load theme "${file.name}"`)
}

const disposable = this.addTheme(themeDefinition, isGlobal)
if (disposables) disposables.push(disposable)
Expand Down
6 changes: 5 additions & 1 deletion src/components/FileSystem/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export class FileSystem extends Signal<void> {

async readJSON(path: string) {
const file = await this.readFile(path)
return await json5.parse(await file.text())
try {
return await json5.parse(await file.text())
} catch {
throw new Error(`Invalid JSON: ${path}`)
}
}
writeJSON(path: string, data: any, beautify = false) {
return this.writeFile(
Expand Down
10 changes: 9 additions & 1 deletion src/components/FileSystem/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export async function setupFileSystem(app: App) {
return false
}

let fileHandle = await get<FileSystemDirectoryHandle>('bridgeBaseDir')
let fileHandle = await get<FileSystemDirectoryHandle | undefined>(
'bridgeBaseDir'
)

try {
await fileHandle?.getDirectoryHandle('data')
} catch {
fileHandle = undefined
}

if (!fileHandle) {
await createSelectProjectFolderWindow(async chosenFileHandle => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Projects/CreateProject/CreateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class CreateProjectWindow extends BaseWindow {
)

for (const createFile of this.createFiles) {
createFile.create(scopedFs, this.createOptions)
await createFile.create(scopedFs, this.createOptions)
}
for (const pack of this.createOptions.packs) {
await this.packs[pack].create(scopedFs, this.createOptions)
Expand Down
7 changes: 6 additions & 1 deletion src/components/Projects/CreateProject/Files/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export class CreateManifest extends CreateFile {
header: {
name: 'pack.name',
description: 'pack.description',
min_engine_version: createOptions.targetVersion.split('.'),
min_engine_version:
this.type === 'data'
? createOptions.targetVersion
.split('.')
.map(str => Number(str))
: undefined,
uuid: uuid(),
version: [1, 0, 0],
},
Expand Down
Loading

0 comments on commit b83f09b

Please sign in to comment.