Skip to main content

A hybrid UI framework and editor and logic for Pygame (Educational Purpose)

Project description

pyui_dl v1.0.0

Pygame用のUIフレームワーク。ビジュアルエディタでレイアウトを組み、ロジックエディタでイベント駆動のルールを定義し、ランタイムでゲームに組み込めます。

操作方法は EDITOR_OPERATIONS.md を参照してください。


セットアップ

pip install -e .

#or
pip install git+https://github.com/RentoCoder-KOSIN/PygameUI_Editor

起動

# エディタ(幅・高さは省略可)
pyui <ファイル名> <幅> <高さ>

# 例
pyui coin_catch 450 700

data/<ファイル名>.jsondata/logic_<ファイル名>.json が自動で読み書きされます。ファイルが存在しない場合は新規作成されます。


ファイル構成

data/
  coin_catch.json            ← UIデザイン(エディタで編集)
  logic_coin_catch.json      ← ロジック定義(エディタで編集)

coin_catch_game.py           ← サンプルゲーム本体

pyui_dl/
  ui/
    widget.py      ← Widgetベースクラス・当たり判定ヘルパー
    button.py      ← Button
    image.py       ← Image
    shapes.py      ← Circle
    layout.py      ← VBox / HBox / AbsoluteLayout
  logic/
    models.py      ← データ構造(イベント・アクション定義)
    serializer.py  ← JSON保存/読み込み
    editor.py      ← ロジックエディタUI
    runtime.py     ← ゲーム組み込み用ランタイム
  editor/
    selector.py    ← デザインエディタUI
  utils/
    serializer.py  ← UIのJSON保存/読み込み
    collision.py   ← 当たり判定ユーティリティ

ゲームへの組み込み方

from pyui_dl.logic.runtime import LogicRuntime
from pyui_dl.logic.serializer import LogicSerializer
from pyui_dl.utils.serializer import Serializer

# ロード
ui_root = Serializer.load_file("data/my_game.json")
logic   = LogicSerializer.load_file("data/logic_my_game.json")
runtime = LogicRuntime(logic, ui_root)

# 毎フレーム(タイマーイベント更新)
runtime.tick(dt)

# イベント発火
runtime.fire("on_click",   "btn_start")
runtime.fire("on_collide", "player", with_tag="enemy")

# 変数の読み書き
hp = runtime.get("hp", default=100)
runtime.set("hp", hp - 10)

# カスタムアクションへの対応(change_scene / play_anim など)
def on_change_scene(act, source, rt):
    load_scene(act["scene"])

runtime.on_action("change_scene", on_change_scene)

ロジックJSON の構造

{
  "global_vars": {
    "hp": 100,
    "score": 0
  },
  "widget_rules": {
    "player": [
      {
        "id": "abc123",
        "label": "ダメージ処理",
        "event": { "type": "on_collide", "with_tag": "enemy" },
        "conditions": [
          { "var": "hp", "op": ">", "value": 0 }
        ],
        "actions": [
          { "type": "set_var",   "var": "hp", "op": "-=", "value": 10 },
          { "type": "play_anim", "target": "player", "anim": "hurt" }
        ]
      }
    ]
  }
}

イベント一覧

イベント パラメータ 説明
on_click クリック
on_collide with_tag 指定タグのWidgetと衝突
on_enter area エリアに進入
on_exit area エリアから退出
on_var_change var 変数が変化
on_timer delay 指定秒ごとに発火
on_game_start ゲーム開始時
on_state_enter state 指定ステートに突入

アクション一覧

アクション パラメータ 説明
set_var var, op, value 変数操作(= += -= *= /=
set_visible target, visible Widgetの表示/非表示
move_to target, x, y 絶対座標へ移動
move_by target, dx, dy 相対移動
play_anim target, anim アニメ再生(要コールバック)
change_scene scene シーン遷移(要コールバック)
spawn template, x, y Widgetを生成(要コールバック)
destroy target Widgetを削除
set_state target, state ステート変更(要コールバック)
play_sound sound 効果音再生(要コールバック)
emit_event event, target 別のイベントを発火

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyui_dl-1.0.0.tar.gz (17.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyui_dl-1.0.0-py3-none-any.whl (17.1 MB view details)

Uploaded Python 3

File details

Details for the file pyui_dl-1.0.0.tar.gz.

File metadata

  • Download URL: pyui_dl-1.0.0.tar.gz
  • Upload date:
  • Size: 17.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pyui_dl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d31a0183791374c4ced4996363055ff94902f91c7cf514656ae29bc4f186175e
MD5 55565ef93fb974f24715c5b958ae1024
BLAKE2b-256 c3ed47db1f2a36dd8a2e5a0f5ecb7870942bf7d9b8f02b7991affb5a523e3d49

See more details on using hashes here.

File details

Details for the file pyui_dl-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyui_dl-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pyui_dl-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5f507e1b1900ca4a8d88c48525117bff5e1c348b7e0ed59bf1be0d8281aee6
MD5 635db9e703679aad12020812b63c43e9
BLAKE2b-256 ccb81c43b130b7a9e0de4aee9bb20d743ca304d8087256c684e4e095a2bb2625

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page