Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
fix #13 , now charEvents are only triggered once per char until the e…
Browse files Browse the repository at this point in the history
…vent is finished!
  • Loading branch information
ericoporto committed Nov 30, 2016
1 parent ed45f13 commit bb0964c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ engine.translateActions = function(action, param, position, charsender) {

function char(chara, x, y) {
this['chara'] = resources['charas'][chara]
this['charEventBlocked'] = false;
this['nocollision'] = this.chara.properties.nocollision
this['charaset'] = resources['charasets'][this['chara']['charaset']]
this['pushable'] = this.chara.properties.pushable
Expand Down Expand Up @@ -1082,7 +1083,13 @@ eventInMap = function(level, evType, position) {
};

eventInChar = function(char, evType, position) {
if(char.charEventBlocked){
return false;
}

if ( engine.compareTypes(char['chara']['actions']['type'],evType) ) {

char.charEventBlocked = true;
char.charwasfacingfirst = char.facing;
char.waits = 16;
var newfacing = player.charaFacingTo(char);
Expand All @@ -1099,6 +1106,7 @@ eventInChar = function(char, evType, position) {
engine.atomStack.push([function() {
char.stopped = false;
char.facing = char.charwasfacingfirst;
char.charEventBlocked = false;
}, '']);
return true;
} else {
Expand Down
39 changes: 33 additions & 6 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ printer.isShown = false;
printer.startingBox = [];
printer.textWidth = screen.GWIDTH-32;
printer.textHeight = 65;
printer.boxbuffer = document.createElement('canvas');

printer.drawText = function(text,x,y){

Expand All @@ -21,12 +22,34 @@ printer.textBoxes = function(_text) {
var i=0;
var remaining_text = _text;
while(remaining_text!=''){
var boxbuffer = document.createElement('canvas')
boxbuffer.width = printer.textWidth;
boxbuffer.height = printer.textHeight;
png_font.ctx = boxbuffer.getContext('2d');
printer.boxbuffer.width = 0;
printer.boxbuffer.height = 0;
printer.boxbuffer.width = printer.textWidth;
printer.boxbuffer.height = printer.textHeight;
png_font.ctx = printer.boxbuffer.getContext('2d');
remaining_text = png_font.drawText(remaining_text,[0,0],'#FFFFFF',2,'#221100');
printer.buffer.push(boxbuffer);

var img = new Image(); // Create new img element
if (!!HTMLCanvasElement.prototype.toBlob) {
//if we have blob, will try to convert asynchronously
(function(img){ printer.boxbuffer.toBlob(function(blob) {
var objectUrl = URL.createObjectURL(blob);

img.onload = function() {
// no longer need to read the blob so it's revoked
URL.revokeObjectURL(objectUrl);
};
img.loaded = true
img.src = objectUrl;
}, "image/png");
})(img)
} else {
//no toBlob support, let's use toDataUrl
img.src = printer.boxbuffer.toDataURL('image/bmp');
img.loaded = true
}

printer.buffer.push(img);
i++;
}

Expand Down Expand Up @@ -57,6 +80,8 @@ printer.dismissText = function() {
};

printer.nextBox = function() {
URL.revokeObjectURL(printer.buffer[0].src);
printer.buffer[0].src = ''
printer.buffer.shift()
if (printer.buffer.length <= printer.startingBox[0]) {
printer.dismissText();
Expand All @@ -68,7 +93,9 @@ printer.nextBox = function() {
printer.update = function() {
if (printer.isShown && printBox.isShown()) {
// console.log('x='+(screen.printBox.X + 16)+'; y='+(screen.printBox.Y+40) +'; w='+printer.textWidth+'; h='+ printer.textHeight)
screen.drawImage(printer.buffer[0], [screen.printBox.X + 16, screen.printBox.Y +8]);
if(!! printer.buffer[0].loaded){
screen.drawImage(printer.buffer[0], [screen.printBox.X + 16, screen.printBox.Y +8]);
}
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/textbuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// the garbage collection was slow to catch all the homeless canvas...

textBuffer = {
newcanvas: document.createElement('canvas'),
buffer: [],
drawText: function(text, posx, posy, size) {
for(var i=0; i<this.buffer.length; i++){
Expand All @@ -23,24 +24,25 @@ textBuffer = {

//let's make the maximum number of texts 24.
if(this.buffer.length>24){
this.buffer[0].src = ''
this.buffer.shift()
}

//since we couldn't find the text, we need to store it.
var newcanvas = document.createElement('canvas');
newcanvas.width = screen.GWIDTH-posx;
newcanvas.height = screen.GHEIGHT;
png_font.ctx =newcanvas.getContext('2d');
this.newcanvas.width = 0;
this.newcanvas.height = 0;
this.newcanvas.width = screen.GWIDTH-posx;
this.newcanvas.height = screen.GHEIGHT;
png_font.ctx =this.newcanvas.getContext('2d');

png_font.drawText(text,[ 0,0],'#FFFFFF',size,'#221100',null, true);

var img = new Image(); // Create new img element
img.src = newcanvas.toDataURL('image/png');
img.src = this.newcanvas.toDataURL('image/png');
this.buffer.push({text: text,
posx: posx,
posy: posy,
size: size,
canvas: img});
newcanvas=0;
}
}

0 comments on commit bb0964c

Please sign in to comment.