Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fantasy-time-crunch

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fantasy-time-crunch

A way of handling time and time-related state changes in a highly customizable way, for use with games and virtual worlds

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fantasy-time-crunch

I needed a way of handling a made-up time system in a game, so I made this.

Sample Configuration

const time = {
  // One and only one unit is the smallest measured subdivision of time, defined as a 'tick'
  second: {
    tick: true,
    makes: {minute: 60},
  },

  // Larger units are defined by how many of a smaller unit they are subdivided into
  minute: {
    makes: {hour: 60},
  },

  // Optionally one can define a function to be called when
  // a unit increments (having a bell toll, etc.)
  hour: {
    makes: {day: 24},
    onIncrement() {
      console.log('BING!');
      console.log('Hour: ', this.time.hour);
    },
    // Units can be divided into multiple state changes. For example, a day has two or more states defined
    // by how many hours have passed.
    // 'states' can be an object or a function.
    // In this case, dawn and dusk are different depending
    // on the season
    states() {
      if (this.states.is('winter')) {
        return {
          day: 9, // 0900 -- by default this number represents hours. however, each property returned can also be a function that has access to any time unit.
          night: 20, // 2000
        };
      }
      return {
        day: 6, // 0900
        night: 23, // 2200
      };
    }
  },


  day: {
    makes() {
      const days = this.time.month % 2 ? 31 : 30;
      return {month: days};
    },
    onIncrement() {
      const names = 'MTWHFSU';
      console.log('Day:', names[this.time.day - 1]);
    },
  },
  month: {
    // The 'of' property can also be a function called
    // In this case, even months have 30 days and odd have 31.
    makes: { year: 12},

    // For simpler state changes, an object marking the
    // transitional thresholds is fine.
    states: {
      winter: 11,
      spring: 3,
      summer: 5,
      fall: 9
    }
  }
};

Keywords

FAQs

Package last updated on 27 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc