screepers/screeps-visual

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Adds a few useful variable wrappers to conole.

Installation

Extension (Browser Only)
  1. Install greasemonkey or tampermonkey
  2. Click here
  3. Click install on the resulting screen
  4. Add visual.js to your screeps codebase
  5. Add RawVisual.commit() at the end of your main loop
  6. Refresh screeps
  7. Profit! (Note: Nothing will render until your code tells it to, See Usage below)
Manually (Browser + Steam Client)
  1. Add 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>')
    
    
  2. Add visual.js to your screeps codebase

  3. Add RawVisual.commit() at the end of your main loop

  4. Run loadVisual() to load visuals (Note: This step will need to be repeated each time you load the steam client or browser tab)

  5. Profit!

Usage

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()



This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.