mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
Merge branch 'explosivegaming:main' into translate
This commit is contained in:
@@ -4,8 +4,8 @@ import { RoleMetaRecord, type ControllerPlugin as RolesPlugin } from "@expcluste
|
||||
import {
|
||||
GroupRecord, GroupPermissions, RoleMappingRecord, type ControllerPlugin as GroupsPlugin,
|
||||
} from "@expcluster/permission-groups";
|
||||
import * as messages from "./messages";
|
||||
import { SeedRole, SeedGroup, seedRoles, seedGroups, flattenSeedPermissions } from "./seed";
|
||||
import * as messages from "./messages.js";
|
||||
import { SeedRole, SeedGroup, seedRoles, seedGroups, flattenSeedPermissions } from "./seed.js";
|
||||
|
||||
export class ControllerPlugin extends BaseControllerPlugin {
|
||||
async init() {
|
||||
|
||||
+29
-25
@@ -1,41 +1,45 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "./messages";
|
||||
|
||||
// Defines a permission for every in game action and role flag used by the scenario
|
||||
import "./permissions";
|
||||
|
||||
lib.definePermission({
|
||||
name: "exp_scenario.config.view",
|
||||
title: "View ExpScenario Config",
|
||||
description: "View the config for all submodules of ExpScenario",
|
||||
});
|
||||
|
||||
lib.definePermission({
|
||||
name: "exp_scenario.config.edit",
|
||||
title: "Edit ExpScenario Config",
|
||||
description: "Edit the config for all submodules of ExpScenario",
|
||||
});
|
||||
|
||||
lib.definePermission({
|
||||
name: "exp_scenario.seed",
|
||||
title: "Seed ExpScenario roles and groups",
|
||||
description: "Create the roles and permission groups the scenario shipped with",
|
||||
});
|
||||
import * as messages from "./messages.js";
|
||||
import { permissions as scenarioPermissions, type ScenarioPermissionName } from "./permissions.js";
|
||||
|
||||
declare module "@clusterio/lib" {
|
||||
|
||||
// Everything checked in game through exp_roles, plus the permissions checked on the controller
|
||||
export interface Permissions extends Record<ScenarioPermissionName, never> {
|
||||
"exp_scenario.config.view": never;
|
||||
"exp_scenario.config.edit": never;
|
||||
"exp_scenario.seed": never;
|
||||
}
|
||||
}
|
||||
|
||||
export const plugin: lib.PluginDeclaration = {
|
||||
name: "exp_scenario",
|
||||
title: "exp_scenario",
|
||||
description: "Example Description. Plugin. Change me in index.ts",
|
||||
controllerEntrypoint: "./dist/node/controller",
|
||||
instanceEntrypoint: "./dist/node/instance",
|
||||
controllerEntrypoint: "./dist/node/controller.js",
|
||||
instanceEntrypoint: "./dist/node/instance.js",
|
||||
|
||||
messages: [
|
||||
messages.SeedRequest,
|
||||
],
|
||||
|
||||
permissions: [
|
||||
...scenarioPermissions,
|
||||
{
|
||||
name: "exp_scenario.config.view",
|
||||
title: "View ExpScenario Config",
|
||||
description: "View the config for all submodules of ExpScenario",
|
||||
},
|
||||
{
|
||||
name: "exp_scenario.config.edit",
|
||||
title: "Edit ExpScenario Config",
|
||||
description: "Edit the config for all submodules of ExpScenario",
|
||||
},
|
||||
{
|
||||
name: "exp_scenario.seed",
|
||||
title: "Seed ExpScenario roles and groups",
|
||||
description: "Create the roles and permission groups the scenario shipped with",
|
||||
},
|
||||
],
|
||||
|
||||
webEntrypoint: "./web",
|
||||
};
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
"author": "Cooldude2606 <https://github.com/Cooldude2606>",
|
||||
"license": "MIT",
|
||||
"repository": "explosivegaming/ExpCluster",
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --env production",
|
||||
"test": "tap --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"test": "tap --type-strip-only --disable-coverage --allow-empty-coverage test/*.test.js",
|
||||
"coverage": "tap --coverage-report=text test/*.test.js"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import type * as lib from "@clusterio/lib";
|
||||
|
||||
/**
|
||||
* Permissions checked by the scenario in game through exp_roles.
|
||||
@@ -7,9 +7,9 @@ import * as lib from "@clusterio/lib";
|
||||
* underscores, see module/commands/_authorities.lua. Everything else is checked
|
||||
* by name at its call site.
|
||||
*/
|
||||
type Definition = [name: string, title: string, description: string, grantByDefault?: boolean];
|
||||
type Definition<Name extends string = string> = readonly [name: Name, title: string, description: string, grantByDefault?: boolean];
|
||||
|
||||
const definitions: Definition[] = [
|
||||
const definitions = [
|
||||
["exp_scenario.bypass.deconstruction_log", "Deconstruction log bypass", "Be excluded from the deconstruction log."],
|
||||
["exp_scenario.bypass.entity_protection", "Bypass entity protection", "Remove entities that the protection filter would block."],
|
||||
["exp_scenario.bypass.nuke_protection", "Bypass nuke protection", "Use nukes without the nuke protection restrictions."],
|
||||
@@ -118,8 +118,12 @@ const definitions: Definition[] = [
|
||||
["exp_scenario.player.admin", "Factorio admin", "Be promoted to Factorio admin while holding a role with this permission."],
|
||||
["exp_scenario.player.instant_respawn", "Instant respawn", "Respawn after two seconds instead of the default delay."],
|
||||
["exp_scenario.player.spectator", "Spectator", "Remove the zoom to world noise effect, as Factorio does for spectators."],
|
||||
];
|
||||
] as const satisfies readonly Definition[];
|
||||
|
||||
for (const [name, title, description, grantByDefault] of definitions) {
|
||||
lib.definePermission({ name, title, description, grantByDefault });
|
||||
}
|
||||
/** Name of a permission defined by the scenario, added to lib.Permissions in index.ts. */
|
||||
export type ScenarioPermissionName = (typeof definitions)[number][0];
|
||||
|
||||
export const permissions = definitions.map((definition: Definition<ScenarioPermissionName>): lib.PermissionDefinition => {
|
||||
const [name, title, description, grantByDefault] = definition;
|
||||
return { name, title, description, grantByDefault };
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type * as lib from "@clusterio/lib";
|
||||
import { RoleColor } from "@expcluster/roles";
|
||||
|
||||
/**
|
||||
@@ -19,7 +20,7 @@ export interface SeedRole {
|
||||
isAdmin?: boolean;
|
||||
/** Name of the role whose permissions are also granted, applied recursively. */
|
||||
parent?: string;
|
||||
permissions: string[];
|
||||
permissions: lib.PermissionName[];
|
||||
/**
|
||||
* Name of the seed group holders are placed in by their highest role.
|
||||
* Without one the holders stay in Factorio's Default group.
|
||||
@@ -329,7 +330,7 @@ export const seedGroups: SeedGroup[] = [
|
||||
|
||||
/** The permissions a seed role grants, including those of its parents. */
|
||||
export function flattenSeedPermissions(role: SeedRole, roles = seedRoles) {
|
||||
const permissions = new Set<string>();
|
||||
const permissions = new Set<lib.PermissionName>();
|
||||
const seen = new Set<string>();
|
||||
let current: SeedRole | undefined = role;
|
||||
while (current && !seen.has(current.name)) {
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
"use strict";
|
||||
const t = require("tap");
|
||||
const lib = require("@clusterio/lib");
|
||||
const { Controller } = require("@clusterio/controller");
|
||||
const { ControllerPlugin } = require("../dist/node/controller");
|
||||
const messages = require("../dist/node/messages");
|
||||
const { seedRoles, seedGroups } = require("../dist/node/seed");
|
||||
const roles = require("@expcluster/roles");
|
||||
const groups = require("@expcluster/permission-groups");
|
||||
const { ControllerPlugin: RolesPlugin } = require("@expcluster/roles/dist/node/controller");
|
||||
const { ControllerPlugin: GroupsPlugin } = require("@expcluster/permission-groups/dist/node/controller");
|
||||
const { GroupRecord, GroupPermissions, RoleMappingRecord } = require("@expcluster/permission-groups");
|
||||
import t from "tap";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { Controller } from "@clusterio/controller";
|
||||
import { ControllerPlugin } from "../dist/node/controller.js";
|
||||
import * as messages from "../dist/node/messages.js";
|
||||
import { seedRoles, seedGroups } from "../dist/node/seed.js";
|
||||
import * as roles from "@expcluster/roles";
|
||||
import * as groups from "@expcluster/permission-groups";
|
||||
import { ControllerPlugin as RolesPlugin } from "@expcluster/roles/dist/node/controller.js";
|
||||
import { ControllerPlugin as GroupsPlugin } from "@expcluster/permission-groups/dist/node/controller.js";
|
||||
import { GroupRecord, GroupPermissions, RoleMappingRecord } from "@expcluster/permission-groups";
|
||||
|
||||
// Importing this defines the permissions the seed grants
|
||||
require("../dist/node/permissions");
|
||||
import { plugin } from "../dist/node/index.js";
|
||||
|
||||
// Registering the plugin defines the permissions the seed grants
|
||||
lib.registerPluginPermissions([plugin]);
|
||||
|
||||
// The controller validates message classes against the link registry
|
||||
for (const Message of [messages.SeedRequest, ...roles.plugin.messages, ...groups.plugin.messages]) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
"use strict";
|
||||
const t = require("tap");
|
||||
const lib = require("@clusterio/lib");
|
||||
const { seedRoles, seedGroups, flattenSeedPermissions } = require("../dist/node/seed");
|
||||
import t from "tap";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { seedRoles, seedGroups, flattenSeedPermissions } from "../dist/node/seed.js";
|
||||
|
||||
// Importing this defines the permissions the seed grants
|
||||
require("../dist/node/permissions");
|
||||
import { plugin } from "../dist/node/index.js";
|
||||
|
||||
// Registering the plugin defines the permissions the seed grants
|
||||
lib.registerPluginPermissions([plugin]);
|
||||
|
||||
t.test("seedRoles[] grant only defined permissions", t2 => {
|
||||
for (const role of seedRoles) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.browser.json",
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "messages.ts", "package.json" ],
|
||||
"include": [ "web/**/*.tsx", "web/**/*.ts", "index.ts", "messages.ts", "permissions.ts", "package.json" ],
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Button, Popconfirm } from "antd";
|
||||
|
||||
import { ControlContext, SectionHeader, useAccount, notifyErrorHandler } from "@clusterio/web_ui";
|
||||
|
||||
import { SeedRequest } from "../../messages";
|
||||
import { SeedRequest } from "../../messages.js";
|
||||
|
||||
/** Button on the roles page which creates the roles and permission groups the scenario shipped with. */
|
||||
export default function Seed() {
|
||||
|
||||
Reference in New Issue
Block a user