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

declick-engine

v0.9.2

Published

Declick Engine

Downloads

386

Readme

Declick Engine

Declick Engine is a javascript interpreter and runtime environment that can be used with graphical and non-graphical objects. Object names and methods are fully internationalized, as well as runtime environemnt itself. Graphical objects are rendered using Phaser library. Declick Engine has been built primarily as an educational tool to teach children how to code and allow them to easily create small graphical games.

Demonstration

A demonstration page is available here: https://colombbus.gitlab.io/declick-engine/

How to build

install dependencies

npm install

build library

npm run build

Generated library is located in dist directory. Currently two versions are generated:

  • declick-engine.js, CommonJS library
  • declick-engine-esm.js ES module (no size optimization)

demo

When library is built, a demo web page is generated at demo/dist/index.html

Documentation

Objects (Work in progress)

Documentation in English

Documentation en français

Sprites and maps

How to add objects

Internationalization

Classes names and exposed methods are internationalized, using two tools:

These tools make it really easy to define a translated name for a class or a method:

import 'reflect-metadata'

@Reflect.metadata('translated', 'MyClass')
class MyClass {
  @Reflect.metadata('translated', 'exposedMethod')
  @Reflect.metadata('help', 'exposedMethod_help')
  exposedMethod(value) {
    this._value = value
  }
}

For internationalization of exposedMethod, two parameters are defined:

  • i18._(exposedMethod) is the translated name
  • i18n._(exposedMethod_help) is the help text that will be used for this method

Translation texts are stored in json files within directory translations.

Note: in Visual Studio Code, the use of i18n ally extension makes it really easy to manage translation texts.

Adding a basic class

Classes are stored in directory src/objects/classes. A basic class should derive from BaseClass:

import 'reflect-metadata'

class MyClass extends BaseClass {
    ...
}

export default MyClass

Adding a graphical class

Graphical classes are stored in directory src/objects/classes. They derive from GraphicClass:

import GraphicClass from '../graphic-class'

class MyGraphicClass extends GraphicClass {

  constructor() {
    super()
    this._object = // _object holds reference to the actual graphics object, handled by Phaser
  }

  static setup() {
    // this static method is called once at setup: it can be used e.g. to load some assets used by every instance
  }

  tick(delta) {
    // called by graphics framework, may be used to animate the instance
  }

  getX() {
    // should be implemented to give the X coordinate of the instance
  }

  getY() {
    // should be implemented to give the Y coordinate of the instance
  }

  setLocation(x, y) {
    // should be implemented to position the object
  }

}

Adding an instance

Instances are stored in directory src/objects/instances. An instance should derive from BaseInstance:

import BaseInstance from '../base-instance'

class MyInstance extends BaseInstance {}

export default MyInstance

Checking arguments of exposed methods

Since exposed metohds will be used from outside of Declick, there is a strong need for checking the type of provided arguments.To do so, Declick object may use @checkArguments as a decorator for the exposed method:

import { checkArguments } from '../utils/checks'

  @checkArguments(['integer'])
  myExposedMethod(value) {
    // value should be an integer, otherwise an error is thrown
    ...
  }

  @checkArguments(['integer', 'string'])
  myExposedMethod2(value1, value2) {
    // value1 should be an integer, value2 should by a string
    ...
  }

  @checkArguments(['integer', 'string', 'array'], 2)
  myExposedMethod3(value1, value2, value3) {
    // value1 should be an integer, value2 should by a string, value3 should by an array
    // the two last parameters are optional
    ...
  }

  @checkArguments(['integer', 'integer|string|boolean'])
  myExposedMethod4(value1, value2) {
    // value1 should be a en integer
    // value2 should be an integer OR a string OR a boolean
    ...
  }

Available types are: integer, string, array, number, boolean, object, function, canvas, any

Handling events

Classes and instances may manage events using the following methods:

  • this.addListener('eventName', function) adds a listener for event eventName
  • this.dispatch('eventName') dispatches event eventName

Dependencies

Declick Engine uses the following libs: