More refactor, more code, more good
This commit is contained in:
parent
8f714021e0
commit
5ed827e084
@ -119,12 +119,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {
|
import {
|
||||||
BingoGame
|
games
|
||||||
} from '@/js/Bingo.js';
|
} from '@/js/ParseGamesJSON.js';
|
||||||
// import {
|
import type BingoGame from '@/js/lib/BingoGame.ts';
|
||||||
// games
|
|
||||||
// } from '@/js/ParseGamesJSON.js';
|
|
||||||
|
|
||||||
@DComponent
|
@DComponent
|
||||||
export default class EditorComponent extends Vue {
|
export default class EditorComponent extends Vue {
|
||||||
|
@ -36,6 +36,12 @@ export default class SidebarComponent extends Vue {
|
|||||||
separator: true,
|
separator: true,
|
||||||
to: 'home'
|
to: 'home'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
icon: 'replay',
|
||||||
|
label: 'Generator',
|
||||||
|
separator: false,
|
||||||
|
to: 'generator'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
icon: 'edit',
|
icon: 'edit',
|
||||||
label: 'Editor',
|
label: 'Editor',
|
||||||
|
@ -40,7 +40,7 @@ function run_old_format() {
|
|||||||
// games.set(`${ game.name }-${ i }`, game);
|
// games.set(`${ game.name }-${ i }`, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('games', games);
|
// console.log('games', games);
|
||||||
|
|
||||||
// const game = games.get('Yakuza 0');
|
// const game = games.get('Yakuza 0');
|
||||||
// console.log(instanceToPlain(game));
|
// console.log(instanceToPlain(game));
|
||||||
|
@ -22,10 +22,10 @@ export default class BingoGame {
|
|||||||
// Funny conversion to allow for both BingoCategory and BingoGoalList
|
// Funny conversion to allow for both BingoCategory and BingoGoalList
|
||||||
@Transform((params: TransformFnParams) => {
|
@Transform((params: TransformFnParams) => {
|
||||||
return params.value.map((value: any) => {
|
return params.value.map((value: any) => {
|
||||||
if (value?.goal_lists || value instanceof BingoCategory) {
|
if (value?.goal_lists) {
|
||||||
return plainToInstance(BingoCategory, value);
|
return plainToInstance(BingoCategory, value);
|
||||||
}
|
}
|
||||||
else if (value?.goals || value instanceof BingoGoalList) {
|
else if (value?.goals) {
|
||||||
return plainToInstance(BingoGoalList, value);
|
return plainToInstance(BingoGoalList, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -4,94 +4,15 @@ import {
|
|||||||
} from 'class-transformer';
|
} from 'class-transformer';
|
||||||
|
|
||||||
export default class Parser {
|
export default class Parser {
|
||||||
// add_children(game: BingoGame, children: (BingoGoal | BingoGroup)[]): void {
|
static from_json(input: string): BingoGame {
|
||||||
// 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 {
|
|
||||||
const json: JSON = JSON.parse(input);
|
const json: JSON = JSON.parse(input);
|
||||||
const game = plainToInstance(BingoGame, json);
|
const game = plainToInstance(BingoGame, json);
|
||||||
|
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
static instance_to_plain(input: BingoGame): Record<string, any> {
|
static to_json(game: BingoGame): Record<string, any> {
|
||||||
const json = instanceToPlain(input);
|
const json = instanceToPlain(game);
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
@ -45,13 +45,13 @@ function test() {
|
|||||||
|
|
||||||
|
|
||||||
// console.log(game);
|
// console.log(game);
|
||||||
const plain = Parser.instance_to_plain(game);
|
const plain = Parser.to_json(game);
|
||||||
console.log('plain', plain);
|
console.log('plain', plain);
|
||||||
// const plain = instanceToPlain(game);
|
// const plain = instanceToPlain(game);
|
||||||
// const text = JSON.stringify(plain);
|
// const text = JSON.stringify(plain);
|
||||||
// console.log(text);
|
// 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);
|
console.log('parsed', parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@ const router = createRouter({
|
|||||||
path: '/editor',
|
path: '/editor',
|
||||||
name: 'editor',
|
name: 'editor',
|
||||||
component: EditorPage
|
component: EditorPage
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/generator',
|
||||||
|
name: 'generator',
|
||||||
|
component: EditorPage
|
||||||
}
|
}
|
||||||
// {
|
// {
|
||||||
// path: '/about',
|
// path: '/about',
|
||||||
|
Loading…
Reference in New Issue
Block a user