npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tom-konda/sc2ktojson

v0.0.4

Published

This JavaScript library converts from .sc2 (SC2K city file) or .scn (SC2K scenario file) file to JSON

Downloads

4

Readme

About

This JavaScript library converts from .sc2 (SC2K city file) or .scn (SC2K scenario file) file to JSON.

Support Browsers

  • Firefox, Google Chrome
  • MS Edge, Safari works probabry.

Usage

CLI

$ sc2ktojson [options] <inputFile>

Options

    -h, --help                 output usage information
    -V, --version              output the version number
    -o, --output <outputFile>  Output JSON file

Library

Browser (Legacy Style)

<!DOCTYPE html>
<html>
  <head>
    <title>Demo</title>
    <script src="../../lib/sc2ktojson.js"></script>
    <script>
      'use strict';
      let xhr = new win.XMLHttpRequest();
      const sc2fileURL = './sc2ktojsonTest.sc2';

      xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
          let cityData = sc2ktojson.analyze(xhr.response);
        }
      }

      xhr.open('GET', sc2fileURL);
      xhr.responseType = 'arraybuffer';
      xhr.send();
    </script>
  </head>
</html>

Browser (ES Modules)

<!DOCTYPE html>
<html>
<head>
  <script type="module">
    import sc2ktojson from './sc2ktojson.js';
    
    fetch('./sc2ktojsonTest.sc2')
    .then(
      (result) => {
        return result.arrayBuffer();
      }
    ).then(
      (buffer) => {
        const cityData = sc2ktojson.analyze(buffer);
      }
    );
  </script>
</head>
</html>

Web worker

importScripts('../../lib/sc2ktojson.js');

self.addEventListener(
    'message',
    function(event){
        let cityData = event.data;
        self.postMessage(self.sc2ktojson.analyze(cityData));
        self.close();
    },
    false
);

Node.js

const sc2ktojson = require('../../sc2ktojson');

let file = fs.readFileSync(`PATH_TO_SCNFILE/test.scn`);

// Convert from buffer to Uint8Array
let uint8arr = new Uint8Array(file);
let cityData = sc2ktojson.analyze(uint8arr.buffer);

Output Format

{
  scenario : {
    tmpl : [0-255, 0-255, ...], // optional, arbitrary items
    text : {
      opening : [0-255, 0-255, ...], // scenario opening text. arbitrary items
      selection : [0-255, 0-255, ...], // scenario selection text. arbitrary items
    },
    scen : {
      disaster : integer,
      disasterCoordinate : {
        x : integer,
        y : integer,
      },
      limit : integer,
      condPop : integer,
      condRPop : integer,
      condCPop : integer,
      condIPop : integer,
      condFund : integer,
      condVal : integer,
      condEdu : integer,
      condPol : integer,
      condCri : integer,
      condTra : integer,
      condBld1ID : integer,
      condBld2ID : integer,
      condBld1Tiles : integer,
      condBld2Tiles : integer,
    },
    pict : {
      width : integer,
      height : integer,
      picture : [
        [0-255, 0-255, ...], // same as width
      ], // same as height
    }
  }, // optional, .scn file only
  tile : {
    altm : [
      [
        {
          isWater : 0-1,
          height : 0-31,
          binaryText: string,
        }, ...
      ], // 128 items
    ], // 128 items
    xter : [
      [0-255, 0-255, ...], // 128 items
    ], // 128 items
    xbld : [
      [0-255, 0-255, ...], // 128 items
    ], // 128 items
    xzon : [
      [
        {
          zone: 0-15,
          binaryText: string,
        },
      ], // 128 items
    ], // 128 items,
    xund : [
      [0-255, 0-255, ...], // 128 items
    ], // 128 items
    xtxt : [
      [0-255, 0-255, ...], // 128 items
    ], // 128 items
    xbit : [
      [
        {
          isSalty : boolean,
          isWaterCovered : boolean,
          isWaterProvided : boolean,
          isPiped : boolean,
          isPowered : boolean,
          binaryText: string,
        }, ...
      ], // 128 items
    ], // 128 items
    surface : [
      [
        "xbld" | "xzon" | "xter", ... // 128 items
      ], // 128 items
    ],
  },
  statistic : {
    xtrf : 2x2AreaFormat, // Traffic map data
    xplt : 2x2AreaFormat, // Pollution map data
    xval : 2x2AreaFormat, // Value map data
    xcrm : 2x2AreaFormat, // Crime map data
    xplc : 4x4AreaFormat, // Police coverage map data
    xfir : 4x4AreaFormat, // Fire coverage map data
    xpop : 4x4AreaFormat, // Population density map data
    xrog : 4x4AreaFormat, // Rate of growth map data 
    xgrp : {
      citySize : GraphFormat,
      residents : GraphFormat,
      commerce : GraphFormat,
      industry : GraphFormat,
      traffic : GraphFormat,
      pollution : GraphFormat,
      value : GraphFormat,
      crime : GraphFormat,
      power : GraphFormat,
      water : GraphFormat,
      health : GraphFormat,
      education : GraphFormat,
      unemployment : GraphFormat,
      GNP : GraphFormat,
      nationalPop : GraphFormat,
      fedRate : GraphFormat,
    },
  }
  city : {
    cnam : [0-255, 0-255, ...], // 32 items
    misc : [
      [0-255, 0-255, ...], // 4 items
      [],
    ], // 1200 items
    xlab : [
      {
        length : integer,
        label: [0-255, 0-255, ...] // 24 items
      }
    ],
    xmic : [
      {
        tileNum : 0-255,
        microsim : [0-255, 0-255, ...] // 6 items
      }, ... // 150 items
    ],
    xthg : [0-255, 0-255, ...], // 480 items
  },
  fileSize : integer
}

2x2AreaFormat

[
  [0-255, 0-255, ...], // 64 items
], // 64 items

4x4AreaFormat

[
  [0-255, 0-255, ...], // 32 items
], // 32 items

GraphFormat

{
  year : [integer, integer, ...] // 12 items
  decade : [integer, integer, ...] // 20 items
  century : [integer, integer, ...] // 20 items
}

How to build

  1. Clone the repo from github git clone https://github.com/tom-konda/sc2ktojson.git
  2. Change current directory cd sc2ktojson
  3. Run npm install
  4. Run npm run build

License

Licensed under the MIT

Acknowledgement