2023-12-01 11:52:37 +08:00
|
|
|
import {apply as json_logic_apply} from "json-logic-js";
|
2023-11-30 17:26:17 +08:00
|
|
|
import {componentsList} from "./components/components";
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/70511311
|
|
|
|
export const true_type_of = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
|
|
|
|
|
2024-01-30 13:02:01 +08:00
|
|
|
export function FillExtCardData(data, index) {
|
2023-11-30 17:26:17 +08:00
|
|
|
return {
|
|
|
|
has_other_dio: data.filter((value, item_index) => index !== item_index && value.name &&value.name.endsWith("-TTL")).length > 0,
|
|
|
|
has_dds: data.filter(((value, _) => value.name === "DDS" && value.name_number === "4410" && (!value.options_data || !value.options_data.mono_eem))).length > 0,
|
|
|
|
has_sampler: data.filter(((value, _) => value.name === "Sampler" && (!value.options_data || !value.options_data.mono_eem))).length > 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:02:01 +08:00
|
|
|
export function FillExtCrateData(crate) {
|
|
|
|
return {
|
|
|
|
crate_mode: crate.crate_mode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 17:20:29 +08:00
|
|
|
export function FillExtOrderData(crates, modes_order) {
|
|
|
|
return {
|
|
|
|
has_crate: crates.filter((crate) => modes_order.includes(crate.crate_mode)).length >= 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 17:26:17 +08:00
|
|
|
export function FilterOptions(options, data) {
|
|
|
|
let options_t = true_type_of(options);
|
|
|
|
let target = {};
|
|
|
|
|
|
|
|
if (options_t === "array") {
|
|
|
|
options.map((option_item, _) => {
|
|
|
|
Object.assign(target, FilterOptions(option_item, data))
|
|
|
|
});
|
|
|
|
} else if (options_t === "object") {
|
|
|
|
if (
|
|
|
|
true_type_of(options.type) === "string" &&
|
|
|
|
(true_type_of(options.args) === "object" || true_type_of(options.items) === "array")
|
|
|
|
) {
|
|
|
|
if (options.type in componentsList) {
|
|
|
|
target[options.args.outvar] = data[options.args.outvar];
|
|
|
|
} else if (options.type === "Group") {
|
2023-12-01 11:52:37 +08:00
|
|
|
Object.assign(target, FilterOptions(json_logic_apply(options.items, data), data))
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|
|
|
|
} else {
|
2023-12-01 11:52:37 +08:00
|
|
|
Object.assign(target, FilterOptions(json_logic_apply(options, data), data))
|
2023-11-30 17:26:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return target
|
|
|
|
}
|