Skip to content

Commit

Permalink
[v1.7.15] Merge pull request #292 from bridge-core/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
solvedDev authored Nov 19, 2020
2 parents 306e4d7 + 311c4f9 commit 69c9b6e
Show file tree
Hide file tree
Showing 20 changed files with 318 additions and 73 deletions.
2 changes: 1 addition & 1 deletion app/renderer/src/UI/Sidebar/Content/Explorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default {
projectIcon: undefined,
}
},
created() {
mounted() {
this.projectIcon = this.loadProjectIcon()
this.$root.$on('refreshExplorer', () =>
EventBus.trigger('bridge:refreshExplorer')
Expand Down
3 changes: 3 additions & 0 deletions app/renderer/src/UI/Sidebar/Content/plugin/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { readJSON, writeJSON } from '../../../../Utilities/JsonFS'
import path from 'path'
import { CURRENT } from '../../../../constants'
import LoadingWindow from '../../../../../windows/LoadingWindow'
import { BridgeCore } from '../../../../bridgeCore/main'
export default {
name: 'plugin-card',
Expand Down Expand Up @@ -129,6 +130,7 @@ export default {
this.plugin.pluginFolder,
plugins
)
else BridgeCore.activate()
lw.close()
},
Expand All @@ -151,6 +153,7 @@ export default {
//This ensures that we're not trying to unload the built-in bridge. Core plugin
if (this.plugin.pluginPath)
PluginLoader.unloadPlugin(this.plugin.id)
else BridgeCore.deactivate()
lw.close()
},
},
Expand Down
11 changes: 11 additions & 0 deletions app/renderer/src/UI/Toolbar/Category/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export const EditMenu: IAppMenu = {
displayIcon: 'mdi-cancel',
keyBinding: {
key: 'escape',
prevent: e => {
if (
e.tagName === 'INPUT' &&
document.activeElement === e
) {
//This might be a "little" bit hacky (because this function shouldn't have side effects) but it works :)
e.blur()
return true
}
return false
},
},
onClick: () => TabSystem.setCurrentFileNav('global'),
},
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/src/UI/Windows/Project/Create/BP/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<p class="mt-10">
The target Minecraft version should be set to what version you
are developing for. Currently
<strong>{{ MC_STABLE_VERSION }}</strong> is the stable release
and <strong>{{ MC_BETA_VERSION }}</strong> is the beta release.
<strong>{{ MC_STABLE_VERSION }}</strong> is the stable release.
<!--and <strong>{{ MC_BETA_VERSION }}</strong> is the beta release.-->
</p>
<v-select
background-color="background"
Expand Down
9 changes: 5 additions & 4 deletions app/renderer/src/autoCompletions/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,13 @@ class Provider {
Omega.walk(object[key].$if)
)
return key.substring(key.indexOf('.') + 1, key.length)
return undefined
} else if (key.startsWith('$versioned_template.')) {
const {
object: tmpObject,
value: tmpValue,
} = compileVersionedTemplate(object[key])
const { object: tmpObject } = compileVersionedTemplate(
object[key]
)

// Check for value is not needed because tmpObject is only undefined when value is also undefined
if (tmpObject === undefined) return undefined
return key.substring(key.indexOf('.') + 1, key.length)
} else if (key.startsWith('@import.value')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import ProjectConfig from '../../../Project/Config'
import Provider from '../../Provider'

interface IVersionedTemplate {
$if: string
$if?: string
$legacy_if?: string //Allows usage of legacy dynamic_template $if hooks into the DYNAMIC lib
$data: any
}

Expand All @@ -22,8 +23,11 @@ export function compileVersionedTemplate(template: IVersionedTemplate[]) {
resValue: string[] = []
let hasTruthyCondition = false

for (let { $if, $data } of template) {
if (!$if || compileCondition($if)) {
for (let { $if, $legacy_if, $data } of template) {
if (
(!$if || compileCondition($if)) &&
(!$legacy_if || Omega.walk($legacy_if))
) {
hasTruthyCondition = true

if (typeof $data === 'string') {
Expand Down
18 changes: 18 additions & 0 deletions app/renderer/src/bridgeCore/BlockHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { set } from '../Utilities/useAttr'
import { OnSaveData } from './main'
import { iterateEvents } from './events/iterate'

export default async function BlockHandler({
file_uuid,
data,
file_name,
}: OnSaveData) {
//DATA
let block = data['minecraft:block']
if (!block) return
set(block, 'components', {})
set(block, 'description', {})
set(block, 'events', {})

await iterateEvents(file_uuid, file_name, block.events)
}
180 changes: 127 additions & 53 deletions app/renderer/src/bridgeCore/EntityHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { transformTag } from './TagHandler'
import LightningCache from '../editor/LightningCache'
import FileType from '../editor/FileType'
import { OnSaveData } from './main'
import { transformJsonCommands } from './functions/transformJson'
import {
transformJsonCommands,
transformRunCommands,
} from './functions/transformJson'
import { createErrorNotification } from '../AppCycle/Errors'
import ProjectConfig from '../Project/Config'
import { compare } from 'compare-versions'

let COM_ID_COUNTER = 0
let A_C: AnimationController
Expand All @@ -23,8 +29,16 @@ async function transformEvent(
events,
file_name,
file_uuid,
eventName,
formatVersion,
}: Partial<
OnSaveData & { component_groups: any; description: any; events: any }
OnSaveData & {
component_groups: any
description: any
events: any
eventName: string
formatVersion: string
}
>
) {
//SPELL EFFECTS
Expand Down Expand Up @@ -58,81 +72,135 @@ async function transformEvent(
set(component_groups, group_name, g.components || {})
}

if (event.run_command !== undefined) {
let { command } = event.run_command
if (typeof command === 'string') command = [command]

if (Array.isArray(command))
event.run_command.command = await transformRunCommands(
file_uuid,
command
)
else
createErrorNotification(
new Error(
`Invalid run_command>command syntax: Expected array, found ${typeof command}! (Path: ${file_name} - ${eventName})`
)
)
}

//EXECUTE COMMANDS
let { commands: e_c } = use(event, 'execute') || {}
if (e_c !== undefined) {
let e_c_group = `execute_command_id_${++COM_ID_COUNTER}`
if (typeof e_c === 'string') e_c = [e_c]
if (e_c !== undefined && Array.isArray(e_c)) {
if (compare(formatVersion, '1.16.100', '<')) {
let e_c_group = `execute_command_id_${++COM_ID_COUNTER}`

if (!COMMAND_ANIM_REGISTERED) {
set(description, 'scripts/animate', ['bridge_execute_commands'])
COMMAND_ANIM_REGISTERED = true
}

set(description, 'animations', {
bridge_execute_commands: `controller.animation.bridge_${file_name}.execute_commands`,
})
set(component_groups, `bridge:${e_c_group}`, {
'minecraft:skin_id': {
value: COM_ID_COUNTER,
},
})
set(component_groups, 'bridge:execute_no_command', {
'minecraft:skin_id': {
value: 0,
},
})
set(event, 'add/component_groups', [`bridge:${e_c_group}`])
set(events, 'bridge:remove_command_id_' + COM_ID_COUNTER, {
add: {
component_groups: ['bridge:execute_no_command'],
},
remove: {
component_groups: [`bridge:${e_c_group}`],
},
})
if (!COMMAND_ANIM_REGISTERED) {
set(description, 'scripts/animate', ['bridge_execute_commands'])
COMMAND_ANIM_REGISTERED = true
}

set(
A_C,
`animation_controllers/controller.animation.bridge_${file_name}.execute_commands/states`,
{
default: {
transitions: [
{ [e_c_group]: `query.skin_id == ${COM_ID_COUNTER}` },
],
set(description, 'animations', {
bridge_execute_commands: `controller.animation.bridge_${file_name}.execute_commands`,
})
set(component_groups, `bridge:${e_c_group}`, {
'minecraft:skin_id': {
value: COM_ID_COUNTER,
},
})
set(component_groups, 'bridge:execute_no_command', {
'minecraft:skin_id': {
value: 0,
},
})
set(event, 'add/component_groups', [`bridge:${e_c_group}`])
set(events, 'bridge:remove_command_id_' + COM_ID_COUNTER, {
add: {
component_groups: ['bridge:execute_no_command'],
},
[e_c_group]: {
transitions: [
{ default: `query.skin_id != ${COM_ID_COUNTER}` },
],
on_entry: (
await transformJsonCommands(file_uuid, e_c)
).concat(['@s bridge:remove_command_id_' + COM_ID_COUNTER]),
remove: {
component_groups: [`bridge:${e_c_group}`],
},
})

set(
A_C,
`animation_controllers/controller.animation.bridge_${file_name}.execute_commands/states`,
{
default: {
transitions: [
{
[e_c_group]: `query.skin_id == ${COM_ID_COUNTER}`,
},
],
},
[e_c_group]: {
transitions: [
{ default: `query.skin_id != ${COM_ID_COUNTER}` },
],
on_entry: (
await transformJsonCommands(file_uuid, e_c)
).concat([
'@s bridge:remove_command_id_' + COM_ID_COUNTER,
]),
},
}
)
} else {
if (event?.run_command?.command === undefined)
event.run_command = {
...(event.run_command ?? {}),
command: await transformRunCommands(
file_uuid,
e_c.map(c => (c[0] === '/' ? c.slice(1) : c))
),
}
else {
if (typeof event.run_command.command === 'string')
event.run_command.command = [event.run_command.command]
if (Array.isArray(event.run_command.command))
event.run_command.command.push(
...(await transformRunCommands(
file_uuid,
e_c.map(c => (c[0] === '/' ? c.slice(1) : c))
))
)
}
}
} else if (e_c !== undefined) {
createErrorNotification(
new Error(
`Invalid execute>commands syntax: Expected array, found ${typeof e_c}! (Path: ${file_name} - ${eventName})`
)
)
}

if (event.sequence !== undefined)
await Promise.all(
event.sequence.map((e: any) =>
event.sequence.map((e: any, i: number) =>
transformEvent(e, {
component_groups,
description,
events,
file_name,
file_uuid,
eventName: `${eventName}>sequence>${i}`,
formatVersion,
})
)
)
if (event.randomize !== undefined)
await Promise.all(
event.randomize.map((e: any) =>
event.randomize.map((e: any, i: number) =>
transformEvent(e, {
component_groups,
description,
events,
file_name,
file_uuid,
eventName: `${eventName}>randomize>${i}`,
formatVersion,
})
)
)
Expand Down Expand Up @@ -177,6 +245,8 @@ export default async function EntityHandler({
file_path,
simulated_call,
}: OnSaveData) {
let formatVersion =
data.format_version || (await ProjectConfig.formatVersion)
let entity = data['minecraft:entity']
if (!entity) return
set(entity, 'component_groups', {})
Expand All @@ -194,12 +264,16 @@ export default async function EntityHandler({
events,
file_uuid,
file_name: file_name.replace('.json', ''),
eventName: e,
formatVersion,
})

await A_C.save(
join(
CURRENT.PROJECT_PATH,
`animation_controllers/bridge/commands_${file_name}`
// The execute>commands syntax only needs an animation controller on Minecraft releases before v1.16.100
if (compare(formatVersion, '1.16.100', '<'))
await A_C.save(
join(
CURRENT.PROJECT_PATH,
`animation_controllers/bridge/commands_${file_name}`
)
)
)
}
Loading

0 comments on commit 69c9b6e

Please sign in to comment.