-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate project from private repo (#7)
* add osrlib, osrgame and pyproject.toml files * migrate from public repo * status update + fix Py version * terminate bullets
- Loading branch information
Showing
36 changed files
with
5,956 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,4 @@ cython_debug/ | |
|
||
# Miscellaneous | ||
.DS_Store | ||
test_db.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# osrgame: Textual TUI for an OSR-style turn-based RPG | ||
|
||
The `osrgame` package provides user interface for the OSR Console application--it's the thing you run to play the game. | ||
|
||
## Prerequisites | ||
|
||
- Python 3.11+ | ||
- Poetry 1.6+ | ||
|
||
## Installation | ||
|
||
Install the application's dependencies and its virtual environment by using Poetry. This command will create a Python virtual environment and install `osrlib` and other dependencies for you. | ||
|
||
```sh | ||
# Run from within the <repo-root>/osrgame directory | ||
poetry install | ||
``` | ||
|
||
## Usage | ||
|
||
Launch the OSR Console game application by using Poetry: | ||
|
||
```sh | ||
# Run from within the <repo-root>/osrgame directory (same dir as install command) | ||
poetry run python ./osrgame/osrgame.py | ||
``` | ||
|
||
By starting the game with `poetry run`, you don't have to worry about manually entering a virtual environment because Poetry handles it for you. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .osrgame import OSRConsole | ||
from .screen import CharacterScreen, WelcomeScreen, ModuleScreen, ExploreScreen | ||
from .widgets import CharacterScreenButtons, CharacterStats, AbilityTable, ItemTable, SavingThrows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from textual.app import App, ComposeResult | ||
|
||
from osrlib import CharacterClassType, PlayerCharacter, Armor, Item, Weapon | ||
from screen import CharacterScreen, WelcomeScreen | ||
|
||
|
||
class OSRConsole(App): | ||
CSS_PATH = "screen.tcss" | ||
|
||
BINDINGS = [ | ||
("c", "character", "Character"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
player_character = PlayerCharacter( | ||
"Sckricko", CharacterClassType.FIGHTER | ||
) | ||
armor = Armor("Chain Mail", -5, usable_by_classes = {CharacterClassType.FIGHTER}, max_equipped = 2, gp_value = 40) | ||
shield = Armor("Shield", -1, usable_by_classes = {CharacterClassType.FIGHTER}, max_equipped = 2, gp_value = 10) | ||
sword = Weapon("Sword", "1d8", usable_by_classes = {CharacterClassType.FIGHTER}, max_equipped = 1, gp_value = 10) | ||
player_character.add_item_to_inventory(armor) | ||
player_character.add_item_to_inventory(shield) | ||
player_character.add_item_to_inventory(sword) | ||
player_character.inventory.equip_item(armor) | ||
player_character.inventory.equip_item(shield) | ||
player_character.inventory.equip_item(sword) | ||
|
||
backpack = Item("Backpack", gp_value = 5) | ||
wineskin = Item("Wineskin", gp_value = 1) | ||
iron_rations = Item("Iron Rations", gp_value = 15) | ||
torch = Item("Torch", gp_value = 1) | ||
player_character.add_item_to_inventory(backpack) | ||
player_character.add_item_to_inventory(wineskin) | ||
player_character.add_item_to_inventory(iron_rations) | ||
player_character.add_item_to_inventory(torch) | ||
|
||
SCREENS = {"scr_character": CharacterScreen()} | ||
|
||
def compose(self) -> ComposeResult: | ||
yield WelcomeScreen() | ||
|
||
def on_mount(self) -> None: | ||
self.title = "OSR Console" | ||
self.sub_title = "Adventures in turn-based text" | ||
|
||
def action_character(self) -> None: | ||
"""Show the character screen.""" | ||
self.push_screen("scr_character") | ||
|
||
def action_quit(self) -> None: | ||
"""Quit the application.""" | ||
self.exit() | ||
|
||
|
||
app = OSRConsole() | ||
if __name__ == "__main__": | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
from textual.app import ComposeResult | ||
from textual.containers import Container | ||
from textual.screen import Screen | ||
from textual.widgets import Button, Header, Footer, Log, Placeholder | ||
|
||
from osrlib import CharacterClassType, Armor, Weapon | ||
from widgets import CharacterStats, AbilityTable, ItemTable, SavingThrows, CharacterScreenButtons | ||
|
||
|
||
#################### | ||
# Welcome Screen | ||
class WelcomeScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
|
||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() | ||
|
||
|
||
#################### | ||
# Main Screen | ||
class MainScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
yield Placeholder("Main") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() | ||
|
||
|
||
#################### | ||
# Character Screen | ||
|
||
|
||
class CharacterScreen(Screen): | ||
BINDINGS = [ | ||
("k", "clear_log", "Clear log"), | ||
("escape", "app.pop_screen", "Pop screen"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(id="header", show_clock=True, classes="header-footer") | ||
yield CharacterStats(id="stat-block", classes="box") | ||
yield Log(id="log", auto_scroll=True, classes="box") | ||
yield AbilityTable(id="ability-block") | ||
yield SavingThrows(id="saving-throw-block") | ||
yield ItemTable(id="item-block", classes="box") | ||
yield CharacterScreenButtons(id="char-buttons", classes="char-buttons-class") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
"""Perform actions when the widget is mounted.""" | ||
self.query_one(Log).border_subtitle = "LOG" | ||
self.query_one(CharacterStats).pc_name = self.app.player_character.name | ||
self.query_one(CharacterStats).pc_class = self.app.player_character.character_class | ||
self.query_one(CharacterStats).pc_level = self.app.player_character.character_class.current_level | ||
self.query_one(CharacterStats).pc_hp = self.app.player_character.character_class.hp | ||
self.query_one(CharacterStats).pc_ac = self.app.player_character.armor_class | ||
self.query_one(AbilityTable).update_table() | ||
self.query_one(SavingThrows).update_table() | ||
self.query_one(ItemTable).items = self.app.player_character.inventory.all_items | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pc = self.app.player_character | ||
if event.button.id == "btn_roll_abilities": | ||
self.reroll() | ||
self.query_one(CharacterStats).pc_ac = pc.armor_class | ||
|
||
elif event.button.id == "btn_roll_hp": | ||
hp_roll = pc.roll_hp() | ||
pc.character_class.hp = max(hp_roll.total_with_modifier, 1) | ||
roll_string = hp_roll.pretty_print() | ||
self.query_one(Log).write_line(roll_string) | ||
self.query_one(CharacterStats).pc_hp = pc.character_class.hp | ||
|
||
def action_clear_log(self) -> None: | ||
"""An action to clear the log.""" | ||
self.query_one(Log).clear() | ||
|
||
def reroll(self): | ||
"""Rolls the ability scores of the active character.""" | ||
self.app.player_character.roll_abilities() | ||
self.query_one(AbilityTable).update_table() | ||
|
||
|
||
#################### | ||
# Party Screen | ||
class PartyScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
yield Placeholder("Party Manager") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() | ||
|
||
|
||
#################### | ||
# Module Screen | ||
class ModuleScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
yield Placeholder("Module Manager") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() | ||
|
||
|
||
#################### | ||
# Explore Screen | ||
class ExploreScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
yield Placeholder("Explore") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() | ||
|
||
|
||
#################### | ||
# Combat Screen | ||
class CombatScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
yield Placeholder("Adventure") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() | ||
|
||
|
||
#################### | ||
# Exit Screen | ||
class ExitScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "app.pop_screen", "Pop screen"), | ||
("q", "quit", "Quit"), | ||
] | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header(show_clock=True, id="header") | ||
yield Placeholder("Goodbye") | ||
yield Footer() | ||
|
||
def on_mount(self) -> None: | ||
pass | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
pass | ||
|
||
def action_quit(self) -> None: | ||
"""An action to quit the application.""" | ||
self.exit() |
Oops, something went wrong.