Created
February 12, 2020 08:40
-
-
Save happylinks/261b2ab147e4c866195d5898718bc13f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Global settings */ | |
| [@bs.deriving abstract] | |
| type pixiSettings = { | |
| [@bs.as "ROUND_PIXELS"] | |
| mutable roundPixels: bool, | |
| [@bs.as "MIPMAP_TEXTURES"] | |
| mutable mipMapTextures: int, | |
| [@bs.as "PRECISION_FRAGMENT"] | |
| mutable precisionFragment: string, | |
| }; | |
| [@bs.val] [@bs.module "pixi.js"] external settings: pixiSettings = "settings"; | |
| /* type error; | |
| type onError; | |
| type onLoad; | |
| [@bs.send] external addOnError: (onError, error => unit) => unit = "add"; | |
| [@bs.send] external addOnLoad: (onLoad, unit => unit) => unit = "add"; | |
| type sharedLoader = { | |
| onError, | |
| onLoad, | |
| }; | |
| [@bs.val] [@bs.module "pixi.js"] [@bs.scope "Loader"] | |
| external loader: sharedLoader = "shared"; | |
| addOnError(loader.onError, err => Js.log("Had error")); | |
| addOnLoad(loader.onLoad, err => Js.log("loaded"));*/ | |
| /* settings->roundPixelsSet(true);*/ | |
| /* settings->precisionFragmentSet("highp");*/ | |
| /* Global settings */ | |
| type position = (int, int); | |
| type dimensions = (int, int); | |
| type interactionData; | |
| type interactionEvent = {. "data": interactionData}; | |
| type event = interactionEvent; | |
| module Texture = { | |
| type t; | |
| [@bs.module "pixi.js"] [@bs.scope "Texture"] [@bs.val] | |
| external white: t = "WHITE"; | |
| }; | |
| module DisplayObject = { | |
| type t; | |
| type position = { | |
| . | |
| "x": float, | |
| "y": float, | |
| }; | |
| type bounds = { | |
| . | |
| "x": float, | |
| "y": float, | |
| "width": float, | |
| "height": float, | |
| }; | |
| [@bs.set] external setCursor: (t, string) => unit = "cursor"; | |
| [@bs.get] external getCursor: t => string = "cursor"; | |
| [@bs.send] [@bs.scope "position"] | |
| external setPosition: (t, float, float) => unit = "set"; | |
| [@bs.get] external getPosition: t => position = "position"; | |
| [@bs.send] external getBounds: t => bounds = "getBounds"; | |
| [@bs.send] external getGlobalPosition: t => position = "getGlobalPosition"; | |
| [@bs.set] external setWidth: (t, int) => unit = "width"; | |
| [@bs.get] external getWidth: t => int = "width"; | |
| [@bs.set] external setHeight: (t, int) => unit = "height"; | |
| [@bs.get] external getHeight: t => int = "height"; | |
| [@bs.send] [@bs.scope "anchor"] | |
| external setAnchor: (t, float, float) => unit = "set"; | |
| [@bs.send] [@bs.scope "scale"] external setScale: (t, float) => unit = "set"; | |
| [@bs.set] external setInteractive: (t, bool) => unit = "interactive"; | |
| [@bs.set] external setAlpha: (t, float) => unit = "alpha"; | |
| [@bs.set] external setVisibility: (t, bool) => unit = "visible"; | |
| [@bs.set] external setTexture: (t, Texture.t) => unit = "texture"; | |
| [@bs.set] external setZIndex: (t, int) => unit = "zIndex"; | |
| [@bs.get] external getZIndex: t => int = "zIndex"; | |
| [@bs.set] external setResolution: (t, float) => unit = "resolution"; | |
| [@bs.set] external setTint: (t, int) => unit = "tint"; | |
| [@bs.send] external destroy: (t, unit) => unit = "destroy"; | |
| type parent; | |
| [@bs.get] external getParent: t => parent = "parent"; | |
| [@bs.send] | |
| external getLocalPositionParent: (interactionData, parent) => position = | |
| "getLocalPosition"; | |
| [@bs.send] | |
| external getLocalPosition: (interactionData, t) => position = | |
| "getLocalPosition"; | |
| let updatePosition: (t, Point.t) => t = | |
| (t, point) => { | |
| switch (point |> Point.view) { | |
| | {x, y} => setPosition(t, x, y) | |
| }; | |
| t; | |
| }; | |
| let updateDimensions: (t, Dimensions.t) => t = | |
| (t, dimensions) => { | |
| switch (dimensions |> Dimensions.view) { | |
| | {width, height} => | |
| setWidth(t, width); | |
| setHeight(t, height); | |
| }; | |
| t; | |
| }; | |
| let updateAnchor = (t, x, y) => { | |
| setAnchor(t, x, y); | |
| t; | |
| }; | |
| let updateScale = (t, scale) => { | |
| setScale(t, scale); | |
| t; | |
| }; | |
| let updateInteractive = (t, interactive) => { | |
| setInteractive(t, interactive); | |
| t; | |
| }; | |
| let updateAlpha = (t, alpha) => { | |
| setAlpha(t, alpha); | |
| t; | |
| }; | |
| let updateVisibility = (t, isVisible) => { | |
| setVisibility(t, isVisible); | |
| t; | |
| }; | |
| let updateTexture = (t, texture) => { | |
| setTexture(t, texture); | |
| t; | |
| }; | |
| let updateZIndex = (t, zIndex) => { | |
| setZIndex(t, zIndex); | |
| t; | |
| }; | |
| let updateCursor = (t, cursor) => { | |
| setCursor(t, cursor); | |
| t; | |
| }; | |
| let updateResolution = (t, resolution) => { | |
| setResolution(t, resolution); | |
| t; | |
| }; | |
| let updateTint = (t, tint) => { | |
| setTint(t, tint); | |
| t; | |
| }; | |
| /* EventEmitter */ | |
| [@bs.send] external on: (t, string, interactionEvent => unit) => unit = "on"; | |
| [@bs.send] | |
| external off: (t, string, interactionEvent => unit) => unit = "off"; | |
| [@bs.send] external emit: (t, string) => unit = "emit"; | |
| [@bs.send] | |
| external stopPropagation: (interactionEvent, unit) => unit = | |
| "stopPropagation"; | |
| }; | |
| module Sprite = { | |
| class type _t = | |
| [@bs] | |
| {}; | |
| type t = Js.t(_t); | |
| [@bs.new] [@bs.module "pixi.js"] external create: Texture.t => t = "Sprite"; | |
| external displayObject: t => DisplayObject.t = "%identity"; | |
| }; | |
| module Source = { | |
| type t; | |
| [@bs.send] external play: (t, unit) => unit = "play"; | |
| [@bs.send] external pause: (t, unit) => unit = "pause"; | |
| [@bs.set] external setCurrentTime: (t, float) => unit = "currentTime"; | |
| [@bs.set] external setVolume: (t, float) => unit = "volume"; | |
| [@bs.get] external currentTime: t => float = "currentTime"; | |
| [@bs.get] external paused: t => bool = "paused"; | |
| external asElement: t => Dom.element = "%identity"; | |
| type event; | |
| [@bs.send] | |
| external addEventListener: (t, string, event => unit) => unit = | |
| "addEventListener"; | |
| [@bs.send] | |
| external removeEventListener: (t, string, event => unit) => unit = | |
| "addEventListener"; | |
| }; | |
| module VideoResource = { | |
| type t; | |
| type source = { | |
| src: string, | |
| mime: string, | |
| }; | |
| type createOptions = { | |
| autoPlay: bool, | |
| autoLoad: bool, | |
| updateFPS: int, | |
| }; | |
| [@bs.new] [@bs.module "pixi.js"] [@bs.scope "resources"] | |
| external create: (array(source), createOptions) => t = "VideoResource"; | |
| [@bs.get] external source: t => Source.t = "source"; | |
| [@bs.send] external load: t => unit = "load"; | |
| }; | |
| module Sound = { | |
| type t; | |
| [@bs.send] external play: (t, unit) => unit = "play"; | |
| [@bs.send] external resume: (t, unit) => unit = "resume"; | |
| [@bs.send] external pause: (t, unit) => unit = "pause"; | |
| [@bs.send] external stop: (t, unit) => unit = "stop"; | |
| [@bs.send] external destroy: (t, unit) => unit = "destroy"; | |
| [@bs.get] external isPlaying: t => bool = "isPlaying"; | |
| [@bs.get] external isLoaded: t => bool = "isLoaded"; | |
| [@bs.get] external isPaused: t => bool = "paused"; | |
| type fromOptions = { | |
| url: string, | |
| preload: bool, | |
| }; | |
| [@bs.val] | |
| [@bs.module "pixi-sound"] | |
| [@bs.scope ("default", "sound", "Sound")] | |
| external make: fromOptions => t = "from"; | |
| }; | |
| module GifSprite = { | |
| type t = {sprite: Sprite.t}; | |
| [@bs.send] external play: (t, unit) => unit = "play"; | |
| [@bs.send] external pause: (t, unit) => unit = "pause"; | |
| [@bs.send] external stop: (t, unit) => unit = "stop"; | |
| [@bs.new] [@bs.module "@happylinks/pixi-apngandgif"] | |
| external make: string => t = "default"; | |
| }; | |
| module TextStyle = { | |
| class type _t = | |
| [@bs] | |
| {}; | |
| type t = Js.t(_t); | |
| [@bs.deriving abstract] | |
| type textStyleOptions = { | |
| [@bs.optional] | |
| align: string, | |
| [@bs.optional] | |
| breakWords: bool, | |
| [@bs.optional] | |
| dropShadow: bool, | |
| [@bs.optional] | |
| dropShadowAlpha: string, | |
| [@bs.optional] | |
| dropShadowAngle: float, | |
| [@bs.optional] | |
| dropShadowBlur: int, | |
| [@bs.optional] | |
| dropShadowColor: string, | |
| [@bs.optional] | |
| dropShadowDistance: int, | |
| [@bs.optional] | |
| fill: string, | |
| [@bs.optional] | |
| fillGradientType: int, | |
| [@bs.optional] | |
| fillGradientStops: array(int), | |
| [@bs.optional] | |
| fontFamily: string, | |
| [@bs.optional] | |
| fontSize: int, | |
| [@bs.optional] | |
| fontStyle: string, | |
| [@bs.optional] | |
| fontVariant: string, | |
| [@bs.optional] | |
| fontWeight: int, | |
| [@bs.optional] | |
| leading: int, | |
| [@bs.optional] | |
| letterSpacing: int, | |
| [@bs.optional] | |
| lineJoin: string, | |
| [@bs.optional] | |
| miterLimit: int, | |
| [@bs.optional] | |
| padding: int, | |
| [@bs.optional] | |
| stroke: string, | |
| [@bs.optional] | |
| strokeThickness: int, | |
| [@bs.optional] | |
| trim: bool, | |
| [@bs.optional] | |
| textBaseline: string, | |
| [@bs.optional] | |
| whiteSpace: string, | |
| [@bs.optional] | |
| wordWrap: bool, | |
| [@bs.optional] | |
| wordWrapWidth: int, | |
| }; | |
| [@bs.new] [@bs.module "pixi.js"] | |
| external create: textStyleOptions => t = "TextStyle"; | |
| }; | |
| module TextSprite = { | |
| type t; | |
| [@bs.new] [@bs.module "pixi.js"] | |
| external create: (string, TextStyle.t) => t = "Text"; | |
| external displayObject: t => DisplayObject.t = "%identity"; | |
| [@bs.set] external setStyle: (t, TextStyle.t) => unit = "style"; | |
| [@bs.get] external getStyle: t => string = "style"; | |
| let updateStyle = (t, style) => { | |
| setStyle(t, style); | |
| t; | |
| }; | |
| }; | |
| module TextInput = { | |
| type t; | |
| type position = { | |
| . | |
| "x": float, | |
| "y": float, | |
| }; | |
| [@bs.deriving abstract] | |
| type styleOptions = { | |
| [@bs.optional] | |
| fontFamily: string, | |
| [@bs.optional] | |
| fontSize: string, | |
| [@bs.optional] | |
| fontWeight: string, | |
| [@bs.optional] | |
| lineHeight: string, | |
| [@bs.optional] | |
| padding: string, | |
| [@bs.optional] | |
| width: string, | |
| [@bs.optional] | |
| color: string, | |
| }; | |
| [@bs.deriving abstract] | |
| type createInput = { | |
| [@bs.optional] | |
| input: styleOptions, | |
| [@bs.optional] | |
| box: styleOptions, | |
| }; | |
| [@bs.set] external setText: (t, string) => unit = "text"; | |
| [@bs.get] external getText: t => string = "text"; | |
| let updateText = (t, text) => { | |
| setText(t, text); | |
| t; | |
| }; | |
| [@bs.new] [@bs.module "pixi-textinput-v5"] | |
| external create: createInput => t = "TextInput"; | |
| external displayObject: t => DisplayObject.t = "%identity"; | |
| external sprite: t => Sprite.t = "%identity"; | |
| /* EventEmitter */ | |
| [@bs.send] external on: (t, string, interactionEvent => unit) => unit = "on"; | |
| [@bs.send] | |
| external off: (t, string, interactionEvent => unit) => unit = "off"; | |
| [@bs.send] external emit: (t, string) => unit = "emit"; | |
| let onBlur = t => t->on("blur"); | |
| let offBlur = t => t->off("blur"); | |
| }; | |
| module Graphics = { | |
| class type _t = | |
| [@bs] | |
| { | |
| pub lineStyle: int => unit; | |
| pub beginFill: (int, float) => unit; | |
| pub drawCircle: (int, int, int) => unit; | |
| pub drawRect: (int, int, int, int) => unit; | |
| pub endFill: unit => unit; | |
| pub clear: unit => unit; | |
| }; | |
| type t = Js.t(_t); | |
| [@bs.new] [@bs.module "pixi.js"] external create: unit => t = "Graphics"; | |
| }; | |
| module Container = { | |
| type t; | |
| type child = | |
| | Graphics(Graphics.t) | |
| | Sprite(Sprite.t) | |
| | TextSprite(TextSprite.t) | |
| | Container(t); | |
| [@bs.send] external addChild': (t, 'a) => unit = "addChild"; | |
| let addChild = (container, child) => | |
| switch (child) { | |
| | Graphics(g) => addChild'(container, g) | |
| | Sprite(s) => addChild'(container, s) | |
| | TextSprite(t) => addChild'(container, t) | |
| | Container(t) => addChild'(container, t) | |
| }; | |
| [@bs.set] | |
| external setSortableChildren: (t, bool) => unit = "sortableChildren"; | |
| let updateSortableChildren = (sprite, value) => { | |
| setSortableChildren(sprite, value); | |
| sprite; | |
| }; | |
| [@bs.new] [@bs.module "pixi.js"] external create: unit => t = "Container"; | |
| [@bs.send] external removeChildren: t => unit = "removeChildren"; | |
| let clear = container => { | |
| removeChildren(container); | |
| container; | |
| }; | |
| /* EventEmitter */ | |
| [@bs.send] external on: (t, string, interactionEvent => unit) => unit = "on"; | |
| [@bs.send] | |
| external off: (t, string, interactionEvent => unit) => unit = "off"; | |
| [@bs.send] external emit: (t, string) => unit = "emit"; | |
| external displayObject: t => DisplayObject.t = "%identity"; | |
| }; | |
| module Plugins = { | |
| type plugin; | |
| type t = {. "interaction": plugin}; | |
| }; | |
| module ViewportPlugins = { | |
| type t; | |
| type plugin; | |
| [@bs.send] external pause: (t, string) => unit = "pause"; | |
| [@bs.send] external resume: (t, string) => unit = "resume"; | |
| [@bs.send] external add: (t, string, plugin) => unit = "add"; | |
| [@bs.send] external remove: (t, string) => unit = "remove"; | |
| }; | |
| module Viewport = { | |
| type t = {. "plugins": ViewportPlugins.t}; | |
| type child = | |
| | Graphics(Graphics.t) | |
| | Sprite(Sprite.t) | |
| | TextSprite(TextSprite.t) | |
| | Container(t); | |
| [@bs.deriving abstract] | |
| type makeOptions = { | |
| [@bs.optional] | |
| screenWidth: int, | |
| [@bs.optional] | |
| screenHeight: int, | |
| [@bs.optional] | |
| worldWidth: int, | |
| [@bs.optional] | |
| worldHeight: int, | |
| [@bs.optional] | |
| interaction: Plugins.plugin, | |
| [@bs.optional] | |
| passiveWheel: bool, | |
| [@bs.optional] | |
| divWheel: Webapi.Dom.Element.t, | |
| }; | |
| [@bs.new] [@bs.module "pixi-viewport"] | |
| external make: makeOptions => t = "Viewport"; | |
| [@bs.send] external addChild: (t, Container.t) => unit = "addChild"; | |
| [@bs.deriving abstract] | |
| type dragOptions = { | |
| [@bs.optional] | |
| mouseButtons: string, | |
| }; | |
| [@bs.send] external drag: (t, dragOptions) => t = "drag"; | |
| [@bs.deriving abstract] | |
| type pinchOptions = { | |
| [@bs.optional] | |
| percent: float, | |
| }; | |
| [@bs.send] external pinch: (t, pinchOptions) => t = "pinch"; | |
| [@bs.deriving abstract] | |
| type clampOptions = { | |
| [@bs.optional] | |
| direction: string, | |
| }; | |
| [@bs.send] external clamp: (t, clampOptions) => t = "clamp"; | |
| [@bs.deriving abstract] | |
| type wheelOptions = { | |
| [@bs.optional] | |
| percent: float, | |
| [@bs.optional] | |
| smooth: bool, | |
| [@bs.optional] | |
| interrupt: bool, | |
| [@bs.optional] | |
| reverse: bool, | |
| [@bs.optional] | |
| center: Point.t, | |
| }; | |
| [@bs.send] external wheel: (t, wheelOptions) => t = "wheel"; | |
| [@bs.send] external decelerate: t => t = "decelerate"; | |
| [@bs.send] external resize: (t, int, int) => unit = "resize"; | |
| [@bs.send] external moveCenter: (t, float, float) => unit = "moveCenter"; | |
| [@bs.send] external zoomPercent: (t, float, bool) => unit = "zoomPercent"; | |
| type scale = { | |
| x: float, | |
| y: float, | |
| }; | |
| type viewport = {scale}; | |
| type event = {viewport}; | |
| [@bs.send] external on: (t, string, event => unit) => unit = "on"; | |
| [@bs.send] external off: (t, string, event => unit) => unit = "off"; | |
| let addWheelEventListener = t => on(t, "wheel"); | |
| let removeWheelEventListener = t => off(t, "wheel"); | |
| let addZoomedEventListener = t => on(t, "zoomed"); | |
| let removeZoomedEventListener = t => off(t, "zoomed"); | |
| let addClickedEventListener = t => on(t, "clicked"); | |
| let removeClickedEventListener = t => off(t, "clicked"); | |
| external toContainer: t => Container.t = "%identity"; | |
| }; | |
| module Stage = { | |
| type t; | |
| [@bs.send] external addChild: (t, Container.t) => unit = "addChild"; | |
| external displayObject: t => DisplayObject.t = "%identity"; | |
| }; | |
| module Ticker = { | |
| type t; | |
| [@bs.send] external add: (t, int => unit) => unit = "add"; | |
| [@bs.send] external remove: (t, int => unit) => unit = "remove"; | |
| }; | |
| module Renderer = { | |
| type t = {. "plugins": Plugins.t}; | |
| [@bs.send] external resize: (t, int, int) => unit = "resize"; | |
| }; | |
| module Application = { | |
| type t = { | |
| . | |
| "view": Webapi.Dom.Element.t, | |
| "stage": Stage.t, | |
| "ticker": Ticker.t, | |
| "renderer": Renderer.t, | |
| }; | |
| [@bs.send] external render: (t, Container.t) => unit = "render"; | |
| [@bs.send] external stop: (t, unit) => unit = "stop"; | |
| [@bs.send] external start: (t, unit) => unit = "start"; | |
| }; | |
| [@bs.deriving abstract] | |
| type applicationOptions = { | |
| [@bs.optional] | |
| backgroundColor: int, | |
| [@bs.optional] | |
| width: int, | |
| [@bs.optional] | |
| height: int, | |
| [@bs.optional] | |
| autoResize: bool, | |
| [@bs.optional] | |
| resolution: float, | |
| [@bs.optional] | |
| resizeTo: Webapi.Dom.Window.t, | |
| [@bs.optional] | |
| antialias: bool, | |
| [@bs.optional] | |
| screenWidth: float, | |
| [@bs.optional] | |
| screenHeight: float, | |
| [@bs.optional] | |
| worldWidth: int, | |
| [@bs.optional] | |
| worldHeight: int, | |
| }; | |
| [@bs.module "pixi.js"] [@bs.new] | |
| external createApplication: applicationOptions => Application.t = | |
| "Application"; | |
| type textureSource = | |
| | VideoResource(VideoResource.t) | |
| | PathResource(string); | |
| [@bs.new] [@bs.scope "Texture"] [@bs.module "pixi.js"] | |
| external from: 'a => Texture.t = "from"; | |
| let createTexture = texture => | |
| switch (texture) { | |
| | VideoResource(v) => from(v) | |
| | PathResource(p) => from(p) | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment