Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SIEngine.Scene = function () {
- this.componentDictionary = {};
- this.systemList = [];
- };
- SIEngine.Scene.prototype = Object.create(Object.prototype, {
- constructor: {
- value: SIEngine.Scene
- },
- componentDictionary: {
- enumerable: true, configurable: true, writable: true
- },
- systemList: {
- enumerable: true, configurable: true, writable: true
- }
- });
- SIEngine.Scene.prototype.getComponentDictionary = function () {
- return this.componentDictionary;
- }
- SIEngine.Scene.prototype.getSystemList = function () {
- return this.systemList;
- }
- SIEngine.Scene.prototype.addComponent = function (entity, component) {
- var entityIdentifier = entity.getIdentifier();
- var componentType = component.getType();
- var componentDictionary = this.getComponentDictionary();
- component.setParentEntity(entity);
- if (!(componentType in componentDictionary)) {
- componentDictionary[componentType] = {};
- }
- componentDictionary[componentType][entityIdentifier] = component;
- };
- SIEngine.Scene.prototype.removeComponent = function (entity, component) {
- var entityIdentifier = entity.getIdentifier();
- var componentType = component.getType();
- var componentDictionary = this.getComponentDictionary();
- component.deleteParentEntity();
- delete componentDictionary[componentType][entityIdentifier];
- if (Object.keys(componentDictionary[componentType]).length === 0) {
- delete componentDictionary[componentType];
- }
- };
- SIEngine.Scene.prototype.removeEntity = function (entity) {
- var entityIdentifier = entity.getIdentifier();
- var componentDictionary = this.getComponentDictionary();
- for (var componentType in componentDictionary) {
- delete componentDictionary[componentType][entity];
- if (Object.keys(componentDictionary[componentType]).length === 0) {
- delete componentDictionary[componentType];
- }
- }
- };
- SIEngine.Scene.prototype.addSystem = function (system) {
- var systemList = this.getSystemList();
- system.setParentScene(this);
- systemList.push(system);
- systemList.sort(function(a, b) {return a.getPriority() - b.getPriority()});
- };
- SIEngine.Scene.prototype.removeSystem = function (system) {
- var systemList = this.getSystemList();
- var systemIndex = systemList.indexOf(system);
- if (systemIndex !== -1) {
- system.deleteParentScene();
- systemList.splice(systemIndex, 1);
- }
- };
- SIEngine.Scene.prototype.updateSystems = function () {
- var systemList = this.getSystemList();
- for (var i = 0; i < systemList.length; i++) {
- systemList[i].update();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement