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

@medieval/sword

v2.0.7

Published

- **Interfaces and Types**: - Defines entities, events, lifecycle hooks, and types that modify properties (`With`, `Without`) and perform operations on entities. - Lifecycle and update hooks manage entity lifecycle and system updates. - **Core Functio

Downloads

183

Readme

  • Interfaces and Types:
    • Defines entities, events, lifecycle hooks, and types that modify properties (With, Without) and perform operations on entities.
    • Lifecycle and update hooks manage entity lifecycle and system updates.
  • Core Functionality: Implements event-driven mechanisms for managing entities, possibly through query and update hooks, which are typical in ECS patterns.

I'll create a README with sections explaining how to use this file, its features, and necessary dependencies. I'll also include emojis to add clarity and friendliness to each section.


README

# 🏰 Medieval ECS TypeScript Library

A TypeScript library implementing an **Entity-Component-System (ECS)** architecture, ideal for game development or simulations where entities require flexible and reusable components. 

## 📋 Table of Contents
- [Introduction](#introduction)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Types & Interfaces](#types--interfaces)
- [Hooks & Events](#hooks--events)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)

## ✨ Introduction

This library provides a streamlined way to manage entities in a game or simulation, using a modular ECS pattern. With **lifecycle hooks** and **event-driven updates**, entities can interact, update, and respond to game-state changes efficiently.

## 🌟 Features
- **Entity Management**: Easily create and manage entities with flexible attributes.
- **Lifecycle Hooks**: Control entities through customizable hooks that respond to lifecycle events.
- **Event System**: Manage events between entities, allowing complex interactions.
- **Type Utilities**: Use helper types like `With` and `Without` to simplify entity property management.

## ⚙️ Installation

Install the necessary packages using npm:

```bash
npm install @medieval/martingale

Then, add this library to your project.

🚀 Usage

  1. Define Entities: Create entities with required attributes.
  2. Setup Hooks: Use lifecycle and update hooks to manage entity behavior.
  3. Emit Events: Utilize event callbacks to allow entities to interact in response to game updates.

📖 Types & Interfaces

  • Entity: Basic unit with flexible attributes.
  • With: Utility type to mark specified entity properties as required.
  • Without: Utility type to omit specific properties.
  • LifecycleHook: A function type for lifecycle event handling on entities.
  • UpdateHook: A function type that runs on each update tick.
  • EntityEvent: Event object associated with an entity.
  • QueryEvent: Event object for querying multiple entities.

🔄 Hooks & Events

The library includes the following hooks and events:

  • LifecycleHook: Operates on entities, handling initialization, updates, and destruction.
  • UpdateHook: Runs every update cycle (e.g., on every game frame).
  • EventCallback: Responds to data-based events.

Example Hook

const onEntityCreate: LifecycleHook<MyEntity> = (entity) => {
  console.log(`Entity created: ${entity}`);
};

Event Usage

const onPlayerAttack: EventCallback<AttackEvent> = (eventData) => {
  console.log(`Player attacked with power: ${eventData.power}`);
};

📝 Examples

Check out the examples below to start integrating this ECS library into your project:

import { Entity, With, Without, LifecycleHook, UpdateHook } from './ecs';

// Define a new entity
interface Player extends Entity {
  health: number;
  power: number;
}

// Create lifecycle hooks
const onPlayerSpawn: LifecycleHook<Player> = (player) => {
  player.health = 100;
  console.log("Player spawned with full health.");
};

// Update hook
const gameTick: UpdateHook = (deltaTime) => {
  console.log(`Game tick: ${deltaTime}`);
};

🤝 Contributing

Contributions are welcome! If you’d like to improve this library, please fork the repository, make changes, and submit a pull request.

📄 License

This project is licensed under the MIT License.