New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sam-ecs

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sam-ecs - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

2

package.json
{
"name": "sam-ecs",
"version": "1.0.4",
"version": "1.0.5",
"description": "A specialized entity component system",

@@ -5,0 +5,0 @@ "main": "sam-ecs.js",

@@ -13,3 +13,3 @@ Sam-ECS: Sam's entity component system

```
import { Manager, Entity, Processor } from 'sam-ecs');
import { Manager, Entity, Processor } from 'sam-ecs';

@@ -23,4 +23,4 @@ //manager creation

// add component to entity
/* Each component has to have at a minimum a name and
* state object
/* Each component has to have at a minimum a 'name' and
* 'state' object
*/

@@ -33,8 +33,10 @@ entity.addComponent({name: 'Transform', state: {x: 0, y: 0}});

super(manager, name);
/* every entity that contains a render component
* will be given to this processor's update
* function
* function
*/
this.components = new Set(['Render']);
}
// Called every time manager.update is called

@@ -47,9 +49,8 @@ update(entities, manager) {

}
/* Required, called by the manager
*
*/
// Required, called by the manager
getComponentNames() {
return this.components();
return this.components;
}
}
```

@@ -53,4 +53,4 @@ /******/ (function(modules) { // webpackBootstrap

'Manager': __webpack_require__(1).Manager,
'Entity': __webpack_require__(2).Entity,
'Processor': __webpack_require__(3).Processor
'Entity': __webpack_require__(3).Entity,
'Processor': __webpack_require__(4).Processor
};

@@ -80,11 +80,10 @@

//user imports
var _require = __webpack_require__(2),
var RandomStringGenerator = __webpack_require__(2);
var _require = __webpack_require__(3),
Entity = _require.Entity;
var _require2 = __webpack_require__(3),
Processor = _require2.Processor;
//constants
var RandomStringGenerator = __webpack_require__(4);
//constants
var HASH_LENGTH = 8,

@@ -301,5 +300,2 @@ ADD_ENTITY = 'ADD_ENTITY',

value: function addEntity(entity) {
if (!(entity instanceof Entity)) {
throw "Parameter 'entity' must be of type Entity!";
}

@@ -343,5 +339,2 @@ //if entity already exists, we remove the current one

// error check
if (!(entity instanceof Entity)) {
throw "Parameter 'entity' must be of type Entity!";
}

@@ -596,5 +589,3 @@ var hash = entity.hash();

value: function removeProcessor(processor) {
if (!(processor instanceof Processor)) {
throw new TypeError("'processor' must be instance of Processor!");
}
if (!(processor.getName() in this._processors)) {

@@ -612,2 +603,15 @@ throw new TypeError("'" + processor.getName().toString() + "' wasn't found!");

/**
* @description - Retrieves a previously added processor
* @param {String} name - the nane of the processor
*/
}, {
key: 'getProcessor',
value: function getProcessor(name) {
if (!this._processors[name]) throw new TypeError("Cannot find '" + name.toString() + "' in this" + " manager's processors!");
return this._processors[name];
}
/**
* @description - Iterates through all the manager's processors

@@ -746,2 +750,26 @@ * and calls them, passing all the entities that have the components

//RandomStringGenerator.js//
/**
* @description - Returns a random string of a given length
* @param {int} length - length of the string
* @return {String} - random string of given length
*/
module.exports = function () {
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}return text;
};
/***/ },
/* 3 */
/***/ function(module, exports) {
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -849,3 +877,3 @@

/***/ },
/* 3 */
/* 4 */
/***/ function(module, exports) {

@@ -933,27 +961,3 @@

/***/ },
/* 4 */
/***/ function(module, exports) {
"use strict";
//RandomStringGenerator.js//
/**
* @description - Returns a random string of a given length
* @param {int} length - length of the string
* @return {String} - random string of given length
*/
module.exports = function () {
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}return text;
};
/***/ }
/******/ ]);

@@ -9,5 +9,4 @@ //Manager.js//

//user imports
const RandomStringGenerator = require('./utils/RandomStringGenerator.js');
const { Entity } = require('./Entity.js');
const { Processor } = require('./Processor.js');
const RandomStringGenerator = require('./utils/RandomStringGenerator.js');

@@ -163,5 +162,2 @@ //constants

addEntity(entity) {
if (!(entity instanceof Entity)) {
throw "Parameter 'entity' must be of type Entity!";
}

@@ -205,5 +201,2 @@ //if entity already exists, we remove the current one

// error check
if (!(entity instanceof Entity)) {
throw "Parameter 'entity' must be of type Entity!";
}

@@ -370,5 +363,3 @@ var hash = entity.hash();

removeProcessor(processor) {
if (!(processor instanceof Processor)) {
throw new TypeError("'processor' must be instance of Processor!");
}
if (!(processor.getName() in this._processors)) {

@@ -388,2 +379,14 @@ throw new TypeError("'" + processor.getName().toString() +

/**
* @description - Retrieves a previously added processor
* @param {String} name - the nane of the processor
*/
getProcessor(name) {
if (!this._processors[name])
throw new TypeError("Cannot find '" + name.toString() + "' in this" +
" manager's processors!");
return this._processors[name];
}
/**
* @description - Iterates through all the manager's processors

@@ -417,3 +420,4 @@ * and calls them, passing all the entities that have the components

var shouldInvalidate = true;
for (var componentName of this._processors[processorName].getComponentNames()) {
for (var componentName of
this._processors[processorName].getComponentNames()) {
if (!(componentName in components)) {

@@ -420,0 +424,0 @@ shouldInvalidate = false;

@@ -388,3 +388,27 @@ //manager.test.js//

/**
* @description - Tests retrieving a processor from the ECS
*/
test("Processor Retrieval", () => {
var manager = new Manager();
class RenderProcessor extends Processor{
update(entities) {
//do stuff
}
getComponentNames() {
if (!this._components) {
this._components = new Set(['Render', 'Transform']);
}
return this._components;
}
}
var renderProcessor = new RenderProcessor(manager, "RenderProcessor");
manager.addProcessor(renderProcessor);
expect(() => { manager.getProcessor("PhysicsProcessor"); }).toThrow();
expect(manager.getProcessor(renderProcessor.getName())).toBe(renderProcessor);
});
/**

@@ -391,0 +415,0 @@ * @description - Test update function

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc