rednode API - v0.80.1
    Preparing search index...

    Variable inkConst

    ink: {
        at(
            x: number,
            y: number,
        ): Promise<{ hits: InkHit[]; looked: number; ms: number }>;
        bar(props?: InkBarProps): InkNode<InkBarProps>;
        boxes(): Promise<
            { looked: number; ms: number; widgets: Omit<InkHit, "path">[] },
        >;
        canvas(...args: (Child | InkContainerProps)[]): InkNode<InkContainerProps>;
        check(
            source: string,
            handlers?: Record<string, unknown> | string[],
            file?: string,
        ): InkMarkupError | null;
        circle(props?: InkProps): InkNode<InkProps>;
        column(...args: (Child | InkContainerProps)[]): InkNode<InkContainerProps>;
        image(props?: InkImageProps): InkNode<InkImageProps>;
        inspect(id: string): Promise<InkWidgetInfo>;
        layers(): Promise<{ layers: InkLayerInfo[] }>;
        list<T>(
            props: InkListProps<T>,
            render: (item: T, index: number) => InkNode,
            key?: (item: T, index: number) => string | number,
        ): InkNode<InkListProps<T>>;
        load(
            file: string,
            handlers?: Record<string, unknown>,
            data?: Record<string, unknown>,
        ): Promise<InkView>;
        markupTags(): Record<string, string[]>;
        mount(
            layer: "hud",
            options: InkMountOptions,
            ...children: Child[],
        ): InkMount;
        parse(
            source: string,
            handlers?: Record<string, unknown>,
            data?: Record<string, unknown>,
        ): InkView;
        read(
            from: { id: string } | { layer: string } | { ref: { $ref: number } },
            options?: {
                boxes?: boolean;
                depth?: number;
                max?: number;
                props?: boolean;
            },
        ): Promise<InkReadResult>;
        rect(props?: InkProps): InkNode<InkProps>;
        reset(
            id?: string,
            prop?: InkTryProp,
        ): Promise<{ errors: string[]; gone: number; reset: number }>;
        row(...args: (Child | InkContainerProps)[]): InkNode<InkContainerProps>;
        text(
            text: string | LocalText,
            props?: Omit<InkTextProps, "text">,
        ): InkNode<InkTextProps>;
        tried(): Promise<{ id: string; prop: InkTryProp; was: unknown }[]>;
        try<P extends InkTryProp>(
            id: string,
            prop: P,
            value: InkTryValue<P>,
        ): Promise<
            { id: string; now: InkTryValue<P>; prop: P; was: InkTryValue<P> },
        >;
        widget(
            className: string,
            props?: InkProps & Record<string, unknown>,
            ...children: Child[],
        ): InkNode;
    } = ...

    The game's own UI, drawn by the game. Needs Codeware.

    Type Declaration

    • at: function
      • The game's drawn widgets under a point on screen, on every active layer, the smallest box first (the most particular widget; then the deepest), leaving out what is not drawn (its or its parents' opacity is 0): what an inspector's Pick finds. x and y are in the game's ink pixels (the layers' size). Reads only.

        Parameters

        • x: number
        • y: number

        Returns Promise<{ hits: InkHit[]; looked: number; ms: number }>

        const { hits } = await ink.at(200, 900);
        console.log(hits[0]?.path);
    • bar: function
    • boxes: function
      • Every drawn widget of the game with a box on screen, on every active layer, the smallest first, in one call (about 7 ms for 1,600 widgets in game 2.5). A page that highlights what is under the cursor reads these once and tests each mouse move itself, instead of asking the game on every move. Boxes are in ink pixels, as ink.at's. Reads only.

        Returns Promise<{ looked: number; ms: number; widgets: Omit<InkHit, "path">[] }>

        const { widgets } = await ink.boxes();
        const under = (x: number, y: number) =>
        widgets.find((w) => w.box && x >= w.box[0] && y >= w.box[1] && x < w.box[0] + w.box[2] && y < w.box[1] + w.box[3]);
    • canvas: function
    • check: function
      • Checks ink markup without putting anything on the game's UI, as ink.parse would read it: answers null when it reads, or the first InkMarkupError, with its line and column. Give handlers (the names its on... attributes may use) to check those too. An editor checks as the modder types with it.

        Parameters

        • source: string
        • Optionalhandlers: Record<string, unknown> | string[]
        • Optionalfile: string

        Returns InkMarkupError | null

        const error = ink.check(source, ["track"]);
        if (error) console.log(`line ${error.line}, column ${error.column}: ${error.reason}`);
    • circle: function
    • column: function
    • image: function
    • inspect: function
      • One of the game's widgets in full: its class and parents' classes, path, box, controllers, where it came from (layer, HUD entry, library file hash) and every property. ref is an api reference to it, for calling its methods. Reads only.

        Parameters

        • id: string

        Returns Promise<InkWidgetInfo>

        const w = await ink.inspect("w42");
        console.log(w.path, w.controllers, w.properties.opacity);
    • layers: function
      • The game's own ink layers (needs Codeware), in their order, each with its window. The HUD layer also lists its entries: each HUD piece the game spawned, with its root widget, its game controller and the .inkwidget file it came from (a path hash). Reads only.

        Returns Promise<{ layers: InkLayerInfo[] }>

        const { layers } = await ink.layers();
        const hud = layers.find((l) => l.name === "inkHUDLayer");
        console.log(hud?.entries?.map((e) => e.name));
    • list: function
      • A column (or direction: "row") of one node per item. Give it new items with set: new keys are added at their place, gone ones removed, moved ones moved, and the others patched, so only what changed goes to the game.

        Type Parameters

        • T

        Parameters

        • props: InkListProps<T>
        • render: (item: T, index: number) => InkNode
        • key: (item: T, index: number) => string | number = ...

        Returns InkNode<InkListProps<T>>

        const board = ink.list({ gap: 6, items: contracts },
        (c) => ink.row({ gap: 12 }, ink.text(c.name, { style: "body" }), ink.text(`${c.reward} €$`, { style: "value" })),
        (c) => c.id);
        board.set({ items: next });
    • load: function
      • Reads an ink markup file (.ink.html) and puts it on the game's UI, as ink.parse does. A relative path starts at the package's folder. Mistakes name the file, line and column.

        Parameters

        • file: string
        • Optionalhandlers: Record<string, unknown>
        • Optionaldata: Record<string, unknown>

        Returns Promise<InkView>

        import { ink } from "rednode";
        import * as handlers from "./bounty.mjs";

        const board = await ink.load("bounty.ink.html", handlers, { contracts: [] });
        board.set({ contracts: await fetchContracts() });
    • markupTags: function
      • The tags ink markup knows, with the attributes each takes: for an editor's completion.

        Returns Record<string, string[]>

    • mount: function
    • parse: function
      • Puts ink markup on the game's UI: the tags of this module written as HTML, their props as attributes. The top of the markup holds <mount> tags (layer, anchor, x, y).

        • Tags: canvas, column, row (also vbox, hbox), text, rect, circle, image, bar, list, and widget class="inkBorder" for any ink class, whose capitalized attributes are its methods. Attributes are the props by name; text-align is textAlign. margin and pad take one number or four.
        • Text: inside <text>...</text>, or text="...". LocKey#... and key show the game's own text.
        • Data: {name} in text or an attribute reads the named data, {name.field} a field of it. An attribute that is one {name} alone takes the value as it is (a number, true). {{ and }} are the characters. No expressions.
        • Lists: <list items="contracts" key="id"> holds the one tag each item gets; inside it {name} reads the item's field first, {.} is the item itself and {$index} its place.
        • Events: onclick="track" names a function of handlers, checked now. Input on ink comes with phase I3: until then no event fires.

        A mistake throws an InkMarkupError with its line and column.

        Parameters

        • source: string

          The markup.

        • Optionalhandlers: Record<string, unknown>

          The functions its on... attributes name: a module (import * as handlers from "./bounty.mjs") or an object.

        • Optionaldata: Record<string, unknown>

          The named data it reads, changed later with InkView.set.

        Returns InkView

        const board = ink.parse(`
        <mount layer="hud" anchor="top-right" x="-40" y="120">
        <column gap="6">
        <text style="title">Bounty board</text>
        <list items="contracts" key="id" gap="4">
        <row gap="12">
        <text style="body">{name}</text>
        <text style="value">{reward} €$</text>
        </row>
        </list>
        </column>
        </mount>`, {}, { contracts: [] });

        board.set({ contracts: [{ id: 1, name: "Watson", reward: 1500 }] });
    • read: function
      • Reads a tree of the game's own widgets in one call: a layer's window, a widget by its id from an earlier read, or an api reference. Each node has its class, name, visibility, box on screen, controller and text; children stops at depth or max nodes (count says how many it has). Reads only.

        Parameters

        • from: { id: string } | { layer: string } | { ref: { $ref: number } }
        • options: { boxes?: boolean; depth?: number; max?: number; props?: boolean } = {}
          • Optionalboxes?: boolean
          • Optionaldepth?: number
          • Optionalmax?: number
          • Optionalprops?: boolean

            Each node's layout and look as well (props and drawn), with texts whole: what ink markup needs to copy it. Needs REDnode 0.56.0.

        Returns Promise<InkReadResult>

        const { root, nodes, ms } = await ink.read({ layer: "inkMenuLayer" }, { depth: 3 });
        console.log(`${nodes} widgets in ${ms} ms`, root.children?.map((c) => c.name));
    • rect: function
    • reset: function
      • Puts back what ink.try changed: every widget the package tried, one widget, or one of its properties. Answers how many were put back, and how many the game had removed meanwhile (a save load rebuilds the HUD). Needs REDnode 0.56.0.

        Parameters

        Returns Promise<{ errors: string[]; gone: number; reset: number }>

    • row: function
    • text: function
    • tried: function
      • What the package has tried and not put back yet, with each value before the first try. Needs REDnode 0.56.0.

        Returns Promise<{ id: string; prop: InkTryProp; was: unknown }[]>

    • try: function
      • Tries a change on one of the game's own widgets, live, to find what controls a look: its visible, opacity, tint, size, margin, padding, translation (x and y), or a text's text and fontSize. The first try of a property keeps the value it had, and ink.reset puts it back; REDnode puts everything back when the package stops, so a try is never kept. Answers the value before the first try and the value now. Only for a package the player allowed admin (the UI Workbench's Try). Needs REDnode 0.56.0.

        Type Parameters

        Parameters

        Returns Promise<{ id: string; now: InkTryValue<P>; prop: P; was: InkTryValue<P> }>

        const { hits } = await ink.at(200, 900);
        await ink.try(hits[0].id, "opacity", 0.3);
        await ink.try(hits[0].id, "tint", "#ff3040");
        await ink.reset(hits[0].id);
    • widget: function
      • Any ink class by name, for what the tags do not cover. Capitalized props are the widget's own methods, called with the value as their arguments.

        Parameters

        • className: string
        • props: InkProps & Record<string, unknown> = {}
        • ...children: Child[]

        Returns InkNode

        ink.widget("inkBorder", { width: 200, height: 40, color: "red", SetThickness: 2 });
        
    import { game, ink } from "rednode";

    const where = ink.text("", { size: 28, color: "cyan" });
    ink.mount("hud", { anchor: "top-right", x: -40, y: 120 },
    ink.column({ gap: 4 }, ink.text("REDnode", { size: 20 }), where));

    setInterval(async () => {
    const p = await game.player.position();
    where.set({ text: `${p.x.toFixed(1)} ${p.y.toFixed(1)} ${p.z.toFixed(1)}` });
    }, 250);