Skip to content

Commit

Permalink
Add Book object
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler committed Oct 7, 2024
1 parent 9b91e6a commit d26509f
Show file tree
Hide file tree
Showing 20 changed files with 902 additions and 16 deletions.
9 changes: 9 additions & 0 deletions encyclopaedia/book/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""This file is used for documentation and testing.
Ren'Py has no use for it.
"""

from encyclopaedia.book.book_ren import Book


__all__ = ['Book']
65 changes: 65 additions & 0 deletions encyclopaedia/book/actions_ren.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import TYPE_CHECKING

import renpy.exports as renpy
from renpy.store import DictEquality
from renpy.ui import Action

if TYPE_CHECKING: # pragma: no cover
from .book_ren import Book

"""renpy
init -84 python:
"""

class BookAction(Action, DictEquality):
"""Base Action that requires a Book as an argument.
Should only be used for class inheritance.
Args:
book: The Book instance to use.
"""
def __init__(self, book: 'Book'):
self.book = book


class BookPreviousPage(BookAction):
"""Change the current sub-entry being viewed.
Used to switch from one page to another.
"""
def __call__(self) -> None:
"""Used by Ren'Py to invoke this Action."""
result = self.book.previous_page()

if result:
renpy.restart_interaction()

def get_sensitive(self) -> bool:
"""Determine if the button should be alive or not.
Return:
bool: True if the button should be alive, else False.
"""
return not (self.book._unlocked_page_index - 1) < 0


class BookNextPage(BookAction):
"""Change the current sub-entry being viewed.
Used to switch from one page to another.
"""
def __call__(self) -> None:
"""Used by Ren'Py to invoke this Action."""
result = self.book.next_page()

if result:
renpy.restart_interaction()

def get_sensitive(self) -> bool:
"""Determine if the button should be alive or not.
Return:
bool: True if the button should be alive, else False.
"""
return not (self.book._unlocked_page_index + 1) >= len(self.book.unlocked_pages)
Loading

0 comments on commit d26509f

Please sign in to comment.