diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..81f187b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.psci_modules +bower_components +built-tests +coverage +lib +node_modules diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68b62ea --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2014, Michael Ficarra. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the project nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall the copyright holder be liable for any direct, +indirect, incidental, special, exemplary, or consequential damages (including, +but not limited to, procurement of substitute goods or services; loss of use, +data, or profits; or business interruption) however caused and on any theory of +liability, whether in contract, strict liability, or tort (including negligence +or otherwise) arising in any way out of the use of this software, even if +advised of the possibility of such damage. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c0a130 --- /dev/null +++ b/Makefile @@ -0,0 +1,61 @@ +default: build doc +all: build doc test + +MODULE = Mario + +build: lib/$(MODULE).js +build-tests: $(TESTSOUT) +externs: lib/$(MODULE).externs.purs +deps: node_modules bower_components +doc: docs/README.md + + +BOWER_DEPS = $(shell find bower_components/purescript-*/src -name '*.purs' -type f | sort) +SRC = $(shell find src -name '*.purs' -type f | sort) +TESTS = $([ -d test ] && shell find test -name '*.purs' -type f | sort) +TESTSOUT = $(TESTS:test/%.purs=built-tests/%.js) + +BOWER = node_modules/.bin/bower +ISTANBUL = node_modules/.bin/istanbul +MOCHA = node_modules/.bin/_mocha +MOCHA_OPTS = --inline-diffs --check-leaks -R dot + +lib/$(MODULE).js: bower_components src/$(MODULE).purs + @mkdir -p '$(@D)' + psc --verbose-errors \ + --main $(MODULE) \ + ${BOWER_DEPS} $(SRC) \ + > lib/$(MODULE).js + +.PHONY: default all build externs deps doc clean test build-tests + +lib/$(MODULE).externs.purs: bower_components src/$(MODULE).purs + @mkdir -p '$(@D)' + psc --verbose-errors \ + -m $(MODULE) \ + --codegen $(MODULE) \ + -e lib/$(MODULE).externs.purs \ + ${BOWER_DEPS} $(SRC) \ + > /dev/null + +docs/README.md: lib/$(MODULE).externs.purs + @mkdir -p '$(@D)' + docgen lib/$(MODULE).externs.purs > docs/README.md + +built-tests/%.js: bower_components test/%.purs + @mkdir -p '$(@D)' + psc --verbose-errors -m Tests \ + $(BOWER_DEPS) '$<' \ + >'$@' + +node_modules: + npm install + +bower_components: node_modules + $(BOWER) install + +test: node_modules $(TESTSOUT) lib/$(MODULE).js + [ -d test ] && $(ISTANBUL) cover --root lib $(MOCHA) -- $(MOCHA_OPTS) -- built-tests + +clean: + rm -rf lib built-tests coverage bower_components node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..39afeeb --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +purescript-demo-mario +===================== + +Implementation of [Elm's Mario demo](http://elm-lang.org/edit/examples/Intermediate/Mario.elm) in PureScript. + +![](https://raw.githubusercontent.com/michaelficarra/purescript-demo-mario/master/demo.gif) + +## Usage + +```sh +make +``` + +Open `index.html` to interact. + +## Documentation + +See the [auto-generated documentation](./docs). diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..e094f13 --- /dev/null +++ b/bower.json @@ -0,0 +1,28 @@ +{ + "name": "purescript-demo-mario", + "homepage": "https://github.com/michaelficarra/purescript-demo-mario", + "description": "implementation of Elm's Mario demo in PureScript", + "keywords": [ + "purescript", + "demo", + "mario", + "example", + "sample", + "frp", + "elm" + ], + "license": "BSD-3-Clause", + "ignore": [ + "**/.*", + "bower_components", + "node_modules", + "bower.json", + "package.json" + ], + "dependencies": { + "purescript-dom": "*", + "purescript-math": "*", + "purescript-signal": "git@github.com:bodil/purescript-signal.git" + }, + "devDependencies": {} +} diff --git a/demo.gif b/demo.gif new file mode 100644 index 0000000..b08bf6c Binary files /dev/null and b/demo.gif differ diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..3e0f410 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,72 @@ +# Module Documentation + +## Module Mario + +### Types + + data Direction where + Left :: Direction + Right :: Direction + + data Verb where + Jumping :: Verb + Walking :: Verb + Standing :: Verb + + +### Values + + accel :: Mario.GameState -> Number + + airAccel :: Number + + airFriction :: Number + + applyFriction :: Mario.GameState -> Mario.GameState + + applyGravity :: Mario.GameState -> Mario.GameState + + currentActivity :: Mario.GameState -> Mario.Verb + + friction :: Mario.GameState -> Number + + gravity :: Number + + groundAccel :: Number + + groundFriction :: Number + + groundHeight :: Number + + initialState :: Mario.GameState + + isAirborne :: Mario.GameState -> Boolean + + jump :: Boolean -> Mario.GameState -> Mario.GameState + + jumpKeyCode :: Number + + jumpSpeed :: Number + + leftKeyCode :: Number + + main :: forall t1844. Control.Monad.Eff.Eff t1844 Prelude.Unit + + marioLogic :: Mario.Inputs -> Mario.GameState -> Mario.GameState + + marioSpriteUrl :: Mario.Verb -> Mario.Direction -> String + + maxMoveSpeed :: Number + + mkInputs :: Boolean -> Boolean -> Boolean -> Mario.Inputs + + offsetGround :: Number -> Mario.DOM.Coordinate -> Mario.DOM.Coordinate + + rightKeyCode :: Number + + velocity :: Mario.GameState -> Mario.GameState + + walk :: Boolean -> Boolean -> Mario.GameState -> Mario.GameState + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..d735905 --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + +
+ +