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
|
|
|
}
|
|
|
|
|
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,
|
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"),
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export function FillResources(data) {
|
|
|
|
return data.map((element, index) => {
|
|
|
|
element.counted_resources = CountResources(data, index);
|
|
|
|
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
|
|
|
}
|