Created
September 4, 2017 15:46
-
-
Save resir014/5b7dee4d6a5c8094f25b6e8d3e1cb35d to your computer and use it in GitHub Desktop.
Vanilla JS (ES6!) implementation of screeps-inscribe. Copy and paste them to your Screeps code.
This file contains 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
/* | |
* Inscribe - a series of helper classes for improving the logging experience | |
* on Screeps. | |
*/ | |
/** | |
* Initialise Inscribe functions to the global. | |
* | |
* @export | |
*/ | |
export function init() { | |
return { color, link, tooltip, time } | |
} | |
/** | |
* Decorates a string of text with color. | |
* | |
* @param {string} str The string to format. | |
* @param {string} fontColor Any HTML color name (`teal`) or hex code (`#33b5e5`). | |
* @returns {string} | |
*/ | |
export function color(str, fontColor) { | |
return `<span style="color:${fontColor}">${str}</span>`; | |
} | |
/** | |
* Appends a link to log output | |
* | |
* @export | |
* @param {string} href Any string-escaped link. | |
* @param {string} title The link title. | |
* @returns {string} | |
*/ | |
export function link(href, title) { | |
return `<a href="${href}" target="_blank">${title}</a>`; | |
} | |
/** | |
* Allows tooltip to be sent to the formatter | |
* | |
* @export | |
* @param {string} str The string to format | |
* @param {string} tooltipText The tooltip text to give away | |
* @returns {string} | |
*/ | |
export function tooltip(str, tooltipText) { | |
return `<abbr title='${tooltipText}'>${str}</abbr>`; | |
} | |
/** | |
* Outputs a formatted version of `Game.time` | |
* | |
* @export | |
* @param {string} [fontColor='gray'] Any HTML color name (`teal`) or hex code | |
* (`#33b5e5`). Defaults to `gray` if empty. | |
* @returns {string} | |
*/ | |
export function time(fontColor = 'gray') { | |
return color(Game.time.toString(), fontColor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment