Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return produceFromBehavior(state, AccessorizerBehavior, behavior => {
const { accessoryName, accessoryType } = action.payload;
const { accessories } = behavior.templateData;
const accessoryIndex = getIndexOfAccessoryType(accessories, accessoryType);
if (accessoryName === null) {
// Remove
accessories.splice(accessoryIndex, 1);
return;
}
const newAccessory = Accessory(accessoryName);
if (accessoryIndex === -1) {
// Add
accessories.push(newAccessory);
} else {
// Replace
accessories[accessoryIndex] = newAccessory;
}
});
}
const accessoryMod: Record = {
[index]: Accessory(`${type}_${padStart(String(ordinal), 3, "0")}`)
};
if (type === "hair") {
const hatHair = getIndexOfAccessoryType(accessories, "hat_hair");
if (hatHair !== -1) {
accessoryMod[hatHair] = Accessory(
`hat_hair_${padStart(String(ordinal), 3, "0")}`
);
}
const hairAlways = getIndexOfAccessoryType(
accessories,
"hair_always"
);
if (hairAlways !== -1) {
accessoryMod[hairAlways] = Accessory(
`hair_always_${padStart(String(ordinal), 3, "0")}`
);
}
}
if (type === "body") {
const arm = getIndexOfAccessoryType(accessories, "arm");
accessoryMod[arm] = Accessory(
`arm_${padStart(String(ordinal), 3, "0")}`
);
}
onTemplateDataModify({
accessories: merge([], accessories, accessoryMod)
});
}