Skip to content

Commit

Permalink
clean up asseta
Browse files Browse the repository at this point in the history
move assert comments into strings
  • Loading branch information
KilledByAPixel committed Jul 11, 2024
1 parent 6237456 commit 10c9312
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/platformer/gameEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const sound_killEnemy = new Sound([,,783,,.03,.02,1,2,,,940,.03,,,,,.2,.6,,.0
const persistentParticleDestroyCallback = (particle)=>
{
// copy particle to tile layer on death
ASSERT(!particle.tileInfo); // quick draw to tile layer uses canvas 2d so must be untextured
ASSERT(!particle.tileInfo, 'quick draw to tile layer uses canvas 2d so must be untextured');
if (particle.groundObject)
tileLayer.drawTile(particle.pos, particle.size, particle.tileInfo, particle.color, particle.angle, particle.mirror);
}
Expand Down
9 changes: 4 additions & 5 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let frameTimeLastMS = 0, frameTimeBufferMS = 0, averageFPS = 0;
* @memberof Engine */
function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSources=['tiles.png'])
{
ASSERT(Array.isArray(imageSources)); // pass in images as array
ASSERT(Array.isArray(imageSources), 'pass in images as array');

// internal update loop for engine
function engineUpdate(frameTimeMS=0)
Expand Down Expand Up @@ -233,8 +233,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
overlayContext = overlayCanvas.getContext('2d');

// set canvas style
const styleCanvas =
'position:absolute;' + // position
const styleCanvas = 'position:absolute;' + // position
'top:50%;left:50%;transform:translate(-50%,-50%)'; // center
(glCanvas||mainCanvas).style.cssText = mainCanvas.style.cssText = overlayCanvas.style.cssText = styleCanvas;

Expand All @@ -256,12 +255,12 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
showSplashScreen && promises.push(new Promise(resolve =>
{
let t = 0;
console.log(`LittleJS Engine v${engineVersion}`);
console.log(`${engineName} Engine v${engineVersion}`);
updateSplash();
function updateSplash()
{
clearInput();
drawEngineSplashScreen(t += .01);
drawEngineSplashScreen(t+=.01);
t>1 ? resolve() : setTimeout(updateSplash, 16);
}
}));
Expand Down
6 changes: 3 additions & 3 deletions src/engineDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function ASSERT(assert, output) { enableAsserts && console.assert(assert, output
* @memberof Debug */
function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
{
ASSERT(typeof color == 'string'); // pass in regular html strings as colors
ASSERT(typeof color == 'string', 'pass in css color strings');
debugPrimitives.push({pos, size:vec2(size), color, time:new Timer(time), angle, fill});
}

Expand All @@ -81,7 +81,7 @@ function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
* @memberof Debug */
function debugCircle(pos, radius=0, color='#fff', time=0, fill=false)
{
ASSERT(typeof color == 'string'); // pass in regular html strings as colors
ASSERT(typeof color == 'string', 'pass in css color strings');
debugPrimitives.push({pos, size:radius, color, time:new Timer(time), angle:0, fill});
}

Expand Down Expand Up @@ -132,7 +132,7 @@ function debugAABB(pA, sA, pB, sB, color)
* @memberof Debug */
function debugText(text, pos, size=1, color='#fff', time=0, angle=0, font='monospace')
{
ASSERT(typeof color == 'string'); // pass in regular html strings as colors
ASSERT(typeof color == 'string', 'pass in css color strings');
debugPrimitives.push({text, pos, size, color, time:new Timer(time), angle, font});
}

Expand Down
8 changes: 4 additions & 4 deletions src/engineDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ function worldToScreen(worldPos)
function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
angle=0, mirror, additiveColor=new Color(0,0,0,0), useWebGL=glEnable, screenSpace, context)
{
ASSERT(!context || !useWebGL); // context only supported in canvas 2D mode
ASSERT(typeof tileInfo !== 'number' || !tileInfo); // prevent old style calls
// to fix old calls, replace with tile(tileIndex, tileSize)
ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode');
ASSERT(typeof tileInfo !== 'number' || !tileInfo,
'this is an old style calls, to fix replace it with tile(tileIndex, tileSize)');

const textureInfo = tileInfo && tileInfo.getTextureInfo();
if (useWebGL)
Expand Down Expand Up @@ -333,7 +333,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, conte
* @memberof Draw */
function setBlendMode(additive, useWebGL=glEnable, context)
{
ASSERT(!context || !useWebGL); // context only supported in canvas 2D mode
ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode');
if (useWebGL)
glAdditive = additive;
else
Expand Down
6 changes: 3 additions & 3 deletions src/engineInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @memberof Input */
function keyIsDown(key, device=0)
{
ASSERT(device > 0 || typeof key !== 'number' || key < 3, 'Use code string for keyboard!');
ASSERT(device > 0 || typeof key !== 'number' || key < 3, 'use code string for keyboard');
return inputData[device] && !!(inputData[device][key] & 1);
}

Expand All @@ -27,7 +27,7 @@ function keyIsDown(key, device=0)
* @memberof Input */
function keyWasPressed(key, device=0)
{
ASSERT(device > 0 || typeof key !== 'number' || key < 3, 'Use code string for keyboard!');
ASSERT(device > 0 || typeof key !== 'number' || key < 3, 'use code string for keyboard');
return inputData[device] && !!(inputData[device][key] & 2);
}

Expand All @@ -38,7 +38,7 @@ function keyWasPressed(key, device=0)
* @memberof Input */
function keyWasReleased(key, device=0)
{
ASSERT(device > 0 || typeof key !== 'number' || key < 3, 'Use code string for keyboard!');
ASSERT(device > 0 || typeof key !== 'number' || key < 3, 'use code string for keyboard');
return inputData[device] && !!(inputData[device][key] & 4);
}

Expand Down
6 changes: 3 additions & 3 deletions src/engineMedals.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Medal
return;

// save the medal
ASSERT(medalsSaveName); // save name must be set
ASSERT(medalsSaveName, 'save name must be set');
localStorage[this.storageKey()] = this.unlocked = 1;
medalsDisplayQueue.push(this);
newgrounds && newgrounds.unlockMedal(this.id);
Expand Down Expand Up @@ -179,8 +179,8 @@ class Newgrounds
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
constructor(app_id, cipher, cryptoJS)
{
ASSERT(!newgrounds && app_id>0); // can only be one newgrounds object
ASSERT(!cipher || cryptoJS); // must provide cryptojs if there is a cipher
ASSERT(!newgrounds && app_id>0, 'there can only be one newgrounds object');
ASSERT(!cipher || cryptoJS, 'must provide cryptojs if there is a cipher');

this.app_id = app_id;
this.cipher = cipher;
Expand Down
6 changes: 3 additions & 3 deletions src/engineObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class EngineObject
constructor(pos=vec2(), size=vec2(1), tileInfo, angle=0, color, renderOrder=0)
{
// set passed in params
ASSERT(isVector2(pos) && isVector2(size)); // ensure pos and size are vec2s
ASSERT(typeof tileInfo !== 'number' || !tileInfo); // prevent old style calls
ASSERT(isVector2(pos) && isVector2(size), 'ensure pos and size are vec2s');
ASSERT(typeof tileInfo !== 'number' || !tileInfo, 'old style tile setup');

/** @property {Vector2} - World space position of the object */
this.pos = pos.copy();
Expand Down Expand Up @@ -363,7 +363,7 @@ class EngineObject
* @param {Boolean} [collideTiles] - Does it collide with the tile collision */
setCollision(collideSolidObjects=true, isSolid=true, collideTiles=true)
{
ASSERT(collideSolidObjects || !isSolid); // solid objects must be set to collide
ASSERT(collideSolidObjects || !isSolid, 'solid objects must be set to collide');

this.collideSolidObjects = collideSolidObjects;
this.isSolid = isSolid;
Expand Down
6 changes: 3 additions & 3 deletions src/engineTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class TileLayer extends EngineObject
// Render the tile layer, called automatically by the engine
render()
{
ASSERT(mainContext != this.context); // must call redrawEnd() after drawing tiles
ASSERT(mainContext != this.context, 'must call redrawEnd() after drawing tiles');

// flush and copy gl canvas because tile canvas does not use webgl
glEnable && !glOverlay && !this.isOverlay && glCopyToContext(mainContext);
Expand Down Expand Up @@ -271,7 +271,7 @@ class TileLayer extends EngineObject
/** Call to end the redraw process */
redrawEnd()
{
ASSERT(mainContext == this.context); // must call redrawStart() before drawing tiles
ASSERT(mainContext == this.context, 'must call redrawStart() before drawing tiles');
glEnable && glCopyToContext(mainContext, true);
//debugSaveCanvas(this.canvas);

Expand All @@ -291,7 +291,7 @@ class TileLayer extends EngineObject
const d = this.getData(layerPos);
if (d.tile != undefined)
{
ASSERT(mainContext == this.context); // must call redrawStart() before drawing tiles
ASSERT(mainContext == this.context, 'must call redrawStart() before drawing tiles');
const tileInfo = tile(d.tile, this.tileInfo.size, this.tileInfo.textureIndex);
drawTile(pos, vec2(1), tileInfo, d.color, d.direction*PI/2, d.mirror);
}
Expand Down
2 changes: 1 addition & 1 deletion src/engineWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ let glPostShader, glPostArrayBuffer, glPostTexture, glPostIncludeOverlay;
* @memberof WebGL */
function glInitPostProcess(shaderCode, includeOverlay)
{
ASSERT(!glPostShader); // can only have 1 post effects shader
ASSERT(!glPostShader, 'can only have 1 post effects shader');

if (!shaderCode) // default shader pass through
shaderCode = 'void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}';
Expand Down

0 comments on commit 10c9312

Please sign in to comment.