Skip to content

Commit

Permalink
Merge pull request #700 from ZeLonewolf/zlw-shieldgen-refactor
Browse files Browse the repository at this point in the history
Refactor utility functions out of shield definitions
  • Loading branch information
ZeLonewolf authored Jan 16, 2023
2 parents 6fd5b5b + 9a4763b commit d61d0ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
19 changes: 16 additions & 3 deletions src/js/shield.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ export function isValidRef(ref) {
return ref !== null && ref.length !== 0 && ref.length <= 6;
}

/**
* Get the number of banner placards associated with this shield
*
* @param {*} shield - Shield definition
* @returns the number of banner placards that need to be drawn
*/
export function getBannerCount(shield) {
if (shield == null || typeof shield.modifiers == "undefined") {
return 0; //Unadorned shield
}
return shield.modifiers.length;
}

/**
* Retrieve the shield blank that goes with a particular route. If there are
* multiple shields for a route (different widths), it picks the best shield.
Expand Down Expand Up @@ -128,7 +141,7 @@ function textColor(shieldDef) {
* @returns a blank graphics context
*/
function generateBlankGraphicsContext(shieldDef, routeDef) {
var bannerCount = ShieldDef.getBannerCount(shieldDef);
var bannerCount = getBannerCount(shieldDef);
var shieldArtwork = getRasterShieldBlank(shieldDef, routeDef);
var compoundBounds = null;

Expand All @@ -148,7 +161,7 @@ function generateBlankGraphicsContext(shieldDef, routeDef) {
}

function drawShield(ctx, shieldDef, routeDef) {
var bannerCount = ShieldDef.getBannerCount(shieldDef);
var bannerCount = getBannerCount(shieldDef);

var shieldArtwork = getRasterShieldBlank(shieldDef, routeDef);

Expand All @@ -172,7 +185,7 @@ function drawShield(ctx, shieldDef, routeDef) {
}

function drawShieldText(ctx, shieldDef, routeDef) {
var bannerCount = ShieldDef.getBannerCount(shieldDef);
var bannerCount = getBannerCount(shieldDef);
var shieldBounds = null;

var shieldArtwork = getRasterShieldBlank(shieldDef, routeDef);
Expand Down
26 changes: 0 additions & 26 deletions src/js/shield_defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4222,29 +4222,3 @@ export function loadShields(shieldImages) {

return shields;
}

/**
* Determines whether there is a raster shield background for a particular network
*
* @param {*} network - Route network
* @returns true if a raster shield is available
*/
export function hasShieldArtwork(network) {
return (
shields[network] != null &&
typeof shields[network].backgroundImage !== "undefined"
);
}

/**
* Get the number of banner placards associated with this shield
*
* @param {*} shield - Shield definition
* @returns the number of banner placards that need to be drawn
*/
export function getBannerCount(shield) {
if (shield == null || typeof shield.modifiers == "undefined") {
return 0; //Unadorned shield
}
return shield.modifiers.length;
}

0 comments on commit d61d0ce

Please sign in to comment.