summaryrefslogtreecommitdiff
path: root/tests/resources/userdiff/files/file.javascript
diff options
context:
space:
mode:
authorArthur Schreiber <schreiber.arthur@googlemail.com>2014-07-14 22:20:02 +0200
committerArthur Schreiber <schreiber.arthur@googlemail.com>2014-10-09 22:14:55 +0200
commit19fa9c0ca018ccc00299222e015a182e73816dc1 (patch)
treebbc32d6a3277584f8217c9d32b0e9c7629165146 /tests/resources/userdiff/files/file.javascript
parent324154a4538f9e821cc1065b72109033b6d5da03 (diff)
downloadlibgit2-19fa9c0ca018ccc00299222e015a182e73816dc1.tar.gz
New test files for the javascript diff driver.
Diffstat (limited to 'tests/resources/userdiff/files/file.javascript')
-rw-r--r--tests/resources/userdiff/files/file.javascript188
1 files changed, 94 insertions, 94 deletions
diff --git a/tests/resources/userdiff/files/file.javascript b/tests/resources/userdiff/files/file.javascript
index 7cd3c5a8a..53917973a 100644
--- a/tests/resources/userdiff/files/file.javascript
+++ b/tests/resources/userdiff/files/file.javascript
@@ -1,108 +1,108 @@
-/*
- Some code extracted from https://github.com/julianlloyd/scrollReveal.js
- which happens to be a trending Javascript repo with an MIT license at
- the time I was working on Javascript userdiff support in libgit2
+define(function(require, exports, module) {
+ module.exports = Player;
- I extracted just some of the code, so I suspect this is no longer valid
- Javascript code, but it contains enough example patterns to work.
-*/
-;(function (window) {
+ var Key = require("./key")
+ , Direction = require("./direction");
- 'use strict';
+ function Player(game) {
+ this.game = game;
- var docElem = window.document.documentElement;
+ this.image = new Image("./assets/fighter.png");
+ this.game.resources.add(this.image);
- function getViewportH () {
- var client = docElem['clientHeight'],
- inner = window['innerHeight'],
- sample = window['otherProperty'];
+ this.x = 0;
+ this.y = 0;
- return (client < inner) ? inner : client;
- }
-
- function getOffset (el) {
- var offsetTop = 0,
- offsetLeft = 0;
+ this.pixelX = 10;
+ this.pixelY = 10;
- do {
- if (!isNaN(el.offsetTop)) {
- offsetTop += el.offsetTop + 1;
- }
- if (!isNaN(el.offsetLeft)) {
- offsetLeft += el.offsetLeft;
- }
- } while (el = el.offsetParent)
-
- return {
- top: offsetTop,
- left: offsetLeft
- }
+ this.animationStep = 0;
}
- function isElementInViewport (el, h) {
- var scrolled = window.pageYOffset,
- viewed = scrolled + getViewportH(),
- elTop = getOffset(el).top,
- elBottom = elTop + el.offsetHeight,
- h = h || 0;
-
- return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
- }
-
- scrollReveal.prototype = {
-
- _init: function () {
-
- var self = this;
-
- this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
- this.scrolled = false;
+ Player.prototype.update = function() {
+ if (!this.isWalking()) {
+ this.handleInput();
+ }
- this.elems.forEach(function (el, i) {
- self.animate(el);
- });
+ if (this.isWalking()) {
+ // Increase the animation step.
+ this.animationStep = ++this.animationStep % 60;
- var scrollHandler = function () {
- if (!self.scrolled) {
- self.scrolled = true;
- setTimeout(function () {
- self._scrollPage();
- }, 61);
- }
- };
+ if (this.x * 32 > this.pixelX) {
+ this.pixelX++;
+ } else if (this.x * 32 < this.pixelX) {
+ this.pixelX--;
+ }
- var resizeHandler = function () {
- function delayed() {
- self._scrollPage();
- self.resizeTimeout = null;
- }
- if (self.resizeTimeout) {
- clearTimeout(self.resizeTimeout);
+ if (this.y * 32 > this.pixelY) {
+ this.pixelY++;
+ } else if (this.y * 32 < this.pixelY) {
+ this.pixelY--;
+ }
+ } else {
+ // Reset the animation step.
+ this.animationStep = 0;
+ }
+ };
+
+ Player.prototype.handleInput = function() {
+ var keyboard = this.game.keyboard, finalAction, action, inputs = {
+ 'moveDown': keyboard.isDown(Key.DOWN),
+ 'moveUp': keyboard.isDown(Key.UP),
+ 'moveLeft': keyboard.isDown(Key.LEFT),
+ 'moveRight': keyboard.isDown(Key.RIGHT)
+ };
+
+ for (action in inputs) {
+ if (inputs[action]) {
+ if (!finalAction || inputs[finalAction] < inputs[action]) {
+ finalAction = action;
}
- self.resizeTimeout = setTimeout(delayed, 200);
- };
-
- window.addEventListener('scroll', scrollHandler, false);
- window.addEventListener('resize', resizeHandler, false);
- },
-
- /*=============================================================================*/
-
- _scrollPage: function () {
- var self = this;
-
- this.elems.forEach(function (el, i) {
- if (isElementInViewport(el, self.options.viewportFactor)) {
- self.animate(el);
- }
- });
- this.scrolled = false;
- this.tested = true;
- },
- }; // end scrollReveal.prototype
+ }
+ }
- document.addEventListener("DOMContentLoaded", function (evt) {
- window.scrollReveal = new scrollReveal();
- });
+ this[finalAction] && this[finalAction]();
+ };
+
+ Player.prototype.isWalking = function() {
+ return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
+ };
+
+ Player.prototype.moveDown = function() {
+ this.y += 1;
+ this.direction = Direction.DOWN;
+ };
+
+ Player.prototype.moveUp = function() {
+ this.y -= 1;
+ this.direction = Direction.UP;
+ };
+
+ Player.prototype.moveLeft = function() {
+ this.x -= 5;
+ this.direction = Direction.LEFT;
+ };
+
+ Player.prototype.moveRight = function() {
+ this.x += 1;
+ this.direction = Direction.RIGHT;
+ };
+
+ Player.prototype.draw = function(context) {
+ var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
+
+ switch(this.direction) {
+ case Direction.UP:
+ offsetY = 48 * 3;
+ break;
+ case Direction.RIGHT:
+ offsetY = 48 * 2;
+ break;
+ case Direction.LEFT:
+ offsetY = 48;
+ break;
+ }
-})(window);
+ context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
+ };
+});