@amxts/menu-core 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/PAWN.md CHANGED
@@ -22,8 +22,8 @@ A plugin compiled against it gets a tag warning for a bare number where `MenuPro
22
22
  - `mc_get_menu_property_string(idx, MP_SECTION)` gives the menu's section.
23
23
  - A condition filter applies wherever the condition is asked.
24
24
  - A restriction's `message` is shown beside an item it greys out when the item has no message of its own.
25
- - `IS_ALIVE`, `IS_DEAD`, `TEAM_<team>`, `IS_BOT`, `IS_ADMIN` and `FLAG_<letters>` are built-in conditions, answered while no plugin registers the name. A plugin that registers one of them answers instead.
26
- - `ADMIN` and `ACCESS_ADMIN` are not built in: they are names like any other, and a menu that uses them needs a plugin that registers them (`mc_register_condition`, `mc_register_restriction`). Otherwise the check says the name is not registered and suggests `IS_ADMIN`. Without a plugin, write `IS_ADMIN` (any admin) or `FLAG_<letters>` (`FLAG_dluy`: ban, rcon, admin or menu access).
25
+ - `IS_ALIVE`, `IS_DEAD`, `TEAM_<team>`, `IS_BOT`, `IS_ADMIN`, `ADMIN`, `ACCESS_ADMIN` and `FLAG_<letters>` are built-in conditions, answered while no plugin registers the name. A plugin that registers one of them answers instead.
26
+ - `ADMIN` and `ACCESS_ADMIN`, as conditions and as restrictions, hold for ban, rcon, admin or menu access (`FLAG_dluy`), as in the Pawn menu_core.
27
27
  - A restriction `NAME:text` takes the rest of the line, spaces and all, as its text; names before it are restrictions of their own.
28
28
  - Closing a menu because another opens over it tells the close callbacks its name.
29
29
  - A locked menu greys out the items of any menu, not only list rows.
package/PAWN.ru.md CHANGED
@@ -22,8 +22,8 @@ Pawn-плагины пишут `#include <menu_core>`; в пакете лежи
22
22
  - `mc_get_menu_property_string(idx, MP_SECTION)` отдаёт секцию меню.
23
23
  - Фильтр условия применяется везде, где спрашивают условие.
24
24
  - `message` ограничения показывается рядом с посеревшим пунктом, если у пункта нет своего сообщения.
25
- - `IS_ALIVE`, `IS_DEAD`, `TEAM_<команда>`, `IS_BOT`, `IS_ADMIN` и `FLAG_<буквы>` — встроенные условия, на них отвечает Menu Core, пока имя не регистрирует ни один плагин. Плагин, который регистрирует такое имя, отвечает вместо него.
26
- - `ADMIN` и `ACCESS_ADMIN` не встроены: это такие же имена, как любые другие, и меню, где они есть, нужен плагин, который их регистрирует (`mc_register_condition`, `mc_register_restriction`). Иначе проверка скажет, что имя не зарегистрировано, и предложит `IS_ADMIN`. Без плагина пишите `IS_ADMIN` (любой админ) или `FLAG_<буквы>` (`FLAG_dluy` — доступ ban, rcon, admin или menu).
25
+ - `IS_ALIVE`, `IS_DEAD`, `TEAM_<команда>`, `IS_BOT`, `IS_ADMIN`, `ADMIN`, `ACCESS_ADMIN` и `FLAG_<буквы>` — встроенные условия, на них отвечает Menu Core, пока имя не регистрирует ни один плагин. Плагин, который регистрирует такое имя, отвечает вместо него.
26
+ - `ADMIN` и `ACCESS_ADMIN` — и как условия, и как ограничения — выполняются при доступе ban, rcon, admin или menu (`FLAG_dluy`), как в Pawn menu_core.
27
27
  - Ограничение `NAME:текст` забирает остаток строки вместе с пробелами как свой текст; имена перед ним — отдельные ограничения.
28
28
  - Когда меню закрывается, потому что поверх открылось другое, колбэки закрытия получают его имя.
29
29
  - Заблокированное меню делает серыми пункты любого меню, а не только строки списков.
package/README.md CHANGED
@@ -123,7 +123,7 @@ const vote = menus.create("LIST_MAPS", { title: "Next map" });
123
123
  vote.setListSource(() => maps.map((map, index) => menus.listRow(index, map)));
124
124
  vote.addItem({
125
125
  title: ({ row }) => maps[row],
126
- onSelect: ({ player, row }) => print(0, `${player.name} votes for ${maps[row]}`),
126
+ onSelect: ({ player, row }) => player.print(`You vote for ${maps[row]}`),
127
127
  });
128
128
  ```
129
129
 
@@ -138,6 +138,9 @@ In code a requirement is a function. Names — `IS_ALIVE`, `FLAG_d`, a restricti
138
138
 
139
139
  Keys: **1–7** choose, **8** is the next page, **9** the previous page or back to the menu this one was opened from, **0** closes.
140
140
 
141
+ > [!WARNING]
142
+ > **Showing the menu a player is on:** from a command or a timer, `show()` opens it anew, at its first page. From one of its own items it stays on its page — and after an item's action the menu is drawn again by itself. `setPage(player, page)` is the page the next `show()` draws.
143
+
141
144
  Text colours are written as tags, the same letters as in chat: `!y` yellow, `!r` red, `!d` grey, `!w` white, `!R` aligns right. Chat's own `!g`, `!b` and `!t` are dropped from a menu.
142
145
 
143
146
  ### API
@@ -161,9 +164,9 @@ Its fields — `title`, `time`, `hideBack`, `hideExit`, `locked`, `sharedTimer`
161
164
  | Function | What it does |
162
165
  | --- | --- |
163
166
  | `create(name, options?)` | A menu in code, or the existing one with that name. A name starting with `LIST_` makes a list menu. Options: `title` (text or a function), `time`, `hideBack`, `hideExit`, `locked`, `activeWhen`. |
164
- | `find(name)` · `register(name)` | A menu by its name; `register` reads it from the file ahead of time. |
167
+ | `find(name)` · `register(...names)` | A menu by its name; `register` reads them from the file ahead of time: `register("MAIN_MENU", "ADMIN_MENU")`. |
165
168
  | `show(player, name, options?)` · `close(player)` · `activeMenu(player)` · `lock(player)` | The player's menu, whichever it is. |
166
- | `addCondition(name, test)` · `addAction(name, handler)` · `addPlaceholder(name, value)` · `addRestriction(name, test, message?)` | What menu files and Pawn plugins name, answered by functions — `%name%` in their text is a placeholder. An action, a placeholder and a restriction get the menu's context and the `name` they are asked by; a condition, `(player, viewer, name)`, is asked of the row's player in a list menu. A restriction's `message` is said beside an item it greys out, unless the item or the requirement has its own. `menu.addPlaceholder(name, value)` gives one to a single menu. |
169
+ | `addCondition(name, test)` · `addAction(name, handler)` · `addPlaceholder(name, value)` · `addRestriction(name, test, message?)` · `addActions({ NAME: handler })` · `addPlaceholders({ name: value })` | What menu files and Pawn plugins name, answered by functions — `%name%` in their text is a placeholder; `addActions` and `addPlaceholders` take several at once. An action or a placeholder is a function of the player, `(player) => ...`, or of the menu's context. An action, a placeholder and a restriction get the menu's context and the `name` they are asked by; a condition, `(player, viewer, name)`, is asked of the row's player in a list menu. A restriction's `message` is said beside an item it greys out, unless the item or the requirement has its own. `menu.addPlaceholder(name, value)` gives one to a single menu. |
167
170
  | `setListSource(name, rows)` · `refresh("A B")` · `conditionChanged(name)` · `addEventListener(type, listener)` | The same for menus by name, and every menu's events. |
168
171
 
169
172
  ## Menus in a file
@@ -280,7 +283,7 @@ VIEW = {
280
283
 
281
284
  | YAML, JSON | INI | What it is |
282
285
  | --- | --- | --- |
283
- | `chatPrefix` | `[MAIN]` `PREFIX` | The chat prefix of Menu Core's messages. |
286
+ | `chatPrefix` | `[MAIN]` `PREFIX` | The chat prefix of Menu Core's messages. The Pawn menu_core's `[Основное]` is read as `[MAIN]`. |
284
287
  | `labels`: `exit`, `back`, `next`, `number`, `disabled`, `page`, `time` | `[MAIN]` `KEY = { ... }` | The words of the buttons, the page and the countdown. |
285
288
  | `menus`: `{ NAME: menu }` | `[NAME]` | The menus; a name starting with `LIST_` is a list menu. |
286
289
  | `title` | `TITLE` | The title; a menu has one. |
@@ -317,6 +320,7 @@ A `visible`, `when`, `enabled`, `activeOn`, `action` or `onTimeout` is a name, s
317
320
  | `TEAM_CT` · `TEAM_TERRORIST` · `TEAM_SPECTATOR` · `TEAM_UNASSIGNED` | is in that team |
318
321
  | `IS_BOT` | is a bot |
319
322
  | `IS_ADMIN` | has any access but a plain user's `z` — AMX Mod X's `is_user_admin` |
323
+ | `ADMIN` · `ACCESS_ADMIN` | has ban, rcon, admin or menu access — `FLAG_dluy`, as the Pawn menu_core answered them |
320
324
  | `FLAG_<letters>` | has any of those `users.ini` letters: `FLAG_ab` |
321
325
 
322
326
  In a list menu, a condition of the view or a filter is asked of the row's player, and a restriction gets the row as its target. The names are case-insensitive.
@@ -332,7 +336,6 @@ A `visible`, `when`, `enabled`, `activeOn`, `action` or `onTimeout` is a name, s
332
336
  > - **An item's name in YAML or JSON is not split on `|`:** its faces are written with `variants`.
333
337
  > - **Colours** are tags in a menu file too: `!y`, `!r`, `!d`, `!w`, `!R`. Pawn's codes (`\y`, `\r`) are warned of, with the tag to write, and left out. Text from Pawn — a Pawn plugin's items and titles, a lang dictionary — keeps its codes, and Menu Core reads them as the tags.
334
338
  > - **`%time%` and `%target%` are lower case:** `%TIME%` and `%s` are left as written.
335
- > - **`ADMIN` and `ACCESS_ADMIN` are not built in:** a plugin registers them, or the file writes `IS_ADMIN` (any admin) or `FLAG_<letters>` (`FLAG_d`).
336
339
 
337
340
  ### INI's columns
338
341
 
package/README.ru.md CHANGED
@@ -123,7 +123,7 @@ const vote = menus.create("LIST_MAPS", { title: "Следующая карта"
123
123
  vote.setListSource(() => maps.map((map, index) => menus.listRow(index, map)));
124
124
  vote.addItem({
125
125
  title: ({ row }) => maps[row],
126
- onSelect: ({ player, row }) => print(0, `${player.name} голосует за ${maps[row]}`),
126
+ onSelect: ({ player, row }) => player.print(`Ты голосуешь за ${maps[row]}`),
127
127
  });
128
128
  ```
129
129
 
@@ -138,6 +138,9 @@ vote.addItem({
138
138
 
139
139
  Клавиши: **1–7** выбирают, **8** — следующая страница, **9** — предыдущая страница или назад, в меню, из которого открыли это, **0** закрывает.
140
140
 
141
+ > [!WARNING]
142
+ > **Показ меню, в котором игрок уже находится:** из команды или таймера `show()` открывает его заново, с первой страницы. Из его собственного пункта меню остаётся на своей странице — а после действия пункта меню и так рисуется снова. `setPage(player, page)` — страница, которую нарисует следующий `show()`.
143
+
141
144
  Цвета в тексте пишутся метками, теми же буквами, что в чате: `!y` жёлтый, `!r` красный, `!d` серый, `!w` белый, `!R` — выравнивание вправо. Метки только для чата — `!g`, `!b` и `!t` — из меню убираются.
142
145
 
143
146
  ### API
@@ -161,9 +164,9 @@ vote.addItem({
161
164
  | Функция | Что делает |
162
165
  | --- | --- |
163
166
  | `create(name, options?)` | Меню в коде или уже существующее с таким именем. Имя с `LIST_` делает меню-список. Опции: `title` (текст или функция), `time`, `hideBack`, `hideExit`, `locked`, `activeWhen`. |
164
- | `find(name)` · `register(name)` | Меню по имени; `register` заранее читает его из файла. |
167
+ | `find(name)` · `register(...names)` | Меню по имени; `register` заранее читает их из файла: `register("MAIN_MENU", "ADMIN_MENU")`. |
165
168
  | `show(player, name, options?)` · `close(player)` · `activeMenu(player)` · `lock(player)` | Меню игрока, какое бы оно ни было. |
166
- | `addCondition(name, test)` · `addAction(name, handler)` · `addPlaceholder(name, value)` · `addRestriction(name, test, message?)` | То, что называют файлы меню и Pawn-плагины, — ответы функциями; `%name%` в их тексте — плейсхолдер. Действие, плейсхолдер и ограничение получают контекст меню и имя `name`, по которому их спросили; условие, `(player, viewer, name)`, в меню-списке спрашивается об игроке строки. `message` ограничения пишется рядом с пунктом, который оно гасит, если у пункта или требования нет своего. `menu.addPlaceholder(name, value)` задаёт его одному меню. |
169
+ | `addCondition(name, test)` · `addAction(name, handler)` · `addPlaceholder(name, value)` · `addRestriction(name, test, message?)` · `addActions({ NAME: handler })` · `addPlaceholders({ name: value })` | То, что называют файлы меню и Pawn-плагины, — ответы функциями; `%name%` в их тексте — плейсхолдер; `addActions` и `addPlaceholders` принимают несколько сразу. Действие или плейсхолдер — функция игрока, `(player) => ...`, или контекста меню. Действие, плейсхолдер и ограничение получают контекст меню и имя `name`, по которому их спросили; условие, `(player, viewer, name)`, в меню-списке спрашивается об игроке строки. `message` ограничения пишется рядом с пунктом, который оно гасит, если у пункта или требования нет своего. `menu.addPlaceholder(name, value)` задаёт его одному меню. |
167
170
  | `setListSource(name, rows)` · `refresh("A B")` · `conditionChanged(name)` · `addEventListener(type, listener)` | То же для меню по имени и события всех меню. |
168
171
 
169
172
  ## Меню в файле
@@ -280,7 +283,7 @@ VIEW = {
280
283
 
281
284
  | YAML, JSON | INI | Что это |
282
285
  | --- | --- | --- |
283
- | `chatPrefix` | `[MAIN]` `PREFIX` | Префикс сообщений Menu Core в чате. |
286
+ | `chatPrefix` | `[MAIN]` `PREFIX` | Префикс сообщений Menu Core в чате. `[Основное]` из Pawn-модуля menu_core читается как `[MAIN]`. |
284
287
  | `labels`: `exit`, `back`, `next`, `number`, `disabled`, `page`, `time` | `[MAIN]` `KEY = { ... }` | Слова кнопок, страницы и отсчёта. |
285
288
  | `menus`: `{ NAME: меню }` | `[NAME]` | Меню; имя на `LIST_` — меню-список. |
286
289
  | `title` | `TITLE` | Заголовок; он у меню обязателен. |
@@ -317,6 +320,7 @@ VIEW = {
317
320
  | `TEAM_CT` · `TEAM_TERRORIST` · `TEAM_SPECTATOR` · `TEAM_UNASSIGNED` | в этой команде |
318
321
  | `IS_BOT` | бот |
319
322
  | `IS_ADMIN` | имеет любой доступ, кроме `z` простого игрока, — `is_user_admin` AMX Mod X |
323
+ | `ADMIN` · `ACCESS_ADMIN` | имеет доступ ban, rcon, admin или menu — `FLAG_dluy`, как отвечал Pawn menu_core |
320
324
  | `FLAG_<буквы>` | имеет любую из этих букв `users.ini`: `FLAG_ab` |
321
325
 
322
326
  В меню-списке условие вида или фильтра спрашивается у игрока строки, а ограничение получает строку как цель. Регистр в именах не важен.
@@ -332,7 +336,6 @@ VIEW = {
332
336
  > - **Имя пункта в YAML или JSON не делится по `|`:** его варианты пишутся через `variants`.
333
337
  > - **Цвета** и в файле меню пишутся метками: `!y`, `!r`, `!d`, `!w`, `!R`. На коды Pawn (`\y`, `\r`) будет предупреждение с меткой, которую писать, и они выбрасываются. Текст из Pawn — пункты и заголовки Pawn-плагина, словарь lang — сохраняет свои коды, и Menu Core читает их как метки.
334
338
  > - **`%time%` и `%target%` пишутся строчными:** `%TIME%` и `%s` остаются как написаны.
335
- > - **`ADMIN` и `ACCESS_ADMIN` не встроены:** их регистрирует плагин, или файл пишет `IS_ADMIN` (любой админ) или `FLAG_<буквы>` (`FLAG_d`).
336
339
 
337
340
  ### Столбцы INI
338
341
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@amxts/menu-core",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "description": "Menus for amxts plugins, from ini files or code: conditions, placeholders, lists - and the mc_* natives for Pawn plugins.",
6
6
  "author": {
7
7
  "name": "kukson777",
@@ -49,8 +49,8 @@
49
49
  "lint:fix": "oxfmt && oxlint --fix --silent || oxlint --fix --silent || oxlint --fix"
50
50
  },
51
51
  "peerDependencies": {
52
- "@amxts/config-core": "^0.1.2",
53
- "@amxts/core": "^0.2.2"
52
+ "@amxts/config-core": "^0.2.0",
53
+ "@amxts/core": "^0.3.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@e18e/eslint-plugin": "^0.8.1",
Binary file