More refactor, more code, more good

This commit is contained in:
Lordmau5 2023-11-15 19:40:06 +01:00
parent 8f714021e0
commit 5ed827e084
7 changed files with 23 additions and 93 deletions

View File

@ -119,12 +119,10 @@
</template>
<script lang="ts">
import type {
BingoGame
} from '@/js/Bingo.js';
// import {
// games
// } from '@/js/ParseGamesJSON.js';
import {
games
} from '@/js/ParseGamesJSON.js';
import type BingoGame from '@/js/lib/BingoGame.ts';
@DComponent
export default class EditorComponent extends Vue {

View File

@ -36,6 +36,12 @@ export default class SidebarComponent extends Vue {
separator: true,
to: 'home'
},
{
icon: 'replay',
label: 'Generator',
separator: false,
to: 'generator'
},
{
icon: 'edit',
label: 'Editor',

View File

@ -40,7 +40,7 @@ function run_old_format() {
// games.set(`${ game.name }-${ i }`, game);
}
console.log('games', games);
// console.log('games', games);
// const game = games.get('Yakuza 0');
// console.log(instanceToPlain(game));

View File

@ -22,10 +22,10 @@ export default class BingoGame {
// Funny conversion to allow for both BingoCategory and BingoGoalList
@Transform((params: TransformFnParams) => {
return params.value.map((value: any) => {
if (value?.goal_lists || value instanceof BingoCategory) {
if (value?.goal_lists) {
return plainToInstance(BingoCategory, value);
}
else if (value?.goals || value instanceof BingoGoalList) {
else if (value?.goals) {
return plainToInstance(BingoGoalList, value);
}
});

View File

@ -4,94 +4,15 @@ import {
} from 'class-transformer';
export default class Parser {
// add_children(game: BingoGame, children: (BingoGoal | BingoGroup)[]): void {
// for (const child of children) {
// if (child instanceof BingoGroup) {
// const group = new BingoGroup(child.name);
// game.addGroup(group);
// this.add_children(game, child.children);
// }
// if (child instanceof BingoGoal) {
// this.add_children(child, child.children);
// }
// }
// }
// parse_new(input: BingoGame[]) {
// const games: Map<string, BingoGame> = new Map;
// for (const j_game of input) {
// const game = new BingoGame(
// j_game.id,
// j_game.name,
// j_game.short_description,
// j_game.description
// );
// for (const j_group of j_game.groups) {
// this.add_children(j_group)
// const group = new BingoGroup(j_group.name);
// game.addGroup(group);
// const children = this.get_children(j_group.children);
// for (const child of children) {
// if (child instanceof BingoGoal) {
// const goal = new BingoGoal(child.name, group);
// goal.possible_spaces = child.possible_spaces;
// goal.tags = child.tags;
// }
// }
// }
// const group_map: Map<string, BingoGroup> = new Map;
// const group_to_group_map: Map<BingoGroup, string> = new Map;
// for (const j_group of j_game.groups) {
// const group = new BingoGroup(j_group.name);
// if (j_group.parent_id)
// group_to_group_map.set(group, j_group.parent_id);
// group_map.set(j_group.name, group);
// game.addGroup(group);
// }
// for (const [
// group,
// parent_id
// ] of group_to_group_map) {
// const parent = group_map.get(parent_id);
// if (!parent)
// continue;
// group.parent = parent;
// }
// for (const j_goal of j_game.goals) {
// const group = group_map.get(j_goal.group_id);
// if (!group)
// continue;
// const goal = new BingoGoal(j_goal.name, group);
// goal.possible_spaces = j_goal.possible_spaces;
// goal.tags = j_goal.tags;
// game.addGoal(goal);
// }
// games.set(game.id, game);
// }
// }
static try_parse_neat(input: string): BingoGame {
static from_json(input: string): BingoGame {
const json: JSON = JSON.parse(input);
const game = plainToInstance(BingoGame, json);
return game;
}
static instance_to_plain(input: BingoGame): Record<string, any> {
const json = instanceToPlain(input);
static to_json(game: BingoGame): Record<string, any> {
const json = instanceToPlain(game);
return json;
}

View File

@ -45,13 +45,13 @@ function test() {
// console.log(game);
const plain = Parser.instance_to_plain(game);
const plain = Parser.to_json(game);
console.log('plain', plain);
// const plain = instanceToPlain(game);
// const text = JSON.stringify(plain);
// console.log(text);
const parsed: BingoGame = Parser.try_parse_neat(JSON.stringify(plain));
const parsed = Parser.from_json(JSON.stringify(plain));
console.log('parsed', parsed);
}

View File

@ -17,6 +17,11 @@ const router = createRouter({
path: '/editor',
name: 'editor',
component: EditorPage
},
{
path: '/generator',
name: 'generator',
component: EditorPage
}
// {
// path: '/about',