Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
behavior => {
const oldAccessories = behavior.parsedData!.accessories;
const accIndex = getIndexOfAccessoryType(oldAccessories, accessoryType);
const newAccessory: Accessory = {
guid: {
Guid: accessoryID
}
};
let accessories: Accessory[];
if (accIndex !== -1) {
accessories = [
...oldAccessories.slice(0, accIndex),
newAccessory,
...oldAccessories.slice(accIndex + 1)
];
}
else {
accessories = [
...oldAccessories,
function setAccessory(type: AccessoryType, ordinal: number) {
const index = getIndexOfAccessoryType(accessories, type);
if (index === -1) {
return;
}
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({
private _setMouth(value: string) {
const { duplicant } = this.props;
const accessorizer = duplicant.getBehavior(AccessorizerBehavior);
if (!accessorizer) return;
const accessories = accessorizer.templateData.accessories;
const index = getIndexOfAccessoryType(accessories, "mouth");
if (index == -1) return;
accessories[index].guid.Guid = value;
}
function setAccessory(type: AccessoryType, ordinal: number) {
const index = getIndexOfAccessoryType(accessories, type);
if (index === -1) {
return;
}
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") {
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)
});
}