@stackedapp/utils 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/conditions.js +34 -6
- package/package.json +1 -1
package/dist/conditions.js
CHANGED
|
@@ -408,15 +408,29 @@ additionalData, }) => {
|
|
|
408
408
|
// Evaluate dynamic conditions
|
|
409
409
|
if (conditions?.dynamic?.conditions?.length) {
|
|
410
410
|
const resolvedConditions = (0, template_1.replaceDynamicConditionKeys)(conditions.dynamic.conditions, playerOffer?.trackers || {});
|
|
411
|
-
const
|
|
411
|
+
const dynamicObj = playerSnap.dynamic || {};
|
|
412
|
+
const dynamicResult = meetsDynamicConditions(dynamicObj, {
|
|
412
413
|
...conditions.dynamic,
|
|
413
414
|
conditions: resolvedConditions,
|
|
414
415
|
});
|
|
415
416
|
if (addDetails) {
|
|
417
|
+
// Extract tracker amount and goal from the first condition for display
|
|
418
|
+
let trackerAmount;
|
|
419
|
+
let trackerGoal;
|
|
420
|
+
if (resolvedConditions.length > 0) {
|
|
421
|
+
const firstCond = resolvedConditions[0];
|
|
422
|
+
if (typeof firstCond.compareTo === 'number') {
|
|
423
|
+
trackerGoal = firstCond.compareTo;
|
|
424
|
+
}
|
|
425
|
+
const val = dynamicObj[firstCond.key];
|
|
426
|
+
trackerAmount = typeof val === 'number' ? val : 0;
|
|
427
|
+
}
|
|
416
428
|
conditionData.push({
|
|
417
429
|
isMet: dynamicResult,
|
|
418
430
|
kind: 'dynamic',
|
|
419
|
-
|
|
431
|
+
trackerAmount,
|
|
432
|
+
trackerGoal,
|
|
433
|
+
text: (0, template_1.renderTemplate)(conditions.dynamic.template, dynamicObj) || 'Dynamic conditions',
|
|
420
434
|
});
|
|
421
435
|
if (!dynamicResult)
|
|
422
436
|
isValid = false;
|
|
@@ -857,23 +871,37 @@ const meetsCompletionConditions = ({ completionConditions, completionTrackers, p
|
|
|
857
871
|
}
|
|
858
872
|
if (conditions?.dynamicTracker?.conditions?.length) {
|
|
859
873
|
const resolvedConditions = (0, template_1.replaceDynamicConditionKeys)(conditions.dynamicTracker.conditions, playerOffer?.trackers || {});
|
|
860
|
-
//
|
|
861
|
-
const
|
|
874
|
+
// Convert { key: { value: X } } to { key: X } format
|
|
875
|
+
const primitiveTrackers = (0, dynamic_1.dynamicTrackerToPrimitive)(completionTrackers?.dynamicTracker || {});
|
|
876
|
+
const dynamicResult = meetsDynamicConditions(primitiveTrackers, {
|
|
862
877
|
...conditions.dynamicTracker,
|
|
863
878
|
conditions: resolvedConditions,
|
|
864
879
|
}, claimMultiplier);
|
|
865
880
|
if (shouldScale) {
|
|
866
|
-
const dynamicMax = getMaxClaimsForDynamicGroup(
|
|
881
|
+
const dynamicMax = getMaxClaimsForDynamicGroup(primitiveTrackers, {
|
|
867
882
|
...conditions.dynamicTracker,
|
|
868
883
|
conditions: resolvedConditions,
|
|
869
884
|
}, playerOffer?.trackers?.claimedCount || 0);
|
|
870
885
|
updateMax(dynamicMax);
|
|
871
886
|
}
|
|
872
887
|
if (addDetails) {
|
|
888
|
+
// Extract tracker amount and goal from the first condition for display
|
|
889
|
+
let trackerAmount;
|
|
890
|
+
let trackerGoal;
|
|
891
|
+
if (resolvedConditions.length > 0) {
|
|
892
|
+
const firstCond = resolvedConditions[0];
|
|
893
|
+
if (typeof firstCond.compareTo === 'number') {
|
|
894
|
+
trackerGoal = firstCond.compareTo;
|
|
895
|
+
}
|
|
896
|
+
const val = primitiveTrackers[firstCond.key];
|
|
897
|
+
trackerAmount = typeof val === 'number' ? val : 0;
|
|
898
|
+
}
|
|
873
899
|
conditionData.push({
|
|
874
900
|
isMet: dynamicResult,
|
|
875
901
|
kind: 'dynamicTracker',
|
|
876
|
-
|
|
902
|
+
trackerAmount,
|
|
903
|
+
trackerGoal,
|
|
904
|
+
text: (0, template_1.renderTemplate)(conditions.dynamicTracker.template, primitiveTrackers) || 'Dynamic conditions',
|
|
877
905
|
});
|
|
878
906
|
if (!dynamicResult)
|
|
879
907
|
isValid = false;
|