Skip to content

Commit

Permalink
Implement getEffectCombinations
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruesc committed Jan 28, 2025
1 parent 0e2a11d commit d286d7b
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/utils/EffectMaterialManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,39 @@ export class EffectMaterialManager implements Disposable {
/**
* Returns all possible effect combinations based on the {@link Effect.optional} flag.
*
* @param effects - A list of effects.
* @see https://www.geeksforgeeks.org/find-all-the-combinations-of-the-array-values-in-javascript/
* @return An iterator that returns the effect combinations.
*/

private *getEffectCombinations(): IterableIterator<Effect[]> {

yield this.effects;
const effects = this.effects;
const optionalEffects = effects.filter(x => x.optional);
const n = optionalEffects.length;
const m = 1 << n;

for(let i = 1; i < m; ++i) {

const combination: Effect[] = [];

for(let j = 0; j < n; ++j) {

for(let i = 0, il = this.effects.length; i < il; ++i) {
if(i & (1 << j)) {

for(let j = i + 1, jl = this.effects.length; j < jl; ++j) {
combination.push(optionalEffects[j]);

//?
}

}

yield effects.filter(x => !x.optional || combination.includes(x));

}

if(optionalEffects.length === effects.length) {

yield [];

}

}
Expand Down

0 comments on commit d286d7b

Please sign in to comment.