diff --git a/src/common/ecs/compiler.ts b/src/common/ecs/compiler.ts index b2220f0b..4f74380f 100644 --- a/src/common/ecs/compiler.ts +++ b/src/common/ecs/compiler.ts @@ -60,8 +60,14 @@ export class ECSCompiler extends Tokenizer { if (!this.em.imported[path]) { // already imported? let text = this.getImportFile && this.getImportFile(path); if (!text) this.compileError(`I can't find the import file "${path}".`); - new ECSCompiler(this.em).parseFile(path, text); this.em.imported[path] = true; + let comp = new ECSCompiler(this.em); + try { + comp.parseFile(text, path); + } catch (e) { + for (e of comp.errors) this.errors.push(e); + throw e; + } } } @@ -390,6 +396,8 @@ export class ECSCompiler extends Tokenizer { export() { let src = new SourceFileExport(); src.debug_file(this.path); + for (let path of Object.keys(this.em.imported)) + src.debug_file(path); this.exportToFile(src); return src.toString(); } diff --git a/src/common/ecs/ecs.ts b/src/common/ecs/ecs.ts index a5d1519e..f3ac0c21 100644 --- a/src/common/ecs/ecs.ts +++ b/src/common/ecs/ecs.ts @@ -1138,13 +1138,16 @@ export class EntityManager { constructor(public readonly dialect: Dialect_CA65) { } newScope(name: string, parent?: EntityScope) { + let existing = this.topScopes[name]; + if (existing && !existing.isDemo) + throw new ECSError(`scope ${name} already defined`, existing); let scope = new EntityScope(this, this.dialect, name, parent); - if (this.topScopes[name]) throw new ECSError(`scope ${name} already defined`); if (!parent) this.topScopes[name] = scope; return scope; } defineComponent(ctype: ComponentType) { - if (this.components[ctype.name]) throw new ECSError(`component ${ctype.name} already defined`); + let existing = this.components[ctype.name]; + if (existing) throw new ECSError(`component ${ctype.name} already defined`, existing); for (let field of ctype.fields) { let list = this.name2cfpairs[field.name]; if (!list) list = this.name2cfpairs[field.name] = []; @@ -1153,7 +1156,8 @@ export class EntityManager { return this.components[ctype.name] = ctype; } defineSystem(system: System) { - if (this.systems[system.name]) throw new ECSError(`system ${system.name} already defined`); + let existing = this.systems[system.name]; + if (existing) throw new ECSError(`system ${system.name} already defined`, existing); for (let a of system.actions) { let event = a.event; let list = this.event2systems[event]; diff --git a/src/common/ecs/main.ts b/src/common/ecs/main.ts index 573505dc..20057603 100644 --- a/src/common/ecs/main.ts +++ b/src/common/ecs/main.ts @@ -1,10 +1,10 @@ import { readFileSync } from "fs"; import { ECSCompiler } from "./compiler"; -import { SourceFileExport } from "./ecs"; +import { Dialect_CA65, EntityManager, SourceFileExport } from "./ecs"; class ECSMain { - compiler = new ECSCompiler(); + compiler = new ECSCompiler(new EntityManager(new Dialect_CA65())); // TODO constructor(readonly args: string[]) { }