JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q57583F
  • License ISC

Package Exports

  • @rbxts/fabric

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts/fabric) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@rbxts/fabric

roblox-ts typings for evaera's Fabric.

npm i @rbxts/fabric @rbxts/t

NPM

Modifications

Modifications I have made to the original package

Usage

ExampleUnit.ts

import { Fabric, UnitDefinition, ThisFabricUnit } from "@rbxts/fabric";

const fabric = new Fabric("game");

declare global {
    interface FabricUnits {
        ExampleUnit: ExampleUnitDefinition;
    }
}

//NOTE: you should never define the `name` field here. `name` should always be the same as the key in `FabricUnits`, which is done automatically for you.
interface ExampleUnitDefinition extends UnitDefinition<"ExampleUnit"> {
    //these three fields are for typing only, and they have to be optional so that the below implementation does not have to define them
    data?: { bar: boolean };
    _addLayerData?: { bar: true }; //if `_addLayerData` is not specified, `data` will be used.
    ref?: Player;

    foo(this: ThisFabricUnit<"ExampleUnit">): void;
}

const exampleUnitDefinition: ExampleUnitDefinition = {
    name: "ExampleUnit",

    foo() {
        this.addLayer("exampleScope", { bar: true }); //here, `bar` must equal `true`.

        //hypothetically, if `_addLayerData` was not specified, then `bar` would be able to be `true` OR `false`, since those are of type `boolean`.
    },
};

fabric.registerUnit(exampleUnitDefinition);

const unit = fabric.getOrCreateUnitByRef("ExampleUnit", game); //attach an ExampleUnit to `game`
unit.foo();
print(unit.data!.bar); // > true

Changelog

1.0.0

- Initial release