Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing typescript types #5

Open
wendigo120 opened this issue Apr 25, 2022 · 1 comment
Open

Missing typescript types #5

wendigo120 opened this issue Apr 25, 2022 · 1 comment

Comments

@wendigo120
Copy link

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
    }
}

@kchapelier
Copy link
Owner

kchapelier commented Aug 8, 2022

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 kchapelier/poisson-disk-sampling#10.

Feel free to publish them there and I'll add a mention to them in the readme of this repo and attribute you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants