Преглед изворни кода

first work on mobile

tags/v0.3.1
BigBadWaffle пре 5 година
committed by Big Bad Waffle
родитељ
комит
22c3ab8ca5
9 измењених фајлова са 126 додато и 49 уклоњено
  1. +2
    -1
      src/client/.eslintrc
  2. +0
    -2
      src/client/js/components/bumpAnimation.js
  3. +1
    -29
      src/client/js/components/keyboardMover.js
  4. +16
    -9
      src/client/js/components/pather.js
  5. +7
    -2
      src/client/js/components/player.js
  6. +65
    -0
      src/client/js/components/touchMover.js
  7. +33
    -0
      src/client/js/input.js
  8. +2
    -1
      src/client/js/misc/helpers.js
  9. +0
    -5
      src/client/js/objects/objects.js

+ 2
- 1
src/client/.eslintrc Прегледај датотеку

@@ -55,7 +55,8 @@
"_": false, "_": false,
"PIXI": false, "PIXI": false,
"scale": false, "scale": false,
"scaleMult": false
"scaleMult": false,
"isMobile": false
}, },


"rules": { "rules": {


+ 0
- 2
src/client/js/components/bumpAnimation.js Прегледај датотеку

@@ -47,8 +47,6 @@ define([
this.direction *= -1; this.direction *= -1;
if ((this.direction === 1) && (!this.infinite)) if ((this.direction === 1) && (!this.infinite))
this.destroyed = true; this.destroyed = true;
else
this.obj.dirty = true;
} }
} }




+ 1
- 29
src/client/js/components/keyboardMover.js Прегледај датотеку

@@ -23,9 +23,6 @@ define([
if (this.obj.dead) if (this.obj.dead)
return; return;


if (this.obj.moveAnimation)
this.obj.pather.clearPath();

if (this.moveCd > 0) { if (this.moveCd > 0) {
this.moveCd--; this.moveCd--;
return; return;
@@ -76,32 +73,7 @@ define([


this.moveCd = this.moveCdMax; this.moveCd = this.moveCdMax;


this.addQueue(newX, newY);
},

addQueue: function (x, y) {
let pather = this.obj.pather;
const isPriority = !pather.path.length;

if (this.obj.moveAnimation)
return;
else if (!pather.add(x, y))
return;

this.obj.dirty = true;

pather.pathPos.x = x;
pather.pathPos.y = y;

client.request({
cpn: 'player',
method: 'move',
priority: isPriority ? true : null,
data: {
x: x,
y: y
}
});
this.obj.pather.addQueue(newX, newY);
} }
}; };
}); });

+ 16
- 9
src/client/js/components/pather.js Прегледај датотеку

@@ -51,9 +51,12 @@ define([
}, },


add: function (x, y) { add: function (x, y) {
if (this.path.length >= maxPathLength)
if (this.path.length >= maxPathLength || this.obj.moveAnimation)
return; return;


pather.pathPos.x = x;
pather.pathPos.y = y;

this.path.push({ this.path.push({
x: x, x: x,
y: y, y: y,
@@ -68,10 +71,21 @@ define([
}) })
}); });


return true;
client.request({
cpn: 'player',
method: 'move',
priority: !this.path.length,
data: {
x: x,
y: y
}
});
}, },


update: function () { update: function () {
if (this.obj.moveAnimation)
this.clearPath();

let x = this.obj.x; let x = this.obj.x;
let y = this.obj.y; let y = this.obj.y;


@@ -100,13 +114,6 @@ define([
return; return;
} }
} }
},

setPath: function (path) {
this.path = this.path.concat(path);

this.pathPos.x = round(path[path.length - 1].x);
this.pathPos.y = round(path[path.length - 1].y);
} }
}; };
}); });

+ 7
- 2
src/client/js/components/player.js Прегледај датотеку

@@ -20,8 +20,13 @@ define([
init: function () { init: function () {
const obj = this.obj; const obj = this.obj;


obj.addComponent('keyboardMover');
obj.addComponent('mouseMover');
if (isMobile)
obj.addComponent('touchMover');
else {
obj.addComponent('keyboardMover');
obj.addComponent('mouseMover');
}
obj.addComponent('serverActions'); obj.addComponent('serverActions');
obj.addComponent('pather'); obj.addComponent('pather');




+ 65
- 0
src/client/js/components/touchMover.js Прегледај датотеку

@@ -0,0 +1,65 @@
define([
'js/system/client',
'js/misc/physics',
'js/system/events'
], function (
client,
physics,
events
) {
return {
type: 'touchMover',

lastNode: null,
nodes: [],

minSqrDistance: 9,

init: function () {
['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'].forEach(e => this[e].bind(this));
},

onTouchStart: function (e) {
this.lastNode = e;
},

onTouchMove: function (e) {
const lastNode = this.lastNode;

let sqrDistance = Math.pow(lastNode.x - e.x, 2) + Math.pow(lastNode.y - e.y, 2);
if (sqrDistance < this.minSqrDistance)
return;

let dx = 1;
let dy = 0;

let newX = this.obj.pather.pathPos.x + dx;
let newY = this.obj.pather.pathPos.y + dy;

if (physics.isTileBlocking(~~newX, ~~newY)) {
this.bump(dx, dy);
return;
}

this.obj.pather.addQueue(newX, newY);
},

onTouchEnd: function () {
this.lastNode = null;
},

onTouchCancel: function () {
this.lastNode = null;
},

ump: function (dx, dy) {
if (this.obj.pather.path.length > 0)
return;

this.obj.addComponent('bumpAnimation', {
deltaX: dx,
deltaY: dy
});
}
};
});

+ 33
- 0
src/client/js/input.js Прегледај датотеку

@@ -61,6 +61,12 @@ define([
.on('mousedown', this.events.mouse.mouseDown.bind(this)) .on('mousedown', this.events.mouse.mouseDown.bind(this))
.on('mouseup', this.events.mouse.mouseUp.bind(this)) .on('mouseup', this.events.mouse.mouseUp.bind(this))
.on('mousemove', this.events.mouse.mouseMove.bind(this)); .on('mousemove', this.events.mouse.mouseMove.bind(this));

$('.canvas-container');
.on('touchstart', this.events.touch.touchStart.bind(this))
.on('touchmove', this.events.touch.touchMove.bind(this))
.on('touchend', this.events.touch.touchEnd.bind(this))
.on('touchcancel', this.events.touch.touchCancel.bind(this));
}, },


resetKeys: function () { resetKeys: function () {
@@ -168,6 +174,7 @@ define([
events.emit('onKeyUp', key); events.emit('onKeyUp', key);
} }
}, },

mouse: { mouse: {
mouseDown: function (e) { mouseDown: function (e) {
let el = $(e.target); let el = $(e.target);
@@ -207,6 +214,32 @@ define([
this.mouse.x = e.offsetX + (renderer.pos.x); this.mouse.x = e.offsetX + (renderer.pos.x);
this.mouse.y = e.offsetY + (renderer.pos.y); this.mouse.y = e.offsetY + (renderer.pos.y);
} }
},

touch: {
touchStart: function (e) {
let touch = e.touches[0];
events.emit('onTouchStart', {
x: touch.clientX,
y: touch.clientY
});
},

touchMove: function (e) {
let touch = e.touches[0];
events.emit('onTouchMove', {
x: touch.clientX,
y: touch.clientY
});
},

touchEnd: function (e) {
events.emit('onTouchEnd');
},

touchCancel: function (e) {
events.emit('onTouchCancel');
}
} }
} }
}; };


+ 2
- 1
src/client/js/misc/helpers.js Прегледај датотеку

@@ -1,7 +1,8 @@
/* global _, scale, scaleMult */
/* global _, scale, scaleMult, isMobile */


window.scale = 40; window.scale = 40;
window.scaleMult = 5; window.scaleMult = 5;
window.isMobile = /Mobi|Android/i.test(navigator.userAgent);


//eslint-disable-next-line no-extend-native //eslint-disable-next-line no-extend-native
Array.prototype.firstIndex = function (callback, thisArg) { Array.prototype.firstIndex = function (callback, thisArg) {


+ 0
- 5
src/client/js/objects/objects.js Прегледај датотеку

@@ -15,7 +15,6 @@ define([
showNames: false, showNames: false,


objects: [], objects: [],
dirty: false,


init: function () { init: function () {
events.on('onKeyDown', this.onKeyDown.bind(this)); events.on('onKeyDown', this.onKeyDown.bind(this));
@@ -113,8 +112,6 @@ define([
}, },


onGetObject: function (obj) { onGetObject: function (obj) {
this.dirty = true;

//Things like attacks don't have ids //Things like attacks don't have ids
let exists = null; let exists = null;
if (obj.has('id')) if (obj.has('id'))
@@ -327,8 +324,6 @@ define([
} }


o.update(); o.update();
if (o.dirty)
this.dirty = true;
} }
}, },




Loading…
Откажи
Сачувај