@scm-js/plugin-api 1.48.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 +72 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -5044,6 +5044,70 @@ export interface MapViewSpec {
|
|
|
5044
5044
|
* to be called when the view goes (the plugin stops, or `dispose`).
|
|
5045
5045
|
*/
|
|
5046
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;
|
|
5047
5111
|
}
|
|
5048
5112
|
export interface MapViewHandle extends Disposable {
|
|
5049
5113
|
/**
|
|
@@ -5061,6 +5125,14 @@ export interface MapViewHandle extends Disposable {
|
|
|
5061
5125
|
* `show` was called, or another map came to the front.
|
|
5062
5126
|
*/
|
|
5063
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;
|
|
5064
5136
|
}
|
|
5065
5137
|
export interface PanelHandle {
|
|
5066
5138
|
close(): void;
|