Move state into patchouli

This commit is contained in:
object-Object 2023-06-25 22:47:46 -04:00
parent b8f2a78a6d
commit c5c4caf22a
12 changed files with 15 additions and 15 deletions

View file

@ -9,8 +9,7 @@ __all__ = [
"HexBookState",
]
from hexcasting.hex_state import HexBookState
from patchouli.book import Book
from patchouli import Book
from .hex_recipes import (
BlockState,
@ -20,5 +19,6 @@ from .hex_recipes import (
ModConditionalCraftingShapelessRecipe,
ModConditionalIngredient,
)
from .hex_state import HexBookState
HexBook = Book[HexBookState]

View file

@ -2,9 +2,8 @@ from dataclasses import dataclass
from typing import Any
from common.pattern import PatternInfo
from common.state import BookState
from minecraft.resource import ResourceLocation
from patchouli.book import Book
from patchouli.state import BookState
@dataclass

View file

@ -14,7 +14,7 @@ from tap import Tap
from collate_data import generate_docs
from common.properties import Properties
from hexcasting.hex_state import HexBookState
from patchouli.book import Book
from patchouli import Book
if sys.version_info < (3, 11):
raise RuntimeError("Minimum Python version: 3.11")

View file

@ -4,9 +4,9 @@ from dataclasses import dataclass
from typing import Any, Self
from common.deserialize import TypeHook, load_json_data
from common.state import AnyState, TypeTaggedUnion
from common.types import LocalizedItem
from minecraft.resource import ResourceLocation
from patchouli.state import AnyState, TypeTaggedUnion
@dataclass

View file

@ -1,6 +1,6 @@
from dataclasses import dataclass
from common.state import BookState
from patchouli.state import BookState
from .abstract_recipes import CraftingRecipe, ItemIngredient

View file

@ -6,11 +6,11 @@ from typing import Literal, Self
from common.deserialize import from_dict_checked, load_json_data, rename
from common.formatting import FormatTree
from common.state import AnyState, Stateful
from common.types import Color, LocalizedStr
from minecraft.i18n import I18n
from minecraft.recipe import Recipe, minecraft_recipes as _ # ensure unions are loaded
from minecraft.resource import ItemStack, ResLoc, ResourceLocation
from patchouli.state import AnyState, Stateful
from .category import Category
from .entry import Entry
@ -71,10 +71,11 @@ class Book(Stateful[AnyState], ABC):
@classmethod
def load(cls, state: AnyState) -> Self:
"""Loads `book.json`, and sets up shared state with `cls._make_state()`.
"""Loads `book.json` and finishes initializing the shared state.
Subclasses should generally not override this. To customize state creation or
add type hooks (including page or recipe types), override `_init_state()`.
add type hooks (including page or recipe types), override `__post_init__()`,
calling `super()` at the end (because that's where categories/entries load).
"""
# read the raw dict from the json file

View file

@ -5,9 +5,9 @@ from typing import Self
from common.deserialize import rename
from common.formatting import FormatTree
from common.state import BookState, StatefulFile
from common.types import LocalizedStr, Sortable, sorted_dict
from minecraft.resource import ItemStack, ResourceLocation
from patchouli.state import BookState, StatefulFile
from .entry import Entry

View file

@ -3,9 +3,9 @@ from __future__ import annotations
from dataclasses import dataclass, field
from common.deserialize import rename
from common.state import BookState, StatefulFile
from common.types import Color, LocalizedStr, Sortable
from minecraft.resource import ItemStack, ResourceLocation
from patchouli.state import BookState, StatefulFile
from .page import Page

View file

@ -4,10 +4,10 @@ from typing import Any, Self
from common.deserialize import TypeHook, rename
from common.formatting import FormatTree
from common.state import AnyState, TypeTaggedUnion
from common.types import LocalizedStr
from minecraft.recipe import CraftingRecipe
from minecraft.resource import ResourceLocation
from patchouli.state import AnyState, TypeTaggedUnion
@dataclass(kw_only=True)

View file

@ -5,10 +5,10 @@ from typing import Any
from common.deserialize import rename
from common.formatting import FormatTree
from common.state import BookState
from common.types import LocalizedItem, LocalizedStr
from minecraft.recipe import CraftingRecipe
from minecraft.resource import Entity, ItemStack, ResourceLocation
from patchouli.state import BookState
from .abstract_pages import Page, PageWithCraftingRecipes, PageWithText, PageWithTitle

View file

@ -15,7 +15,7 @@ from common.properties import Properties
from common.types import LocalizedStr
from hexcasting.hex_state import HexBookState
from main import Args, main
from patchouli.book import Book
from patchouli import Book
def prettify(data: SerializedData) -> str: