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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rpgja/rpgen-map

v1.1.7

Published

Library on map data for RPGEN.

Readme

rpgen-map

Library on map data for RPGEN.

RPGEN 規格に基づいた RPG マップテキストデータをパースし、
JavaScript/TypeScript で扱いやすいオブジェクトに変換するライブラリです。


概要 / Overview

rpgen-map は、RPGEN のマップテキストデータをプログラムで解釈可能な形に変換します。
歩行グラフィック(歩行グラ)やスプライト素材、マップに付随する各種情報も解析可能です。


リンク集

主な機能 / Features

  • RPGEN マップテキストデータのパース
  • 歩行グラ・スプライト素材の解釈
  • マップ関連の補助ユーティリティ
  • TypeScript 対応


使い方・パースの2段階処理 / Usage & Two-Stage Parsing

本ライブラリのパース処理は、マップ全体と個別コマンドの2段階構造になっています。

  1. 第1段階: マップ全体のパース (RPGMap.parse(mapText))

    • マップ全体のデータ(タイル、配置、イベントポイント等)を解析し、RPGMap オブジェクトを返します。
    • イベントフェイズ内のコマンドシーケンス (phase.sequence) は、テキストの相互変換(stringify)を可能にするため RawCommand オブジェクト(#name と未解釈の生文字列 #body)の配列として保持されます。
  2. 第2段階: コマンドの構造化パース (rawCommand.parse())

    • 各 RawCommand の .parse() メソッドを呼び出すことで、選択肢(#SEL)の入れ子構造や各種パラメータが解釈され、型付けされた抽象構文木 Command オブジェクト(SelectCommand, MessageCommand など)に変換されます。
import { RPGMap } from "@rpgja/rpgen-map";

// 第1段階: マップ全体のパース
const rpgMap = RPGMap.parse(mapText);

// イベントポイントとフェイズの取得
const eventPoint = rpgMap.eventPoints.get(5, 3);
const phase = eventPoint?.phases[0];

// 第2段階: RawCommand[] から構造化された Command[] へ変換
const structuredCommands = phase?.sequence.map((rawCmd) => rawCmd.parse());

パース結果のサンプル / Sample of parsing results

イベントポイント(#EPOINT)は、発動タイミング(tm)が自然言語の値にパースされます。 また #SEL は入れ子になった分岐構造もパース可能です(#SEL0-0 の中にさらに #SEL1-0 を含む例)。

入力(RPGENマップテキスト):

#EPOINT tx:5,ty:3,
#PH0 tm:1,
#MSG
m:この先には わなが あるようだ,
#ED
#SEL0-0 x:50,y:220,c:1,i0:しらべる,i1:やめておく,
#SEL1-0 c:0,i0:はい,i1:いいえ,
#MSG
m:わなを かいじょした!,
#ED
#SEL1-1
#MSG
m:なにも しなかった,
#ED
#SELEND1
#SEL0-1
#MSG
m:やめておいた,
#ED
#SELEND0
#PHEND0
#END

コード:

const rpgMap = RPGMap.parse(mapText);
const eventPoint = rpgMap.eventPoints.get(5, 3);
const primaryPhase = eventPoint.phases[0];
const commands = primaryPhase.sequence.map((c) => c.parse());

パース結果(timing が 1 ではなく "touch" になる点、#SEL が入れ子のまま choices 配列として表現される点に注目):

{
  "position": { "x": 5, "y": 3 },
  "timing": "touch",
  "sequence": [
    {
      "type": "MSG",
      "content": "この先には わなが あるようだ"
    },
    {
      "type": "SEL",
      "mode": "gui",
      "clearMessage": true,
      "choices": [
        {
          "label": "しらべる",
          "sequence": [
            {
              "type": "SEL",
              "mode": "random",
              "clearMessage": false,
              "choices": [
                {
                  "label": "はい",
                  "sequence": [
                    { "type": "MSG", "content": "わなを かいじょした!" }
                  ]
                },
                {
                  "label": "いいえ",
                  "sequence": [
                    { "type": "MSG", "content": "なにも しなかった" }
                  ]
                }
              ]
            }
          ]
        },
        {
          "label": "やめておく",
          "sequence": [
            { "type": "MSG", "content": "やめておいた" }
          ]
        }
      ],
      "displayPosition": { "x": 50, "y": 220 }
    }
  ]
}

mode は選択肢の動作モードを表します。

  • "gui" (SelectMode.GUI): x・y 座標が指定されており、その座標に選択肢のUIを表示します。
  • "random" (SelectMode.Random): x・y 座標が省略されており、ランダムに1つの選択肢が自動選択されます(選択UIは表示されません)。

timing の値は EventTiming.Confirm("confirm"、決定ボタンで発動)または EventTiming.Touch("touch"、接触で発動)のいずれかです。


ライセンス / License

  • MIT
    本プロジェクト全体には MIT ライセンスが適用されます。詳細は LICENSE をご覧ください。

コントリビュート / Contributing

バグ報告・機能提案・PR 大歓迎です。 Issue または Fork → PR にてご協力ください。