@scm-js/plugin-api 1.47.0 → 1.49.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/index.d.ts +116 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -5029,6 +5029,111 @@ export interface FileTypeSpec {
|
|
|
5029
5029
|
extensions: string[];
|
|
5030
5030
|
open(files: File[]): void | Promise<void>;
|
|
5031
5031
|
}
|
|
5032
|
+
/**
|
|
5033
|
+
* Another way to look at a map, shown where the map is drawn (`ui.mapView`): a replay's
|
|
5034
|
+
* game played out, a 3D view, a picture of something else entirely. The editor gives the
|
|
5035
|
+
* view one element for its whole life and never moves it — an iframe in it is not loaded
|
|
5036
|
+
* again when the view is hidden and shown — and lays it over the map, rulers and all.
|
|
5037
|
+
*/
|
|
5038
|
+
export interface MapViewSpec {
|
|
5039
|
+
/** What the switch over the map calls it ("Game"). The map itself is "Map". */
|
|
5040
|
+
title: string;
|
|
5041
|
+
/**
|
|
5042
|
+
* Called once, with the element the view lives in. Fill it as you like; it is as large as
|
|
5043
|
+
* the map's area and in the page from the first time the view is shown. Return a function
|
|
5044
|
+
* to be called when the view goes (the plugin stops, or `dispose`).
|
|
5045
|
+
*/
|
|
5046
|
+
mount(element: HTMLElement): void | (() => void);
|
|
5047
|
+
/**
|
|
5048
|
+
* The view is shown in the map's place, where the map was looking: `look` is the map's view
|
|
5049
|
+
* at that moment, or the other view's (`setCamera`) when the switch came from one. Turn to
|
|
5050
|
+
* look at the same place, as near the same scale as you can, so the switch keeps the person
|
|
5051
|
+
* where they were. Not called when another map, already showing the view, comes to the front.
|
|
5052
|
+
*/
|
|
5053
|
+
onShow?(look: MapViewCamera): void;
|
|
5054
|
+
/**
|
|
5055
|
+
* What the minimap shows while the view is shown. Without it the minimap shows the map, and
|
|
5056
|
+
* its box and presses are the map's own view's (hidden behind this one).
|
|
5057
|
+
*/
|
|
5058
|
+
minimap?: MapViewMinimapSpec;
|
|
5059
|
+
}
|
|
5060
|
+
/**
|
|
5061
|
+
* Where a view looks, in map pixels (32 to a tile): the point in the middle of what it shows,
|
|
5062
|
+
* and how much of the map that is.
|
|
5063
|
+
*/
|
|
5064
|
+
export interface MapViewCamera {
|
|
5065
|
+
x: number;
|
|
5066
|
+
y: number;
|
|
5067
|
+
width: number;
|
|
5068
|
+
height: number;
|
|
5069
|
+
}
|
|
5070
|
+
/**
|
|
5071
|
+
* A map view's own minimap (`MapViewSpec.minimap`): the minimap draws the map's ground, then
|
|
5072
|
+
* `draw` over it in place of the map's units, start locations and fog, and its box where the
|
|
5073
|
+
* view looks (`MapViewHandle.setCamera`).
|
|
5074
|
+
*
|
|
5075
|
+
* @example
|
|
5076
|
+
* // A replay's units as dots, and the minimap moving the game's camera.
|
|
5077
|
+
* const view = api.ui.mapView({
|
|
5078
|
+
* title: "Replay",
|
|
5079
|
+
* mount: (el) => el.append(frame),
|
|
5080
|
+
* minimap: {
|
|
5081
|
+
* draw(ctx, m) {
|
|
5082
|
+
* for (const u of units) {
|
|
5083
|
+
* ctx.fillStyle = u.colour;
|
|
5084
|
+
* ctx.fillRect(m.x(u.x) - 1, m.y(u.y) - 1, Math.max(2, u.width * m.scale), Math.max(2, u.height * m.scale));
|
|
5085
|
+
* }
|
|
5086
|
+
* },
|
|
5087
|
+
* press: (x, y) => game.lookAt(x, y),
|
|
5088
|
+
* },
|
|
5089
|
+
* });
|
|
5090
|
+
* game.onUnits(() => view.redrawMinimap());
|
|
5091
|
+
* game.onCamera((c) => view.setCamera(c));
|
|
5092
|
+
*/
|
|
5093
|
+
export interface MapViewMinimapSpec {
|
|
5094
|
+
/** Draw over the map's ground, each time the minimap's picture is made while the view is shown. */
|
|
5095
|
+
draw?(ctx: CanvasRenderingContext2D, minimap: MinimapView): void;
|
|
5096
|
+
/**
|
|
5097
|
+
* A press on the minimap, and each move of a drag from it, at a map pixel: look there. Without
|
|
5098
|
+
* it the minimap does not move anything while the view is shown.
|
|
5099
|
+
*/
|
|
5100
|
+
press?(x: number, y: number): void;
|
|
5101
|
+
}
|
|
5102
|
+
/** Map pixels to minimap canvas pixels, for `MapViewMinimapSpec.draw`. */
|
|
5103
|
+
export interface MinimapView {
|
|
5104
|
+
/** Minimap canvas pixels per map pixel. */
|
|
5105
|
+
scale: number;
|
|
5106
|
+
/** A map pixel's x on the minimap's canvas. */
|
|
5107
|
+
x(px: number): number;
|
|
5108
|
+
y(py: number): number;
|
|
5109
|
+
/** The canvas's size in pixels, each side (the map is centred in it, letterboxed). */
|
|
5110
|
+
size: number;
|
|
5111
|
+
}
|
|
5112
|
+
export interface MapViewHandle extends Disposable {
|
|
5113
|
+
/**
|
|
5114
|
+
* Offer the view on a map (by `OpenDocumentInfo.id`; the one in front when left out), or
|
|
5115
|
+
* stop offering it there. A map that offers views has a switch over it, the map's own
|
|
5116
|
+
* view first. Nothing is offered until you say so.
|
|
5117
|
+
*/
|
|
5118
|
+
offer(on: boolean, documentId?: number): void;
|
|
5119
|
+
/** Show the view in that map's place (offering it there if it was not), or the map again. */
|
|
5120
|
+
show(on: boolean, documentId?: number): void;
|
|
5121
|
+
/** Whether the view is what the map in front shows now. */
|
|
5122
|
+
isShown(): boolean;
|
|
5123
|
+
/**
|
|
5124
|
+
* Whether the view is shown changed for the map in front: the person used the switch,
|
|
5125
|
+
* `show` was called, or another map came to the front.
|
|
5126
|
+
*/
|
|
5127
|
+
onChange(listener: (shown: boolean) => void): Disposable;
|
|
5128
|
+
/**
|
|
5129
|
+
* Where the view looks now, in map pixels; call it whenever that changes. The minimap draws
|
|
5130
|
+
* its box there while the view is shown, and the map, shown again, opens on the same place at
|
|
5131
|
+
* the same scale.
|
|
5132
|
+
*/
|
|
5133
|
+
setCamera(camera: MapViewCamera): void;
|
|
5134
|
+
/** Make the minimap's picture again (`minimap.draw`), at most once a frame. Cheap: call it as the view's contents move. */
|
|
5135
|
+
redrawMinimap(): void;
|
|
5136
|
+
}
|
|
5032
5137
|
export interface PanelHandle {
|
|
5033
5138
|
close(): void;
|
|
5034
5139
|
isOpen(): boolean;
|
|
@@ -5409,6 +5514,17 @@ export interface UiApi {
|
|
|
5409
5514
|
* api.ui.fileType({ name: "StarCraft replay", extensions: [".rep"], open: (files) => loadReplays(files) });
|
|
5410
5515
|
*/
|
|
5411
5516
|
fileType(spec: FileTypeSpec): Disposable;
|
|
5517
|
+
/**
|
|
5518
|
+
* Another way to look at the maps you choose, in the map's place, with a switch over the
|
|
5519
|
+
* map between it and the map itself (see `MapViewSpec`). A map shows one view at a time;
|
|
5520
|
+
* each map keeps the one it was left on. Ends with the plugin, or with `dispose`.
|
|
5521
|
+
*
|
|
5522
|
+
* @example
|
|
5523
|
+
* const game = api.ui.mapView({ title: "Game", mount: (el) => { el.append(frame); } });
|
|
5524
|
+
* // A map just opened is the one in front.
|
|
5525
|
+
* if (await api.document.open(map, "replay.scx", { viewOnly: { label: "Replay" } })) game.show(true);
|
|
5526
|
+
*/
|
|
5527
|
+
mapView(spec: MapViewSpec): MapViewHandle;
|
|
5412
5528
|
/**
|
|
5413
5529
|
* A cell of your own in the status bar. One line of text beside the plugin's icon, a
|
|
5414
5530
|
* spinner while `busy`, a click. Keep the handle and `set` it as things move; it
|