2023-12-05 17:35:31 +08:00
|
|
|
const count_item_occupied_eem = (item) => {
|
2023-12-04 17:40:23 +08:00
|
|
|
if (!item.options_data
|
|
|
|
|| item.options_data.ext_pwr === false
|
|
|
|
|| item.options_data.mono_eem === false
|
|
|
|
)
|
2023-12-06 16:27:43 +08:00
|
|
|
return (item.consumes && item.consumes.eem) || 0;
|
2023-12-04 17:40:23 +08:00
|
|
|
else if (item.options_data.ext_pwr === true)
|
|
|
|
return 0;
|
|
|
|
else if (item.options_data.mono_eem === true || item.options_data.n_eem === "1 EEM")
|
|
|
|
return 1;
|
|
|
|
else if (item.options_data.n_eem === "3 EEM")
|
|
|
|
return 3;
|
|
|
|
|
2023-12-06 16:27:43 +08:00
|
|
|
return (item.consumes && item.consumes.eem) || 0;
|
2023-12-04 17:40:23 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 17:35:31 +08:00
|
|
|
const count_item_occupied_clock = (item) => {
|
2023-12-06 16:27:43 +08:00
|
|
|
return (item.options_data && (item.options_data.ext_clk === true || (item.options_data.ext_clk && item.options_data.ext_clk.checked === true)) ) ? 0 : ((item.consumes && item.consumes.clk) || 0);
|
2023-12-04 17:40:23 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 17:35:31 +08:00
|
|
|
const count_item_occupied_idc = (item) => {
|
2023-12-06 16:27:43 +08:00
|
|
|
return (item.consumes && item.consumes.idc) || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const count_item_occupied_hp = (item) => {
|
|
|
|
return (item.consumes && item.consumes.hp) || 0;
|
2023-12-04 17:40:23 +08:00
|
|
|
}
|
|
|
|
|
2024-07-04 13:28:02 +08:00
|
|
|
const count_item_occupied_tec = (item) => {
|
2024-12-23 12:51:39 +08:00
|
|
|
return (item.options_data && item.options_data.tec === false) ? 0 : ((item.consumes && item.consumes.tec) || 0);
|
2024-07-04 13:28:02 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 17:35:31 +08:00
|
|
|
export const item_occupied_counters = {
|
|
|
|
"eem": count_item_occupied_eem,
|
|
|
|
"clk": count_item_occupied_clock,
|
|
|
|
"idc": count_item_occupied_idc,
|
2024-07-04 13:28:02 +08:00
|
|
|
"tec": count_item_occupied_tec,
|
2023-12-06 16:27:43 +08:00
|
|
|
"hp": count_item_occupied_hp,
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 17:35:31 +08:00
|
|
|
function CounterFactory(name) {
|
|
|
|
return (data, index) => {
|
|
|
|
let count = 0;
|
|
|
|
for (let i = index + 1; i < data.length; i++) {
|
|
|
|
count += item_occupied_counters[name](data[i]);
|
2023-12-06 16:27:43 +08:00
|
|
|
if (data[i].resources && !!data[i].resources.find((value, _i) => value.name === name)) break;
|
2023-12-05 17:35:31 +08:00
|
|
|
}
|
|
|
|
return count;
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
export const resource_counters = {
|
2023-12-05 17:35:31 +08:00
|
|
|
"eem": CounterFactory("eem"),
|
|
|
|
"clk": CounterFactory("clk"),
|
2023-12-06 16:27:43 +08:00
|
|
|
"idc": CounterFactory("idc"),
|
|
|
|
"hp": CounterFactory("hp"),
|
2024-07-04 13:28:02 +08:00
|
|
|
"tec": CounterFactory("tec"),
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
export function CountResources(data, index) {
|
2023-12-01 17:36:55 +08:00
|
|
|
if (!data[index].resources) return null;
|
|
|
|
let result = [];
|
|
|
|
data[index].resources.forEach((item, _) => {
|
|
|
|
if (resource_counters[item.name]) result.push({
|
|
|
|
name: item.name,
|
|
|
|
occupied: resource_counters[item.name](data, index),
|
|
|
|
max: item.max
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return result;
|
2023-12-05 17:35:31 +08:00
|
|
|
}
|
|
|
|
|
2024-01-02 17:35:09 +08:00
|
|
|
export function FillResources(data, disabled) {
|
2023-12-05 17:35:31 +08:00
|
|
|
return data.map((element, index) => {
|
2024-01-02 17:35:09 +08:00
|
|
|
element.counted_resources = disabled ? [] : CountResources(data, index);
|
2023-12-05 17:35:31 +08:00
|
|
|
return element;
|
|
|
|
})
|
2023-12-07 17:08:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function hp_to_slots(hp) {
|
|
|
|
return Math.trunc(hp / 4);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|