From 7cab0a6f18b82fb396c1f613f35247a271384af1 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 15 Oct 2019 11:57:57 +1100 Subject: [PATCH] combo counts --- client/src/components/vbox.component.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index 7b43931e..067f8310 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -1,5 +1,6 @@ const preact = require('preact'); const range = require('lodash/range'); +const countBy = require('lodash/countBy'); const without = require('lodash/without'); const { connect } = require('preact-redux'); @@ -262,7 +263,19 @@ function Vbox(args) { // invalid combo const combinerItems = combiner.map(j => vbox.bound[j]); - if (!itemInfo.combos.some(combo => combinerItems.every(c => combo.components.includes(c)))) { + const combinerCounts = countBy(combinerItems, c => c); + + // unless some combo + // contains every combinerItems + // and combinerItems.count of item >= components.count(item) + + if (!itemInfo.combos + .some(combo => { + const comboCount = countBy(combo.components, c => c); + return combinerItems.every(c => + combo.components.includes(c) && comboCount[c] >= combinerCounts[c] + ); + })) { return combinerChange([i]); }