diff --git a/exp_roles/web/components/RoleProperties.tsx b/exp_roles/web/components/RoleProperties.tsx index 53f6ca99..c68d5f49 100644 --- a/exp_roles/web/components/RoleProperties.tsx +++ b/exp_roles/web/components/RoleProperties.tsx @@ -5,7 +5,7 @@ import * as lib from "@clusterio/lib"; import { ControlContext, SectionHeader, useAccount, notifyErrorHandler } from "@clusterio/web_ui"; import { RoleColor, RoleMetaRecord, RoleMetaUpdateRequest } from "../../messages.js"; -import type { WebPlugin } from ".."; +import { useRoles } from ".."; const MS_PER_HOUR = 3600000; @@ -25,13 +25,13 @@ type RoleFormValues = { * The name, description and permissions of a role are owned by clusterio, this * only covers the properties which only mean something in game. */ -export default function RoleProperties(props: { plugin: WebPlugin, role?: lib.Role }) { +export default function RoleProperties(props: { role?: lib.Role }) { const control = useContext(ControlContext); const account = useAccount(); + const [roles] = useRoles(); const [form] = Form.useForm(); const [applying, setApplying] = useState(false); - const [roles] = props.plugin.useRoles(); const record = props.role ? roles.get(props.role.id) : undefined; const meta = record?.meta; const canUpdate = account.hasPermission("core.role.update"); diff --git a/exp_roles/web/index.tsx b/exp_roles/web/index.tsx index 36e9de1d..0753cf9c 100644 --- a/exp_roles/web/index.tsx +++ b/exp_roles/web/index.tsx @@ -1,24 +1,22 @@ import React, { useCallback, useSyncExternalStore } from "react"; -import { BaseWebPlugin } from "@clusterio/web_ui"; +import { WebPluginContext } from "@clusterio/web_ui"; import * as lib from "@clusterio/lib"; import * as messages from "../messages.js"; import RoleProperties from "./components/RoleProperties"; -export class WebPlugin extends BaseWebPlugin { - roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, this.control); +let roles: lib.MapSubscriber | undefined; - async init() { - // The core components pass a role and the plugin, which componentExtra - // does not carry in its type - this.componentExtra = { - RoleViewPage: RoleProperties as React.ComponentType, - }; - } +export function useRoles() { + const subscribe = useCallback((cb: () => void) => roles!.subscribe(cb), []); + return useSyncExternalStore(subscribe, () => roles!.getSnapshot()); +} - useRoles() { - const subscribe = useCallback((cb: () => void) => this.roles.subscribe(cb), []); - return useSyncExternalStore(subscribe, () => this.roles.getSnapshot()); - } +export default function registerPlugin(context: WebPluginContext) { + context.control.hooks.extensionComponents.attach("exp_roles", () => ({ + RoleViewPage: RoleProperties, + })); + + roles = new lib.MapSubscriber(messages.RoleUpdatedEvent, context.control); } diff --git a/exp_scenario/controller.ts b/exp_scenario/controller.ts index 05d3303e..e76d0c8e 100644 --- a/exp_scenario/controller.ts +++ b/exp_scenario/controller.ts @@ -19,6 +19,8 @@ export class ControllerPlugin extends BaseControllerPlugin { * permissions, groups which already exist by name are reset to the seed. */ async handleSeedRequest() { + throw new lib.RequestError("Seeding is temporarily disabled, please contact the server administrator to seed the roles and groups"); + /* const rolesPlugin = this.controller.plugins.get("exp_roles") as RolesPlugin | undefined; const groupsPlugin = this.controller.plugins.get("exp_groups") as GroupsPlugin | undefined; if (!rolesPlugin || !groupsPlugin) { @@ -52,6 +54,7 @@ export class ControllerPlugin extends BaseControllerPlugin { this.seedRoleMappings(groupsPlugin, roleIds, groupIds); this.logger.info(`Seeded ${roleIds.size} roles and ${groupIds.size} permission groups`); + */ } /** Find or create the clusterio role for a seed role, returns undefined if it has no role to use. */