2023-12-01 17:36:55 +08:00
|
|
|
import {OverlayTrigger} from "react-bootstrap";
|
|
|
|
import React from "react";
|
2023-12-05 17:35:31 +08:00
|
|
|
import {v4 as uuidv4} from "uuid";
|
2023-12-14 16:29:32 +08:00
|
|
|
|
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
import {useRenderCount} from "@uidotdev/usehooks";
|
2023-12-15 13:49:54 +08:00
|
|
|
import {useShopStore} from "./shop_store";
|
|
|
|
import {compareArraysLevelOne} from "./utils";
|
2023-12-01 17:36:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
const resourcesWidthStyle = (occupied, max) => {
|
|
|
|
return {
|
|
|
|
width: `${Math.min(occupied * 100 / max, 100)}%`,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function EEMRenderer({occupied, max}) {
|
|
|
|
return (
|
2023-12-05 17:35:31 +08:00
|
|
|
<div className="nbr-connectors" key={uuidv4()}>
|
2023-12-01 17:36:55 +08:00
|
|
|
<div style={{...resourcesWidthStyle(occupied, max)}}></div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function ClockRenderer({occupied, max}) {
|
|
|
|
return (
|
2023-12-05 17:35:31 +08:00
|
|
|
<div className="nbr-clocks" key={uuidv4()}>
|
2023-12-01 17:36:55 +08:00
|
|
|
<div style={{...resourcesWidthStyle(occupied, max)}}></div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const resource_progress_renderers = {
|
|
|
|
"eem": EEMRenderer,
|
|
|
|
"clk": ClockRenderer,
|
|
|
|
"idc": EEMRenderer
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function EEMTipRender({occupied, max}) {
|
2023-12-05 17:35:31 +08:00
|
|
|
return (<p key={uuidv4()}>{`${occupied}/${max} EEM connectors used`}</p>);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function IDCTipRender({occupied, max}) {
|
2023-12-05 17:35:31 +08:00
|
|
|
return (<p key={uuidv4()}>{`${occupied}/${max} IDC connectors used`}</p>);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function ClockTipRender({occupied, max}) {
|
2023-12-05 17:35:31 +08:00
|
|
|
return (<p key={uuidv4()}>{`${occupied}/${max} clock connectors used`}</p>);
|
2023-12-01 17:36:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const resource_tip = {
|
|
|
|
"eem": EEMTipRender,
|
|
|
|
"clk": ClockTipRender,
|
|
|
|
"idc": IDCTipRender
|
|
|
|
}
|
|
|
|
|
|
|
|
function RenderResources({resources, library}) {
|
|
|
|
if (!resources) return null;
|
|
|
|
let result = [];
|
|
|
|
|
|
|
|
resources.forEach((value, _) => {
|
|
|
|
if (library[value.name]) result.push(library[value.name](value));
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-12-15 13:49:54 +08:00
|
|
|
export function Resources({crate_index, card_index}) {
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
const renderCount = useRenderCount();
|
2023-12-15 13:49:54 +08:00
|
|
|
|
|
|
|
const resources = useShopStore(state => state.crates[crate_index].items[card_index].counted_resources, compareArraysLevelOne);
|
|
|
|
|
2023-12-14 16:29:32 +08:00
|
|
|
// #!render_count
|
2023-12-14 16:09:33 +08:00
|
|
|
console.log("Resources renders: ", renderCount)
|
2023-12-01 17:36:55 +08:00
|
|
|
return (
|
|
|
|
<OverlayTrigger
|
|
|
|
placement="top"
|
|
|
|
trigger={['click', 'hover', 'focus']}
|
|
|
|
overlay={({arrowProps, hasDoneInitialMeasure, show, ...props}) => (
|
|
|
|
<div className="k-popup-connectors" {...props}>
|
|
|
|
<RenderResources
|
|
|
|
resources={resources}
|
|
|
|
library={resource_tip}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
rootClose
|
|
|
|
>
|
|
|
|
<div className="progress-container">
|
|
|
|
<RenderResources
|
|
|
|
resources={resources}
|
|
|
|
library={resource_progress_renderers}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</OverlayTrigger>
|
|
|
|
)
|
|
|
|
}
|