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

masoria-parser

v1.0.1

Published

A novel syntax parser built in typescript!

Downloads

8

Readme

Masoria Visual Novel Parser

A vanilla parser that I made for my visual novel project, Masoria. It's not very good, but it works for my purposes. I'm not planning on updating it, but I'm releasing it in case anyone wants to use it for their own projects.

⚠️ Warning: Masoria Language is recursive. Declare things from top to bottom.

Installation

npm i masoria-lang

Summary

Implementation

import parser from "masoria-parser";
import { readFileSync, writeFileSync } from "fs";

const fileName = "tutorial";

const readScript = readFileSync(`scripts/${fileName}.masoria`, "utf-8");
const result = parser(readScript);

writeFileSync(`output/${fileName}.json`, JSON.stringify(result));

Features

Arrow Pointer

By default, the next scene reference is always the following one (except if they contain choices inside them). You can overwrite this by using the arrow pointer ->, which will label the next scene of the current scene with the name you provide after the arrow pointer.

scene sceneName -> sceneName2:

Character Declaration

You have to declare characters on the top of the file, and save their emotions to the variable, so they can be referenced afterwards.

character alice:
    emotion frowning: data/Characters/Alice/AliceFrowning.png
    emotion smiling: data/Characters/Alice/AliceSmiling.png
    emotion blushing: data/Characters/Alice/AliceBlushing.png
    emotion waving: data/Characters/Alice/AliceWaving.png
    emotion sad: data/Characters/Alice/AliceSad.png
    emotion bookShy: data/Characters/Alice/AliceBookShy.png
    emotion bookSad: data/Characters/Alice/AliceBookSad.png

Dynamic Emotions and Dialogues

You can declare the emotion to be used on the next dialogues. If no other emotion is declared in the scene, all the other dialogues inherit the declared one. This works recursively.

use emotion alice frowning
|---------| |--|  |------|
 keyword character emotion

Scenes with Javascript Conditions

Regular scenes can have names between < and > to reference javascript conditions that must be executed BEFORE the scene changes.

scene sceneName<condition>:

Keywords

⚠️ Keep reading for syntax examples.

choice: Must be used inside a scene. Appends the choice to an array in the output. use emotion: Must be used inside a scene. Use an emotion in the current scene. ending scene: Defines an ending scene. Program should close after this. character: Declares a character. emotion: Declare an emotion inside a character declaration block.

Syntax Examples

character characterName:
    emotion emotionName1: path/to/file.png
    emotion emotionName2: path/to/file2.png

scene sceneName<optionalCondition>:
    use emotion characterName emotionName1

    [characterName]: characterSpeech

scene sceneName2:
    use emotion characterName emotionName1

    [characterName]: characterSpeech

    choice<sceneName3>: promptText
    choice<sceneName4>: promptText

ending scene sceneName3:
    use emotion characterName emotionName1

    [characterName]: characterSpeech

    use emotion characterName emotionName2

    [characterName]: characterSpeech

scene sceneName4:
    use emotion characterName emotionName2

    [characterName]: characterSpeech

Package Output

This is the expected result if syntax is followed correctly.

{
  "scenes": [
    {
      "label": "sceneName",
      "isEndingScene": false,
      "condition": "optionalCondition",
      "dialogues": [
        {
          "character": "characterName",
          "emotion": "emotionName1",
          "text": ["characterSpeech"]
        }
      ],
      "nextScene": "sceneName2"
    },
    {
      "label": "sceneName2",
      "isEndingScene": false,
      "dialogues": [
        {
          "character": "characterName",
          "emotion": "emotionName1",
          "text": ["characterSpeech"]
        }
      ],
      "previousScene": "sceneName",
      "choices": [
        {
          "label": "promptText",
          "targetScene": "sceneName3"
        },
        {
          "label": "promptText",
          "targetScene": "sceneName4"
        }
      ]
    },
    {
      "label": "sceneName3",
      "isEndingScene": true,
      "dialogues": [
        {
          "character": "characterName",
          "emotion": "emotionName1",
          "text": ["characterSpeech"]
        },
        {
          "character": "characterName",
          "emotion": "emotionName2",
          "text": ["characterSpeech"]
        }
      ],
      "nextScene": "sceneName4",
      "previousScene": "sceneName2"
    },
    {
      "label": "sceneName4",
      "isEndingScene": false,
      "dialogues": [
        {
          "character": "characterName",
          "emotion": "emotionName2",
          "text": ["characterSpeech"]
        }
      ],
      "previousScene": "sceneName2"
    }
  ],
  "characters": [
    {
      "name": "characterName",
      "emotions": {
        "emotionName1": "path/to/file.png",
        "emotionName2": "path/to/file2.png"
      }
    }
  ]
}