shangdibaozi / ecs Goto Github PK
View Code? Open in Web Editor NEWEntity-Component-System
License: MIT License
Entity-Component-System
License: MIT License
强烈建议用这个库去开发Screeps游戏,用代码玩游戏的那个,Steam平台有
麻烦区分下版本,打个tag
按ecs的**,不同组件的组合对应系列“能力”。可以定义一种组件,该组件能包含其他纯数据组件,包含一系列方法。这种组件由ecs系统自动加入到满足条件的实体上。
tag组件是一种不携带数据的组件,它仅仅用来起标识的作用。
重现代码如下:
import { ecs } from "./ECS";
@ecs.register('Hello')
export class HelloComponent extends ecs.Comp {
info: string;
// 组件被回收前会调用这个方法。
reset() {
this.info = '';
}
}
export class TestHelloSystem extends ecs.ComblockSystem implements ecs.IEntityRemoveSystem {
entityRemove(entities: ecs.Entity[]): void {
console.log('TestSystem entityRemove');
}
filter(): ecs.IMatcher {
return ecs.allOf(HelloComponent);
}
update(entities: ecs.Entity[]): void {
}
export default class RoomSystem extends ecs.RootSystem {
constructor() {
super();
this.add(new TestHelloSystem());
}
}
//调用如下:
let entity = ecs.createEntity();
entity.add(HelloComponent);
setInterval(() => {
//会触发entityRemove
entity.remove(HelloComponent);
}, 4000);
提供序列化和反序列化的功能。
Matcher没有export
createComp方法没有导出,register.test.ts文件中调用ecs.createComp会报错
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.