mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-22 14:33:51 +00:00
ecs: fixed import
This commit is contained in:
parent
01de3b8d6b
commit
513fb85b8e
@ -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();
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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[]) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user