From 7d3b1cf3da3aa53a73b0f83ce0a9fb5f33bcdfb3 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Tue, 25 Aug 2020 11:40:12 +0200 Subject: [PATCH] Add .coffee.md to Literate Coffeescript --- lib/linguist/languages.yml | 1 + samples/Literate CoffeeScript/pixi.coffee.md | 113 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 samples/Literate CoffeeScript/pixi.coffee.md diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 8e403c3832..0406c4a1fd 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2894,6 +2894,7 @@ Literate CoffeeScript: - litcoffee extensions: - ".litcoffee" + - ".coffee.md" language_id: 206 Literate Haskell: type: programming diff --git a/samples/Literate CoffeeScript/pixi.coffee.md b/samples/Literate CoffeeScript/pixi.coffee.md new file mode 100644 index 0000000000..2ac1b1e511 --- /dev/null +++ b/samples/Literate CoffeeScript/pixi.coffee.md @@ -0,0 +1,113 @@ +Pixi Test +========= + +Testing out Pixi.js + + _ = require "./lib/underscore" + + {applyStylesheet} = require "util" + applyStylesheet require("./style") + {width, height} = require "./pixie" + + {update, applyProperties, hydrate} = require "./object_updater" + editor = require("./editor")() + + PIXI = require "./lib/pixi" + # PIXI.Texture.SCALE_MODE.DEFAULT = PIXI.Texture.SCALE_MODE.NEAREST + + stage = new PIXI.Stage(0x66FF99) + + renderer = PIXI.autoDetectRenderer(width, height) + + clickHandler = (mouseData) -> + if mouseData.originalEvent.ctrlKey or mouseData.originalEvent.metaKey + editor.activeObject mouseData.target.data + else + if data = mouseData.target.data + data.click?(data) + + document.body.appendChild(renderer.view) + +Load textures from a data file and map them into Pixi.js texture objects + + textures = require "./textures" + Object.keys(textures).forEach (name) -> + value = textures[name] + textures[name] = PIXI.Texture.fromImage("http://a0.pixiecdn.com/#{value}", true) + +Reload our app data or use our default data. + + if data = ENV?.APP_STATE + data = JSON.parse(data) + else + data = require("./default_data") + +Fill children + + populate = (object) -> + [0..4].forEach (i) -> + [0..4].forEach (j) -> + c = new PIXI.Sprite(textures.pixie) + object.addChild c + c.position = + x: i * 50 - 125 + y: j * 50 - 125 + +Reconstitute our objects using our app data. + + objects = data.map (datum) -> + object = new PIXI.Sprite(textures[datum.sprite]) + + datum._host = object + + object.anchor.x = object.anchor.y = 0.5 + + object.data = datum + object.interactive = true + object.click = clickHandler + + # TODO: Figure out child object compositions + # something like + # object.data.children?.forEach (datum) -> + # recurse object, datum + # populate object + + hydrate(object.data) + applyProperties(object) + + # TODO: stage should be 'parent' or 'root' so we can handle trees of objects + stage.addChild(object) + + return object + +Our main loop, update and draw. + + dt = 1/60 + animate = -> + requestAnimationFrame(animate) + + objects.forEach (object) -> + update(object, dt) + + renderer.render(stage) + + requestAnimationFrame(animate) + +This is where we export and expose our app state. + + global.appData = -> + JSON.stringify stage.children.map (child) -> + _.omit child.data, "_host" + +Text sample (still need to figure out how to handle different PIXI types for our +objects) + + addText = -> + textSample = new PIXI.Text "Pixi.js can has\nmultiline text!", + font: "35px Snippet" + fill: "white" + align: "left" + textSample.position.x = 20 + textSample.position.y = 20 + stage.addChild(textSample) +