bm
Create and use bitmasks of arbitrary depth without thinking.
NOTE: This has not been battle tested yet; use at your own risk. (And please report issues)
var createBitmaskGenerator = ; // Up to 1000 unique values (actually a multiple of 32 under the hood)var bm = ; var positionable = ;var moveable = ;var sprite = ; moveable; // truemoveable; // truepositionable; // false moveable; // truemoveable; // false moveable === sprite; // truesprite === moveable; // true // Notice how you can actually compare by value; this is because// the generator keeps a cache of all the mask objects// under the hood.sprite === ; // true
API
var createBitmaskGenerator = ;
Create a new bitmask generator
var bm = ;
maxUniqueValues
Number default=31 The number of unique tags supported.
Create a new bitmask from any number of tags
var mask = ;
tag1, tag2, tagN...
Strings The tags that are marked in this mask.
Note: Masks returned by this function can be compared by value, and order of arguments does not matter.
In other words, bm('a','b','c') === bm('c','b','a')
.
Check if one mask contains all values from another
mask;
Example:
; // true!; // false!
Check if one mask contains any values from another
mask;
Example:
; // true!; // false!
Combine two groups of tags
var combined = mask;
Example:
=== ; // true!
Remove certain tags from a mask
var without = mask;
Example:
=== ; // true!
License
MIT
Install
npm install bm --save