Skip to content

Commit

Permalink
Merge pull request #223 from KonstantinKlepikov/KonstantinKlepikov/is…
Browse files Browse the repository at this point in the history
…sue219

steps changes
  • Loading branch information
KonstantinKlepikov authored Dec 1, 2022
2 parents f92a9c7 + 7ec07c0 commit 3642f8e
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 395 deletions.
3 changes: 1 addition & 2 deletions bgameb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from bgameb.markers import Step
from bgameb.items import Dice, Card
from bgameb.items import Dice, Card, Step
from bgameb.tools import Shaker, Deck, Steps
from bgameb.players import Player
from bgameb.game import Game
Expand Down
24 changes: 19 additions & 5 deletions bgameb/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@
from dataclasses_json import config, dataclass_json
from bgameb.base import Base
from bgameb.errors import StuffDefineError
from bgameb.types import MARKERS


@dataclass_json
@dataclass(repr=False)
class BaseItem(Base):
"""Base class for game items (like dices or cards)
"""

Attr:
- count (int): count of items. Default to 1.
def __post_init__(self) -> None:
super().__post_init__()


@dataclass_json
@dataclass(order=True, repr=False)
class Step(BaseItem):
"""Game steps or turns
Attr:
- priority (int): priority queue number. Default to 0.
"""
count: int = 1
priority: int = 0

def __post_init__(self) -> None:
super().__post_init__()
self._types_to_add = MARKERS


@dataclass_json
Expand All @@ -38,9 +45,14 @@ class Dice(BaseItem):
dice = Dice('coin', sides=2)
Attr:
- count (int): count of items. Default to 1.
- sides (int): sides of dice or coin. Default to 2.
Raises:
StuffDefineError: number of sides less than 2
"""
count: int = 1
sides: int = 2
_range: List[int] = field(
default_factory=list,
Expand Down Expand Up @@ -79,6 +91,7 @@ class Card(BaseItem):
"""Card object
Attr:
- count (int): count of items. Default to 1.
- opened (bool): is card oppened. Default to False.
- tapped (bool): is card tapped. Default to False.
- side (str, optional): the side of tap. Default to None.
Expand All @@ -89,6 +102,7 @@ class Card(BaseItem):
card = CardType('unique_card')
card.tap(side='left')
"""
count: int = 1
opened: bool = False
tapped: bool = False
side: Optional[str] = None
Expand Down
29 changes: 0 additions & 29 deletions bgameb/markers.py

This file was deleted.

6 changes: 6 additions & 0 deletions bgameb/newsfragments/219.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#219:
* Step now is an item
* BaseIteme now hasnt count attr - this attribute moved to Card and Dice classes
* tests all
* docs changes
* ->
3 changes: 3 additions & 0 deletions bgameb/newsfragments/219.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#219:
* markers.py, markers types and test are removed.
* ->
4 changes: 2 additions & 2 deletions bgameb/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from bgameb.base import Base
from bgameb.types import MARKERS_ITEMS_TOOLS
from bgameb.types import ITEMS_TOOLS


@dataclass_json
Expand All @@ -24,4 +24,4 @@ class Player(Base):

def __post_init__(self) -> None:
super().__post_init__()
self._types_to_add = MARKERS_ITEMS_TOOLS
self._types_to_add = ITEMS_TOOLS
10 changes: 6 additions & 4 deletions bgameb/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from dataclasses import dataclass, field, replace
from dataclasses_json import config, dataclass_json
from bgameb.base import Base
from bgameb.markers import Step
from bgameb.items import Card, Dice
from bgameb.items import Card, Dice, Step
from bgameb.errors import ArrangeIndexError
from bgameb.types import MARKERS_ITEMS
from bgameb.types import ITEMS


@dataclass_json
Expand All @@ -21,7 +20,7 @@ class BaseTool(Base):

def __post_init__(self) -> None:
super().__post_init__()
self._types_to_add = MARKERS_ITEMS
self._types_to_add = ITEMS


@dataclass_json
Expand Down Expand Up @@ -72,6 +71,9 @@ class Deck(BaseTool):
`python deque
<https://docs.python.org/3/library/collections.html#deque-objects>`_
Attr:
- current (Deque[Card]): current cards deque.
.. code-block::
:caption: Example:
Expand Down
8 changes: 3 additions & 5 deletions bgameb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from typing import List


MARKERS: List[str] = ['step']
ITEMS: List[str] = ['dice', 'card', ]
ITEMS: List[str] = ['dice', 'card', 'step', ]
TOOLS: List[str] = ['shaker', 'deck', 'steps']
PLAYERS: List[str] = ['player', ]
GAMES: List[str] = ['game', ]

MARKERS_ITEMS = MARKERS + ITEMS
MARKERS_ITEMS_TOOLS = MARKERS_ITEMS + TOOLS
COMPONENTS = MARKERS_ITEMS_TOOLS + PLAYERS + GAMES
ITEMS_TOOLS = ITEMS + TOOLS
COMPONENTS = ITEMS_TOOLS + PLAYERS + GAMES
4 changes: 2 additions & 2 deletions docs/build/html/_modules/bgameb/errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>bgameb.errors &mdash; bgameb 0.0.24 documentation</title>
<title>bgameb.errors &mdash; bgameb 0.0.27 documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -28,7 +28,7 @@
<a href="../../index.html" class="icon icon-home"> bgameb
</a>
<div class="version">
0.0.24
0.0.27
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down
30 changes: 22 additions & 8 deletions docs/build/html/_modules/bgameb/items.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>bgameb.items &mdash; bgameb 0.0.24 documentation</title>
<title>bgameb.items &mdash; bgameb 0.0.27 documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand All @@ -28,7 +28,7 @@
<a href="../../index.html" class="icon icon-home"> bgameb
</a>
<div class="version">
0.0.24
0.0.27
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
Expand Down Expand Up @@ -77,23 +77,30 @@ <h1>Source code for bgameb.items</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">dataclasses_json</span> <span class="kn">import</span> <span class="n">config</span><span class="p">,</span> <span class="n">dataclass_json</span>
<span class="kn">from</span> <span class="nn">bgameb.base</span> <span class="kn">import</span> <span class="n">Base</span>
<span class="kn">from</span> <span class="nn">bgameb.errors</span> <span class="kn">import</span> <span class="n">StuffDefineError</span>
<span class="kn">from</span> <span class="nn">bgameb.types</span> <span class="kn">import</span> <span class="n">MARKERS</span>


<div class="viewcode-block" id="BaseItem"><a class="viewcode-back" href="../../bgameb.html#bgameb.items.BaseItem">[docs]</a><span class="nd">@dataclass_json</span>
<span class="nd">@dataclass</span><span class="p">(</span><span class="nb">repr</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">BaseItem</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Base class for game items (like dices or cards)</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="sd"> Attr:</span>
<span class="sd"> - count (int): count of items. Default to 1.</span>
<span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span></div>


<div class="viewcode-block" id="Step"><a class="viewcode-back" href="../../bgameb.html#bgameb.items.Step">[docs]</a><span class="nd">@dataclass_json</span>
<span class="nd">@dataclass</span><span class="p">(</span><span class="n">order</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="nb">repr</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">Step</span><span class="p">(</span><span class="n">BaseItem</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Game steps or turns</span>

<span class="sd"> Attr:</span>
<span class="sd"> - priority (int): priority queue number. Default to 0.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">count</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">priority</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span>

<span class="k">def</span> <span class="nf">__post_init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_types_to_add</span> <span class="o">=</span> <span class="n">MARKERS</span></div>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__post_init__</span><span class="p">()</span></div>


<div class="viewcode-block" id="Dice"><a class="viewcode-back" href="../../bgameb.html#bgameb.items.Dice">[docs]</a><span class="nd">@dataclass_json</span>
Expand All @@ -109,9 +116,14 @@ <h1>Source code for bgameb.items</h1><div class="highlight"><pre>

<span class="sd"> dice = Dice(&#39;coin&#39;, sides=2)</span>

<span class="sd"> Attr:</span>
<span class="sd"> - count (int): count of items. Default to 1.</span>
<span class="sd"> - sides (int): sides of dice or coin. Default to 2.</span>

<span class="sd"> Raises:</span>
<span class="sd"> StuffDefineError: number of sides less than 2</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">count</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">sides</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">_range</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span>
<span class="n">default_factory</span><span class="o">=</span><span class="nb">list</span><span class="p">,</span>
Expand Down Expand Up @@ -150,6 +162,7 @@ <h1>Source code for bgameb.items</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;Card object</span>

<span class="sd"> Attr:</span>
<span class="sd"> - count (int): count of items. Default to 1.</span>
<span class="sd"> - opened (bool): is card oppened. Default to False.</span>
<span class="sd"> - tapped (bool): is card tapped. Default to False.</span>
<span class="sd"> - side (str, optional): the side of tap. Default to None.</span>
Expand All @@ -160,6 +173,7 @@ <h1>Source code for bgameb.items</h1><div class="highlight"><pre>
<span class="sd"> card = CardType(&#39;unique_card&#39;)</span>
<span class="sd"> card.tap(side=&#39;left&#39;)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">count</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">opened</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">tapped</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">side</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>
Expand Down
Loading

0 comments on commit 3642f8e

Please sign in to comment.