forked from increpare/PuzzleScript
-
Notifications
You must be signed in to change notification settings - Fork 6
wip merge pseudo-3d effect from broken-sign-games #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pancelor
wants to merge
1
commit into
Auroriax:master
Choose a base branch
from
pancelor:psp-perspective
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,39 @@ | ||
| function createSprite(name,spritegrid, colors, padding) { | ||
| function createSprite(name,spritegrid, colors, padding, override_cellwidth, override_cellheight) { | ||
| if (colors === undefined) { | ||
| colors = [state.bgcolor, state.fgcolor]; | ||
| } | ||
|
|
||
| var sprite = makeSpriteCanvas(name); | ||
| var spritectx = sprite.getContext('2d'); | ||
|
|
||
| renderSprite(spritectx, spritegrid, colors, padding, 0, 0); | ||
| if (override_cellheight !== undefined) { | ||
| sprite.height=override_cellheight | ||
| } | ||
| renderSprite(spritectx, spritegrid, colors, padding, 0, 0, override_cellwidth, override_cellheight); | ||
|
|
||
| return sprite; | ||
| } | ||
|
|
||
| function renderSprite(spritectx, spritegrid, colors, padding, x, y) { | ||
| // render a sprite (spritegrid, colors) to a drawing context (spritectx,padding,x,y) | ||
| // the image will be scaled up based on cellwidth and cellheight | ||
| function renderSprite(spritectx, spritegrid, colors, padding, x, y, override_cellwidth, override_cellheight) { | ||
| if (colors === undefined) { | ||
| colors = ['#00000000', state.fgcolor]; | ||
| } | ||
|
|
||
| var offsetX = x * cellwidth; | ||
| var offsetY = y * cellheight; | ||
| override_cellheight=override_cellheight || cellheight | ||
| override_cellwidth=override_cellwidth || cellwidth | ||
|
|
||
| var offsetX = x * override_cellwidth; | ||
| var offsetY = y * override_cellheight; | ||
|
|
||
| spritectx.clearRect(offsetX, offsetY, cellwidth, cellheight); | ||
| spritectx.clearRect(offsetX, offsetY, override_cellwidth, override_cellheight); | ||
|
|
||
| var w = spritegrid[0].length; | ||
| var h = spritegrid.length; | ||
| var cw = ~~(cellwidth / (w + (padding|0))); | ||
| var ch = ~~(cellheight / (h + (padding|0))); | ||
| var cw = ~~(override_cellwidth / (w + (padding|0))); | ||
| var ch = ~~(override_cellheight / (h + (padding|0))); | ||
|
|
||
| var pixh=ch; | ||
| if ("scanline" in state.metadata) { | ||
| pixh=Math.ceil(ch/2); | ||
|
|
@@ -120,13 +129,41 @@ function regenSpriteImages() { | |
| continue; | ||
| } | ||
|
|
||
| if (canOpenEditor) { | ||
| spriteimages[i] = createSprite(i.toString(),sprites[i].dat, sprites[i].colors); | ||
| if (sprites[i].dat.length === state.sprite_size) { | ||
| // normal sprite | ||
| if (canOpenEditor) { | ||
| spriteimages[i] = createSprite(i.toString(),sprites[i].dat, sprites[i].colors); | ||
| } | ||
|
|
||
| var spriteX = (i % spritesheetSize)|0; | ||
| var spriteY = (i / spritesheetSize)|0; | ||
| renderSprite(spritesheetContext, sprites[i].dat, sprites[i].colors, 0, spriteX, spriteY); | ||
| sprites[i].canvas=spritesheetCanvas | ||
| sprites[i].sx=spriteX * cellwidth | ||
| sprites[i].sy=spriteY * cellheight | ||
| sprites[i].sw=cellwidth | ||
| sprites[i].sh=cellheight | ||
| sprites[i].oy=0 | ||
| // console.log("normal",i) | ||
| } else { | ||
| // tall sprite | ||
|
|
||
| var name=i.toString() | ||
| var tallheight = cellheight * sprites[i].dat.length / state.sprite_size | ||
|
|
||
| // the only place the overide params are used: | ||
| var canv=createSprite(name,sprites[i].dat, sprites[i].colors,0,cellwidth,tallheight); | ||
| // assert(precanv==canv) | ||
| spriteimages[i] = canv | ||
| sprites[i].canvas=canv | ||
| sprites[i].sx=0 | ||
| sprites[i].sy=0 | ||
| sprites[i].sw=cellwidth | ||
| sprites[i].sh=tallheight | ||
| sprites[i].oy=cellheight - canv.height | ||
| // console.log("tall",name,canv.width,canv.height); | ||
| } | ||
|
|
||
| var spriteX = (i % spritesheetSize)|0; | ||
| var spriteY = (i / spritesheetSize)|0; | ||
| renderSprite(spritesheetContext, sprites[i].dat, sprites[i].colors, 0, spriteX, spriteY); | ||
| // console.log(" ",sprites[i].sx,sprites[i].sy,sprites[i].sw,sprites[i].sh,sprites[i].oy) | ||
| } | ||
|
|
||
| if (canOpenEditor) { | ||
|
|
@@ -147,16 +184,12 @@ var editorGlyphMovements=[]; | |
|
|
||
| var canvasdict={}; | ||
| function makeSpriteCanvas(name) { | ||
| var canvas; | ||
| if (name in canvasdict) { | ||
| canvas = canvasdict[name]; | ||
| } else { | ||
| canvas = document.createElement('canvas'); | ||
| canvasdict[name]=canvas; | ||
| if (!(name in canvasdict)) { | ||
| canvasdict[name]=document.createElement('canvas'); | ||
| canvasdict[name].width = cellwidth; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the important bit here is that the canvas only gets resized on creation, not every time we get it |
||
| canvasdict[name].height = cellheight; | ||
| } | ||
| canvas.width = cellwidth; | ||
| canvas.height = cellheight; | ||
| return canvas; | ||
| return canvasdict[name]; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -495,16 +528,14 @@ function redraw() { | |
| for (var k = 0; k < state.objectCount; k++) { | ||
|
|
||
| if (posMask.get(k) != 0) { | ||
| var spriteX = (k % spritesheetSize)|0; | ||
| var spriteY = (k / spritesheetSize)|0; | ||
|
|
||
| var x = xoffset + (i-mini-cameraOffset.x) * cellwidth; | ||
| var y = yoffset + (j-minj-cameraOffset.y) * cellheight; | ||
|
|
||
| var sprite = sprites[k]; | ||
| ctx.drawImage( | ||
| spritesheetCanvas, | ||
| spriteX * cellwidth, spriteY * cellheight, cellwidth, cellheight, | ||
| Math.floor(x), Math.floor(y), cellwidth, cellheight); | ||
| sprite.canvas, | ||
| sprite.sx,sprite.sy,sprite.sw,sprite.sh, | ||
| Math.floor(x), Math.floor(y)+sprite.oy, sprite.sw,sprite.sh); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -546,12 +577,6 @@ function redraw() { | |
| var posMask = curlevel.getCellInto(posIndex,_o12); | ||
|
|
||
| if (posMask.get(k) != 0) { | ||
| var spriteX = (k % spritesheetSize)|0; | ||
| var spriteY = (k / spritesheetSize)|0; | ||
|
|
||
|
|
||
| //console.log(posIndex + " " + layerID); | ||
|
|
||
| var x = xoffset + (i-mini-cameraOffset.x) * cellwidth; | ||
| var y = yoffset + (j-minj-cameraOffset.y) * cellheight; | ||
|
|
||
|
|
@@ -567,11 +592,11 @@ function redraw() { | |
| ctx.globalAlpha = 1-tween; | ||
| } | ||
| } | ||
|
|
||
| var sprite = sprites[k]; | ||
| ctx.drawImage( | ||
| spritesheetCanvas, | ||
| spriteX * cellwidth, spriteY * cellheight, cellwidth, cellheight, | ||
| Math.floor(x), Math.floor(y), cellwidth, cellheight); | ||
| sprite.canvas, | ||
| sprite.sx,sprite.sy,sprite.sw,sprite.sh, | ||
| Math.floor(x), Math.floor(y)+sprite.oy, sprite.sw,sprite.sh); | ||
| ctx.globalAlpha = 1; | ||
| } | ||
| } | ||
|
|
@@ -839,13 +864,8 @@ function canvasResize() { | |
| cellwidth = canvas.width / screenwidth; | ||
| cellheight = canvas.height / screenheight; | ||
|
|
||
| var w = 5; | ||
| var h = 5; | ||
|
|
||
| if (sprites.length >= 2) { | ||
| var w = sprites[1].dat.length; | ||
| var h = sprites[1].dat.length;//sprites[1].dat[0].length; | ||
| } | ||
| var w = state.sprite_size || 5; | ||
| var h = state.sprite_size || 5; | ||
|
|
||
| if (textMode) { | ||
| w=5 + 1; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the meat of the change - the sprites are packed into a fixed-size spritesheet, but we want to make variably-sized sprites. so, just create a new entire spritesheet for each one. and then for all sprites, track which spritesheet they come from (using the
spritestable)