Skip to content

Commit

Permalink
Patch cutscene system, add possibility to handle mcfunction during ci…
Browse files Browse the repository at this point in the history
…nematic
  • Loading branch information
c-bertran committed Sep 22, 2024
1 parent 69e994d commit ec37dd6
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 346 deletions.
555 changes: 251 additions & 304 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import {
import '@quasar/extras/roboto-font/roboto-font.css'
import '@quasar/extras/material-icons/material-icons.css';
import '@quasar/extras/material-icons-outlined/material-icons-outlined.css';
import '@quasar/extras/material-icons-round/material-icons-round.css';
import '@quasar/extras/material-icons-sharp/material-icons-sharp.css';
import '@quasar/extras/material-symbols-outlined/material-symbols-outlined.css';
import '@quasar/extras/material-symbols-rounded/material-symbols-rounded.css';
import '@quasar/extras/material-symbols-sharp/material-symbols-sharp.css';
import '@quasar/extras/animate/fadeIn.css';
import '@quasar/extras/animate/fadeOut.css';
import 'quasar/src/css/index.sass';
Expand Down
17 changes: 5 additions & 12 deletions src/builtin/cutscene/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,10 @@ class cutscene {
.catch(() => { /* make nothing */ });
}

openFile(id: number, start: boolean = true): void {
const link = resolve(this._path.dir, id.toString(), `${start
? 'start'
: 'end'
}.mcfunction`);
if (!existsSync(link)) {
writeFileSync(link, `# Cutscene ${start
? 'start'
: 'end'
}\n`, { encoding: 'utf-8', flag: 'w' });
}
openFile(id: number, type: 'start' | 'during' | 'end'): void {
const link = resolve(this._path.dir, id.toString(), `${type}.mcfunction`);
if (!existsSync(link))
writeFileSync(link, `# Cutscene ${type}\n`, { encoding: 'utf-8', flag: 'w' });
ipc.send('editor::open-editor', link);
}

Expand Down Expand Up @@ -136,7 +129,7 @@ const __instance__ = new cutscene();
exposeInMainWorld('cutscene', {
__builtin__: true,
init: (env: envInterface, name: string) => __instance__.init(env, name),
openFile: (id: number, start: boolean = true) => __instance__.openFile(id, start),
openFile: (id: number, type: 'start' | 'during' | 'end') => __instance__.openFile(id, type),
getCutscene: (id: number | undefined = undefined) => __instance__.getCutscene(id),
getPoints: (id: number) => __instance__.getPoints(id),
create: (name: string) => __instance__.createCutscene(name),
Expand Down
17 changes: 13 additions & 4 deletions src/builtin/cutscene/components/option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@
<div class="row no-wrap justify-between">
<q-btn
square unelevated color="light-blue-7"
icon="play_arrow"
@click="$emit('open', true)"
icon="sym_o_line_start_diamond"
@click="$emit('open', 'start')"
>
<q-tooltip :delay="500" class="bg-light-blue-7">
{{ $capitalize($t('builtin.cutscene.content.menu.editStart')) }}
</q-tooltip>
</q-btn>
<q-btn
square unelevated color="purple-5"
icon="route"
@click="$emit('open', 'during')"
>
<q-tooltip :delay="500" class="bg-purple-5">
{{ $capitalize($t('builtin.cutscene.content.menu.editDuring')) }}
</q-tooltip>
</q-btn>
<q-btn
square unelevated color="red-7"
icon="stop"
@click="$emit('open', false)"
icon="sym_o_line_end_diamond"
@click="$emit('open', 'end')"
>
<q-tooltip :delay="500" class="bg-red-7">
{{ $capitalize($t('builtin.cutscene.content.menu.editEnd')) }}
Expand Down
12 changes: 4 additions & 8 deletions src/builtin/cutscene/components/sidenav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
<template v-slot:right>
<q-icon name="delete"/>
</template>
<q-item :class="isSelected(cutscene.id)">
<q-item :class="{
'element-selected': (cutsceneSelectedId === cutscene.id),
row: true
}">
<q-item-section no-wrap>
<span class="q-mr-md">
<q-icon name="sell" class="q-mr-xs" />
Expand Down Expand Up @@ -82,12 +85,6 @@ export default defineComponent({
const modalCutsceneName = ref<string | null>(null);
const cutsceneSelectedId = ref<number>(-1);
const isSelected = (id: number) => {
if (cutsceneSelectedId.value === id)
return 'element-selected';
return '';
};
const openCutscene = (id: number) => {
window.mapcraft.clipboard.writeText(`cutscene_${id}`);
const x = props.list.findIndex((e) => e.id === id);
Expand Down Expand Up @@ -120,7 +117,6 @@ export default defineComponent({
modalCutsceneName,
cutsceneSelectedId,
isSelected,
openCutscene,
createCutscene,
deleteCutscene
Expand Down
2 changes: 1 addition & 1 deletion src/builtin/cutscene/declare.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export declare global {
interface Window {
cutscene: {
init: (env: envInterface, name: string) => Promise<void>,
openFile: (id: number, start: boolean = true) => void,
openFile: (id: number, type: 'start' | 'during' | 'end') => void,
getCutscene: (id: number | undefined = undefined) => Promise<cutsceneInterface | cutsceneInterface[]>,
getPoints: (id: number) => Promise<cutscenePointInterface[]>,
create: (name: string) => Promise<cutsceneInterface>,
Expand Down
4 changes: 2 additions & 2 deletions src/builtin/cutscene/functions/createCutscene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'path';
import { fs, type sql } from 'mapcraft-api/backend';
import type { cutsceneInterface } from '../interface';

const deleteCutscene_GEN1 = async (db: sql, name: string, path: {dir: string, main: string}): Promise<cutsceneInterface> => {
const createCutscene_GEN1 = async (db: sql, name: string, path: {dir: string, main: string}): Promise<cutsceneInterface> => {
await db.update('INSERT INTO cutscene (name, duration) VALUES (?, ?)', name, 0);
const ret: cutsceneInterface = await db.get('SELECT * FROM cutscene WHERE name = ?', name);
await db.update('UPDATE cutscene SET tag = ? WHERE id = ?', `Cutscene_${ret.id}`, ret.id);
Expand Down Expand Up @@ -35,5 +35,5 @@ export default (
|| version === '1.19' || version === '1.19.1' || version === '1.19.2' || version === '1.19.3' || version === '1.19.4'
)
*/
return deleteCutscene_GEN1(db, name, path);
return createCutscene_GEN1(db, name, path);
};
42 changes: 30 additions & 12 deletions src/builtin/cutscene/functions/generateCutscene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ class GenerateCutsceneGen1 {
return data;
}

private genSavePosition (parse: string[]) {
private genSavePosition (parse: string[], isPlayer = false) {
const ret = [];

if (parse[0] === 'origin') {
return [
'# Save position',
ret.push(...[
'# Save data',
'\n',
'execute if score @s MC_Cutscene matches 0 if entity @s[tag=!Debug] positioned as @s store result score @s MC_CutsceneSaveX run data get entity @s Pos[0]',
'\n',
Expand All @@ -112,9 +114,16 @@ class GenerateCutsceneGen1 {
'execute if score @s MC_Cutscene matches 0 if entity @s[tag=!Debug] positioned as @s store result score @s MC_CutsceneSaveRx run data get entity @s Rotation[0]',
'\n',
'execute if score @s MC_Cutscene matches 0 if entity @s[tag=!Debug] positioned as @s store result score @s MC_CutsceneSaveRy run data get entity @s Rotation[1]'
];
]);
}
if (isPlayer) {
ret.push(...[
'\n',
'execute if score @s MC_Cutscene matches 0 if entity @s[tag=!Debug] positioned as @s store result score @s MC_CutsceneSaveGamemode run data get entity @s playerGameType'
])
}
return undefined;

return ret;
}

private genLoadPosition (parse: string[], time: { Max: number }) {
Expand Down Expand Up @@ -230,12 +239,14 @@ class GenerateCutsceneGen1 {
cameraPlayer: resolve(this.path.dir, this.id.toString(), 'camera_player.mcfunction'),

start: resolve(this.path.dir, this.id.toString(), 'start.mcfunction'),
during: resolve(this.path.dir, this.id.toString(), 'during.mcfunction'),
end: resolve(this.path.dir, this.id.toString(), 'end.mcfunction')
};

const templateFiles = {
Launch: ['execute if entity @s[tag=Cutscene,tag=', tag ,'] run function mapcraft-data:cutscene/', this.id.toString(), '/main'],
Start: ['# ', tag,' start'],
During: ['# ', tag, 'during'],
End: ['# ', tag,' end'],
Main: {
0: ['execute if entity @s[type=minecraft:player] positioned ', coordinates.position, ' rotated ', coordinates.rotation, ' run function mapcraft-data:cutscene/', this.id.toString() ,'/player'],
Expand All @@ -262,7 +273,8 @@ class GenerateCutsceneGen1 {
Cutscene: {
0: ['# Cutscene'],
1: ['execute if score @s MC_Cutscene matches 1..', time.Max.toString(), ' run function mapcraft-data:cutscene/', this.id.toString(), '/camera_entity'],
2: ['scoreboard players add @s MC_Cutscene 1'],
2: ['execute if score @s MC_Cutscene matches 1..', time.Max.toString(), ' if entity @s[tag=!Debug] run function mapcraft-data:cutscene/', this.id.toString() ,'/during'],
3: ['scoreboard players add @s MC_Cutscene 1'],
},
End: {
0: ['# End'],
Expand All @@ -277,7 +289,7 @@ class GenerateCutsceneGen1 {
const templatePlayerFile = {
Core: {
0: ['# Core'],
1: () => this.genSavePosition(parse),
1: () => this.genSavePosition(parse, true),
2: ['execute if score @s MC_Cutscene matches 0 if entity @s[tag=!Debug] run function mapcraft:built_in/cutscene/save_gamemode'],
3: ['execute if score @s MC_Cutscene matches 0 run tp @s[tag=', tag, ',tag=Cutscene,tag=!Debug] ~ ~ ~ ~ ~'],
4: ['execute if score @s MC_Cutscene matches 0 unless entity @e[sort=nearest,tag=Cutscene,tag=Camera] run function mapcraft:built_in/cutscene/summon_camera'],
Expand All @@ -297,17 +309,22 @@ class GenerateCutsceneGen1 {
0: ['# Cutscene'],
1: ['execute if entity @s[tag=', tag ,',tag=!Debug] if score @s MC_Cutscene matches ..', time.Max.toString() ,' if entity @e[tag=', tag ,',tag=Cutscene,tag=Camera,sort=nearest,limit=1,distance=1..] run spectate @e[tag=', tag ,',tag=Cutscene,tag=Camera,sort=nearest,limit=1] @s'],
2: ['scoreboard players add @s MC_Cutscene 1'],
3: ['execute if score @s MC_Cutscene matches 1..', time.Max.toString(), ' at @e[tag=', tag, ',tag=Cutscene,tag=Camera,sort=nearest,limit=1] run function mapcraft-data:cutscene/', this.id.toString(), '/camera_player'],
3: ['execute if score @s MC_Cutscene matches 1..', time.Max.toString(), ' if entity @s[tag=!Debug] run function mapcraft-data:cutscene/', this.id.toString() ,'/during'],
4: ['execute if score @s MC_Cutscene matches 1..', time.Max.toString(), ' at @e[tag=', tag, ',tag=Cutscene,tag=Camera,sort=nearest,limit=1] run function mapcraft-data:cutscene/', this.id.toString(), '/camera_player'],
},
End: {
0: ['# End'],
1: ['execute if score @s[tag=', tag ,',tag=!Debug] MC_Cutscene matches ..', time.Max.toString() ,' if entity @e[tag=', tag ,',tag=Cutscene,tag=Camera,sort=nearest,limit=1,distance=1..] run spectate @e[tag=', tag ,',tag=Cutscene,tag=Camera,sort=nearest,limit=1] @s'],
4: ['execute if score @s MC_Cutscene matches ', time.Max.toString(), '.. run kill @e[tag=', tag, ',tag=Cutscene,tag=Camera,sort=nearest,limit=1]'],
5: ['execute if score @s MC_Cutscene matches ', time.Max.toString(), '.. if entity @s[tag=!Debug] run function mapcraft:built_in/cutscene/load_gamemode'],
6: () => this.genLoadPosition(parse, time),
7: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=', tag ,',tag=!Debug] run tag @s remove ', tag],
8: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=!Debug] run function mapcraft-data:cutscene/', this.id.toString() ,'/end'],
9: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. run scoreboard players set @s MC_Cutscene 0']
7: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=!Debug] if score @s MC_CutsceneSaveGamemode matches 0 run gamemode survival @s'],
8: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=!Debug] if score @s MC_CutsceneSaveGamemode matches 1 run gamemode creative @s'],
9: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=!Debug] if score @s MC_CutsceneSaveGamemode matches 2 run gamemode adventure @s'],
10: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=!Debug] if score @s MC_CutsceneSaveGamemode matches 3 run gamemode spectator @s'],
11: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=', tag ,',tag=!Debug] run tag @s remove ', tag],
12: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. if entity @s[tag=!Debug] run function mapcraft-data:cutscene/', this.id.toString() ,'/end'],
13: ['execute if score @s MC_Cutscene matches ', time.Max.toString() ,'.. run scoreboard players set @s MC_Cutscene 0']
}
};

Expand Down Expand Up @@ -336,10 +353,11 @@ class GenerateCutsceneGen1 {
fs.modifyLine(this.path.main, `tag=${tag}`, templateFiles.Launch.join(''), true);

/**
* Create start and end mcfunction files
* Create start, during and end mcfunction files
*/
await Promise.all([
writeFile(filePath.start , `${templateFiles.Start.join('')}\n`, { encoding: 'utf-8', flag: 'wx' }),
writeFile(filePath.during , `${templateFiles.Start.join('')}\n`, { encoding: 'utf-8', flag: 'wx' }),
writeFile(filePath.end, `${templateFiles.End.join('')}\n`, { encoding: 'utf-8', flag: 'wx' })
]).catch(() => { /* make nothing */ });

Expand Down
1 change: 1 addition & 0 deletions src/builtin/cutscene/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
content: {
menu: {
editStart: 'edit start mcfunction file',
editDuring: 'edit the mcfunction that is executed during the cutscene',
editEnd: 'edit end mcfunction file',
option: 'edit options',
save: {
Expand Down
1 change: 1 addition & 0 deletions src/builtin/cutscene/lang/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
content: {
menu: {
editStart: 'modifier le mcfunction de départ',
editDuring: 'modifier le mcfunction exécuté pendant la scène',
editEnd: 'modifier le mcfunction de fin',
option: 'modifier les options',
save: {
Expand Down
7 changes: 5 additions & 2 deletions src/builtin/cutscene/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ export default defineComponent({
const cutsceneSelected = ref<cutscene | null>(null);
let saveCutscene: NodeJS.Timer; // eslint-disable-line no-undef
const openFile = (start: boolean) => {
const openFile = (type: 'start' | 'during' | 'end') => {
if (cutsceneSelected.value)
window.cutscene.openFile(cutsceneSelected.value.cutscene.id, start);
window.cutscene.openFile(
cutsceneSelected.value.cutscene.id,
type
);
};
//#region Cutscene
Expand Down
10 changes: 10 additions & 0 deletions src/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ export default defineConfig((env) => ({
clearScreen: false,
publicDir: './public',
logLevel: 'info',
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler'
},
sass: {
api: 'modern-compiler'
},
}
},
define: {
__VUE_I18N_FULL_INSTALL__: true,
__VUE_I18N_LEGACY_API__: false
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
Expand Down

0 comments on commit ec37dd6

Please sign in to comment.