wavefunctioncollapse
wavefunctioncollapse copied to clipboard
Missing typescript types
Hey, I noticed this module doesn't seem to have any type definitions so I wrote my own based on the documentation. I don't know what the usual process is for these things, but here is the .d.ts file from my project:
declare module 'wavefunctioncollapse'
{
type RGBA = Uint8Array | Uint8ClampedArray;
abstract class Model
{
/**
* Execute a complete new generation. Returns whether the generation was successful.
* @param rng A function to use as random number generator, defaults to Math.random.
*/
public generate(rng?: () => number): boolean
/**
* Execute a fixed number of iterations. Stop when the generation is successful or reaches a contradiction. Returns whether the iterations ran without reaching a contradiction.
* @param iterations Maximum number of iterations to execute (0 = infinite).
* @param rng A function to use as random number generator, defaults to Math.random.
*/
public iterate(iterations: number, rng?: () => number): boolean
/**
* Returns whether the previous generation completed successfully.
*/
public isGenerationComplete(): boolean
/**
* Clear the internal state to start a new generation.
*/
public clear(): void
}
class OverlappingModel extends Model
{
/**
* new OverlappingModel(data, dataWidth, dataHeight, N, width, height, periodicInput, periodicOutput, symmetry[, ground])
* @param data The RGBA data of the source image.
* @param datawidth The width of the source image.
* @param dataHeight The height of the source image.
* @param N Size of the patterns.
* @param width The width of the generation (in pixels).
* @param height The height of the generation (in pixels).
* @param periodicInput Whether the source image is to be considered as periodic / as a repeatable texture.
* @param periodicOutput Whether the generation should be periodic / a repeatable texture.
* @param symmetry Allowed symmetries from 1 (no symmetry) to 8 (all mirrored / rotated variations)
* @param ground Id of the specific pattern to use as the bottom of the generation (learn more: https://github.com/mxgmn/WaveFunctionCollapse/issues/3#issuecomment-250995366)
*/
public constructor(data: RGBA, datawidth: number, dataHeight: number, N: number, width: number, height: number, periodicInput: boolean, periodicOutput: boolean, symmetry: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8, ground?: number)
/**
* Retrieve the RGBA data of the generation.
* @param array Array to write the RGBA data into (must already be set to the correct size), if not set a new Uint8Array will be created and returned. It is recommended to use Uint8Array or Uint8ClampedArray.
*/
public graphics(array?: RGBA): RGBA
}
class SimpleTiledModel extends Model
{
/**
* new SimpleTiledModel(data, subsetName, width, height, periodicOutput)
* @param data Tiles, subset and constraints definitions. The proper doc on this matter is yet to be written, check the example in the meantime.
* @param subsbetName Name of the subset to use from the data. If falsy, use all tiles.
* @param width The width of the generation (in tiles).
* @param height The height of the generation (in tiles).
* @param periodicOutput Whether the generation should be periodic / a repeatable texture.
*/
public constructor(data: any, subsbetName: string, width: number, height: number, periodicOutput: boolean)
/**
* Retrieve the RGBA data of the generation.
* @param array Array to write the RGBA data into (must already be set to the correct size), if not set a new Uint8Array will be created and returned. It is recommended to use Uint8Array or Uint8ClampedArray.
* @param defaultColor RGBA data of the default color to use on untouched tiles.
*/
public graphics(array?: RGBA, defaultColor?: number): RGBA
}
}
Hello, the Typescript-recommended way to add definitions to non-typescript libraries is to publish them on @types. They have extensive documentation on how to do it. For example, this is how it was handled for https://github.com/kchapelier/poisson-disk-sampling/pull/10.
Feel free to publish them there and I'll add a mention to them in the readme of this repo and attribute you.