Name: screeps-visual
Owner: screepers
Description: Chrome Extension that adds a Visual API to screeps
Created: 2016-11-30 16:43:01.0
Updated: 2018-02-12 01:57:22.0
Pushed: 2016-12-12 20:27:26.0
Homepage: null
Size: 19
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Adds a few useful variable wrappers to conole.
RawVisual.commit()
at the end of your main loopAdd this snippet to your code
al.loadVisual = function(){
rn console.log('<script>' +
f(!window.visualLoaded){' +
$.getScript("https://screepers.github.io/screeps-visual/src/visual.screeps.user.js");' +
window.visualLoaded = true;' +
</script>')
Add visual.js to your screeps codebase
Add RawVisual.commit()
at the end of your main loop
Run loadVisual()
to load visuals (Note: This step will need to be repeated each time you load the steam client or browser tab)
Profit!
visual.js implements nearly all of the canvas context API MDN
t Visual = require('visual')
ctx = new Visual('E0N0')
fillRect(1,1,1,1)
commit() // Commit this renderqueue, will NOT save until RawVisual.commit() is called
Example function to render creep paths.
tion visualizePaths(){
t Visual = require('visual')
t colors = []
t COLOR_BLACK = colors.push('#000000') - 1
t COLOR_PATH = colors.push('rgba(255,255,255,0.5)') - 1
each(Game.rooms,(room,name)=>{
let visual = new Visual(name)
visual.defineColors(colors)
visual.setLineWidth = 0.5
_.each(Game.creeps,creep=>{
if(creep.room != room) return
let mem = creep.memory
if(mem._move){
let path = Room.deserializePath(mem._move.path)
if(path.length){
visual.drawLine(path.map(p=>([p.x,p.y])),COLOR_PATH,{ lineWidth: 0.1 })
}
}
})
visual.commit()