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

@iyio/liirn-mini-games

v0.0.3

Published

The Liirn Mini Games interface (LMI) is a small package that allows mini-games hosted in a webview to communicate with the Liirn app.

Downloads

2

Readme

Liirn Mini Games interface

The Liirn Mini Games interface (LMI) is a small package that allows mini-games hosted in a webview to communicate with the Liirn app.

Install

You can install the package in 1 of 2 ways, npm or a script tag

npm

npm install @iyio/liirn-mini-games

Script tag

<body>
    ...
    <!-- include liirn-mini-game.js before your own game script -->
    <script src="https://liirn-mini-games.web.app/liirn-mini-games-script/liirn-mini-games.js"></script>
    <script src="path/to/your-game-script.js"></script>
</body>

Examplpe Usage

Below is an example of a game where a player searches for dinosaurs and gets 5 points for finding a dinosaur a points for completing a level. The game can run either inside the Liirn app or standalone in a browser. The state of the game such as points and current level is stored in the memory of the game and points are are synchornized by sending an add points message to the host app.


// Using ES modules - Installed using npm
import {
    addMiniGameMessageListener,
    isInMiniGameWebView,
    sendMiniGameMessage
} from "@iyio/liirn-mini-games";

// Using global varialbe - Installed using a script tag
const {
    addMiniGameMessageListener,
    isInMiniGameWebView,
    sendMiniGameMessage
} = LiirnMiniGames;





let gameState='loading';
let points=0;

function loadGame()
{
    if(isInMiniGameWebView){
        // The game is running in the Liirn app

        // Request game data from the host app
        sendMiniGameMessage({
            type:'host:getGame',
            name:'dinosaur-finder'
        })

    }else{
        // The game is not running in the Liirn app. Most likely you are testing 
        // the game in a browser
        setLevels(getTestLevels());
        startGame();
    }
}

const stopListening=addMiniGameMessageListener(msg=>{
    switch(msg.type){

        case 'client:game':
            // msg.game?.data should contain levels for your game, 
            // but if not fallback to using test levels.
            setLevels(msg.game?.data || getTestLevels());
            startGame();
            break;

    }
})

function setLevels(levels:GameLevel[])
{
    // store levels somewhere
}

function startGame()
{
    // Ready, Set, Go - 🕹 🎮 🎱
    gameState='playing';
    requestAnimationFrame(gameLoop);
}

function gameLoop()
{
    
    ....

    switch(action){

        case 'found-dinosaur':
            addPoints(5);
            break;

        case 'completed-level':
            addPoints(currentLevel.points)
            break;
    }

    ....

    if(gameState==='playing'){
        requestAnimationFrame(gameLoop);
    }
}

function addPoints(p:number)
{
    points+=p;
    sendMiniGameMessage({
        type:'host:addPoints',
        points:currentLevel.points
    })
}

function endGame()
{
    gameState='end';
    stopListening();
    sendMiniGameMessage({
        type:'host:exit'
    })
}


loadGame();

Messages Structure


/**
 * Message structure
 */
export interface MiniGameMessage
{
    /**
     * Indicates the message is a mini game message
     */
    isMiniGameMessage:true;

    /**
     * message type
     */
    type:MessageType;

    /**
     * points to add to the players score
     */
    points?:number;

    /**
     * Game data sent as a respone to the host:getGame message.
     */
    game?:MiniGame;

    /**
     * Generic name prop
     */
    name?:string;
}


/**
 * Defines the different messages passed between the host app and client game
 */
export type MessageType=(
    'host:getGame'|
    'host:addPoints'|
    'host:exit'|
    'host:levelComplete'|
    'client:nextLevel'|
    'client:game'
);

Message Types

| Type | Props | Description | |--------------------|--------------------------------|---------------------------------------------------| | host:getGame | name: Name of the game | Request the host to send game data | | host:addPoints | ponts: number of points to add | Adds points to the players score | | host:exit | | Tells the host to unload the game | | host:levelComplete | | Tells the host the player has completed a level | | client:nextLevel | | Informs the client game to move to the next level | | client:game | game: Game data | Returns game data to the client game |