Skip to content

Commit ab539bc

Browse files
committed
Fix loading script code from URL
1 parent 46337c4 commit ab539bc

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

etc/js/app.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const defaultAppParams = {
4343
refresh: "auto"
4444
}
4545

46+
const defaultCodeScript = "etc.assets.scene\\.flecs";
47+
4648
function newAppParams() {
4749
let result = structuredClone(defaultAppParams);
4850

@@ -274,6 +276,14 @@ Promise.all(components).then((values) => {
274276
// Load URL parameters
275277
this.fromUrlParams();
276278

279+
// If code is provided, open the script inspector for it.
280+
if (this.app_params.code !== undefined) {
281+
if (!this.app_params.entities.path) {
282+
this.app_params.entities.path = this.getCodeScriptPath();
283+
}
284+
this.app_params.entities.inspector_tab = "Script";
285+
}
286+
277287
let explicitHost = true;
278288
if (!this.app_params.host) {
279289
this.app_params.host = "localhost";
@@ -302,7 +312,7 @@ Promise.all(components).then((values) => {
302312
if (status == flecs.ConnectionStatus.Connected) {
303313
if (this.conn.mode == flecs.ConnectionMode.Wasm) {
304314
if (this.app_params.code) {
305-
this.conn.scriptUpdate("etc.assets.scene\\.flecs", this.app_params.code, {
315+
this.conn.scriptUpdate(this.getCodeScriptPath(), this.app_params.code, {
306316
try: true
307317
}, () => {});
308318
}
@@ -368,6 +378,15 @@ Promise.all(components).then((values) => {
368378
},
369379

370380
methods: {
381+
getCodeScriptPath() {
382+
if (this.app_params.entities && this.app_params.entities.path) {
383+
return this.app_params.entities.path;
384+
}
385+
if (this.app_params.script) {
386+
return this.app_params.script;
387+
}
388+
return defaultCodeScript;
389+
},
371390
convertTo(type, value) {
372391
if (type === "undefined") {
373392
return value;

etc/js/components/pages/entities/page.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
:path="appParams.entities.path"
4141
v-model:app_params="appParams.entities"
4242
@close="onClose"
43+
@onCodeChange="onCodeChange"
4344
@scriptOpen="onScriptOpen"
4445
@queryOpen="onQueryOpen"
4546
@selectEntity="onSelectEntity">

etc/js/components/pages/entities/pane-scripts.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
<div class="script-editor">
2323
<flecs-script
2424
:conn="conn"
25-
:script="activeScript"
25+
:script="activeScript.path"
2626
v-model:error="scriptError"
27-
v-model:changed="scriptChanged"
2827
@onChange="onCodeChange"
28+
@onUpdate="onScriptUpdate"
2929
v-if="activeScript">
3030
</flecs-script>
3131
</div>
@@ -45,7 +45,7 @@ export default { name: "pane-scripts" }
4545
</script>
4646

4747
<script setup>
48-
import { computed, onMounted, ref, watch } from 'vue';
48+
import { defineProps, defineModel, defineEmits, computed, onMounted, ref, watch } from 'vue';
4949
5050
const props = defineProps({
5151
conn: {type: Object, required: true}
@@ -157,6 +157,10 @@ function onCodeChange(evt) {
157157
emit("onCodeChange", evt);
158158
}
159159
160+
function onScriptUpdate(msg) {
161+
scriptChanged.value = msg.changed;
162+
}
163+
160164
defineExpose({openScript, closeScripts});
161165
162166
</script>

etc/js/components/widgets/edit-tabs-close-button.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default { name: "edit-tabs-close-button" }
1212

1313
<script setup>
1414
15-
import { computed, ref } from 'vue';
15+
import { defineProps, defineEmits, computed, ref } from 'vue';
1616
1717
const props = defineProps({
1818
changed: {type: Boolean, required: false, default: false},

etc/js/components/widgets/edit-tabs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default { name: "edit-tabs" }
4141
</script>
4242

4343
<script setup>
44-
import { onMounted } from 'vue';
44+
import { defineProps, defineModel, defineEmits, onMounted } from 'vue';
4545
4646
const props = defineProps({
4747
items: {type: Array, required: true},

etc/js/components/widgets/flecs-script.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default { name: "flecs-script" }
1111
</script>
1212

1313
<script setup>
14-
import { onMounted, computed, ref, watch } from 'vue';
14+
import { defineProps, defineModel, defineEmits, onMounted, computed, ref, watch } from 'vue';
1515
1616
const props = defineProps({
1717
conn: {type: Object, required: true},

etc/js/components/widgets/inspector/entity-inspector.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
:conn="conn"
5656
:script="path"
5757
v-if="entityQueryResult && isScript"
58+
@onChange="onCodeChange"
5859
@onUpdate="onScriptUpdate">
5960
</flecs-script>
6061
</template>
@@ -143,7 +144,7 @@ export default { name: "entity-inspector" }
143144
<script setup>
144145
import { defineProps, defineEmits, defineModel, computed, ref, watch, onMounted, onUnmounted, nextTick } from 'vue';
145146
146-
const emit = defineEmits(["abort", "scriptOpen", "queryOpen","selectEntity", "close"]);
147+
const emit = defineEmits(["abort", "scriptOpen", "queryOpen","selectEntity", "close", "onCodeChange"]);
147148
148149
const props = defineProps({
149150
conn: {type: Object, required: false},
@@ -431,6 +432,10 @@ function onScriptUpdate(evt) {
431432
scriptChanged.value = evt.changed;
432433
}
433434
435+
function onCodeChange(code) {
436+
emit("onCodeChange", code);
437+
}
438+
434439
function onAddComponent(component) {
435440
props.conn.add(props.path, component, (reply) => {
436441
entityQuery.value.now();

0 commit comments

Comments
 (0)