mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-11 15:54:52 +09:00
The plugin is now exp_player_statistics (@expcluster/player-statistics), with the module, global, permission, route and database directory renamed to match. The exp-statistics locale section keeps its name. Every statistic is tracked unconditionally, so the enable flags are gone from config.lua. Playtime and JoinCount are no longer counted in game: clusterio already keeps online time and joins for each user, so the controller fills them in from the user when a player's totals are requested, and the web page does the same from the user list. They are not stored or adjusted by the plugin. The web table has a column picker, a multiple select with check boxes, Select all and Reset buttons, showing "N statistics selected". The choice is kept in local storage. The user page shows the statistics of the player in a grid like the core player stats. The readme statistics table drops its second title and uses the short time format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import React, { useContext, useEffect, useState } from "react";
|
|
import { Descriptions } from "antd";
|
|
|
|
import { ControlContext, PluginExtensionProps, SectionHeader, notifyErrorHandler, useAccount } from "@clusterio/web_ui";
|
|
|
|
import { PlayerStatistics, StatisticsGetRequest } from "../../messages.js";
|
|
import { formatValue, statistics } from "../statistics";
|
|
|
|
/** The statistics of a player, shown on their user page. */
|
|
export default function UserStatistics(props: PluginExtensionProps<"UserViewPage">) {
|
|
const control = useContext(ControlContext);
|
|
const account = useAccount();
|
|
const canView = Boolean(account.hasPermission("exp_player_statistics.view"));
|
|
const name = props.user.name;
|
|
const [record, setRecord] = useState<PlayerStatistics>();
|
|
|
|
useEffect(() => {
|
|
if (canView) {
|
|
control.send(new StatisticsGetRequest(name))
|
|
.then(setRecord)
|
|
.catch(notifyErrorHandler("Error loading player statistics"));
|
|
}
|
|
}, [name, canView]);
|
|
|
|
if (!canView || !record) {
|
|
return null;
|
|
}
|
|
|
|
return <>
|
|
<SectionHeader title="Statistics" />
|
|
<Descriptions size="small" bordered column={{ xs: 1, sm: 2, md: 2, lg: 2, xl: 2, xxl: 2 }}>
|
|
{statistics.map(([statistic, title]) => <Descriptions.Item key={statistic} label={title}>
|
|
{formatValue(statistic, record.stats[statistic] ?? 0)}
|
|
</Descriptions.Item>)}
|
|
</Descriptions>
|
|
</>;
|
|
}
|