Skip to content

Commit 34cb1f9

Browse files
committed
Add helpers for RPG data serialization and markdown processing
1 parent ec3a350 commit 34cb1f9

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

engine/rpg/markdown_helper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Markdown Helper for RPG Data (Obsidian integration)
3+
"""
4+
import re
5+
6+
def extract_code_blocks(md_text, block_type='yaml'):
7+
pattern = rf'```{block_type}([\s\S]+?)```'
8+
return re.findall(pattern, md_text)
9+
10+
# Example: extract YAML blocks from Obsidian markdown
11+
# blocks = extract_code_blocks(md_content, 'yaml')

engine/rpg/serialization_helper.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Serialization Helper for RPG Data
3+
"""
4+
import yaml
5+
import json
6+
7+
def save_yaml_data(data, filepath):
8+
with open(filepath, 'w', encoding='utf-8') as f:
9+
yaml.safe_dump(data, f)
10+
11+
def save_json_data(data, filepath):
12+
with open(filepath, 'w', encoding='utf-8') as f:
13+
json.dump(data, f, indent=2)

engine/rpg/status_effects.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Status Effects for RPG Characters and NPCs
3+
"""
4+
class StatusEffect:
5+
def __init__(self, name, description, duration=None, effect=None):
6+
self.name = name
7+
self.description = description
8+
self.duration = duration # in turns or None for permanent
9+
self.effect = effect or {}
10+
11+
def __repr__(self):
12+
return f"<StatusEffect {self.name} ({self.duration})>"
13+
14+
class StatusManager:
15+
def __init__(self):
16+
self.effects = []
17+
18+
def add_effect(self, name, description, duration=None, effect=None):
19+
eff = StatusEffect(name, description, duration, effect)
20+
self.effects.append(eff)
21+
return eff
22+
23+
def get_effect(self, name):
24+
for eff in self.effects:
25+
if eff.name == name:
26+
return eff
27+
return None
28+
29+
def list_effects(self):
30+
return self.effects

engine/rpg/yaml_loader.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
YAML Loader for RPG Data (Characters, Items, Spells, Quests, Campaigns)
3+
"""
4+
import yaml
5+
import os
6+
7+
def load_yaml_data(filepath):
8+
with open(filepath, 'r', encoding='utf-8') as f:
9+
return yaml.safe_load(f)
10+
11+
# Example: load character data from YAML
12+
# data = load_yaml_data('game/characters.yaml')

0 commit comments

Comments
 (0)