screeps-local-visuals

Crates.ioscreeps-local-visuals
lib.rsscreeps-local-visuals
version0.1.2
sourcesrc
created_at2024-03-03 20:37:29.526125
updated_at2024-07-29 03:23:39.806077
descriptionA library for the programmable MMO Screeps that allows tools to produce images of game data without relying on the game engine for rendering
homepage
repositoryhttps://github.com/jciskey/screeps-local-visuals
max_upload_size
id1160884
size2,302,589
Joe Ciskey (jciskey)

documentation

README

Screeps Local Visuals

This library provides helper methods for creating room images for the programmable MMO Screeps, without relying on the in-game renderer.

Example Usage

The following example code produces an image simple.png that represents an empty room with an Extension, a Source, a Catalyst Mineral, a Swamp, and 3 Walls.

use screeps_local_visuals::render;
use render::{ Terrain, Resource, BuildableStructure, OutputImage, DEFAULT_ROOM_MAX_ROWS, DEFAULT_ROOM_MAX_COLUMNS };


fn main()   {
  make_map_image("simple.png");
}


fn make_map_image(filename: &str) {

  let mut imgbuf = render::create_image();

  draw_terrain(&mut imgbuf);

  draw_test_terrain(&mut imgbuf);
  draw_test_resource(&mut imgbuf);
  draw_test_structure(&mut imgbuf);

  render::draw_grid(&mut imgbuf);

  imgbuf.save(filename).unwrap();
}

fn draw_terrain(imgbuf: &mut OutputImage) {
  for col in 0..DEFAULT_ROOM_MAX_COLUMNS {
    for row in 0..DEFAULT_ROOM_MAX_ROWS {
      render::draw_terrain_tile_xy(imgbuf, col, row, &Terrain::Plain);
    }
  }
}

fn draw_test_terrain(imgbuf: &mut OutputImage)  {
  render::draw_terrain_tile_xy(imgbuf, 20, 20, &Terrain::Swamp);
  render::draw_terrain_tile_xy(imgbuf, 21, 20, &Terrain::Wall);
  render::draw_terrain_tile_xy(imgbuf, 21, 21, &Terrain::Wall);
  render::draw_terrain_tile_xy(imgbuf, 20, 21, &Terrain::Wall);
}

fn draw_test_resource(imgbuf: &mut OutputImage)  {
  render::draw_resource_tile_xy(imgbuf, 10, 20, &Resource::Source);
  render::draw_resource_tile_xy(imgbuf, 20, 10, &Resource::Catalyst);
}

fn draw_test_structure(imgbuf: &mut OutputImage)  {
  render::draw_buildablestructure_tile_xy(imgbuf, 10, 10, &BuildableStructure::Extension);
}
Commit count: 13

cargo fmt