Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions button_2/blackboard.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,14 @@ This is where I apply wrappers.
employee_text_rendered.rendered_text

```


##


```{python}
from classes.game.node_engine import NodeEngine

node_engine = NodeEngine()

```
28 changes: 1 addition & 27 deletions button_2/blackboard_node_logic.py
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
# this script is for sketching the node engine logic


# this would be done in the game engine

from classes.game.node_context import NodeContext
from classes.entities.employee import Employee
from classes.data.button_dat import ButtonDat

button_dat = ButtonDat()

# aha so I can refactor this to be generated by the context?
employee = Employee(button_dat.employee_df.iloc[0]['job_title'],
button_dat.employee_df.iloc[0]['department'])

context = NodeContext(employee=employee)


# node engine logic
from classes.text_gen.textgen_employee import EmployeeTextGenerator

# todo node title

employee.set_current_titles()

employee_text_gen = EmployeeTextGenerator()
print(employee_text_gen.generate_text(context))
#
28 changes: 28 additions & 0 deletions button_2/classes/game/edge_selector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from ..data.button_dat import ButtonDat
from ..entities.employee import Employee

class EdgeSelector:
def __init__(self, button_dat: ButtonDat, employee: Employee, current_node=None):
self.button_dat = button_dat
self.employee = employee
self.current_node = current_node
self.next_edge = None

def set_current_node(self, node):
self.current_node = node
self.next_edge = None

def select_next_edge(self):
if self.current_node is None:
raise ValueError("Current node is not set.")

# Logic to select the next edge
connections = self.button_dat.edges_df[
self.button_dat.edges_df['source'] == self.current_node
]

# perhaps I need an edge id to refer to here
if not connections.empty:
self.next_edge = connections.target.iloc[0]
else:
self.next_edge = None
20 changes: 20 additions & 0 deletions button_2/classes/game/node_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ..data.button_dat import ButtonDat
from ..entities.employee import Employee
from ..game.edge_selector import EdgeSelector

class NodeEngine:
def __init__(
self, button_dat: ButtonDat, employee: Employee
):
self.button_dat = button_dat
self.employee = employee
self.current_node = button_dat.nodes_df.node.iloc[0]
self.next_edge = None
self.edge_selector = EdgeSelector(
button_dat, employee, self.current_node
)

def select_next_edge(self):
self.edge_selector.set_current_node(self.current_node)
self.edge_selector.select_next_edge()
self.next_edge = self.edge_selector.next_edge
8 changes: 7 additions & 1 deletion button_2/tests/data/test_button_dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ def test_button_dat_initialisation():
assert not game_data.edges_df.empty, "Edges DataFrame should not be empty"
assert not game_data.nodes_df.empty, "Nodes DataFrame should not be empty"
assert not game_data.text_df.empty, "Text DataFrame should not be empty"
assert not game_data.employee_df.empty, "Employee DataFrame should not be empty"
assert not game_data.employee_df.empty, "Employee DataFrame should not be empty"

# Test edges has expected columns
expected_edge_columns = {'source', 'target', 'outro_text', 'desired'}
assert set(game_data.edges_df.columns) == expected_edge_columns, (
"Edges DataFrame has unexpected columns"
)
Empty file.
20 changes: 12 additions & 8 deletions button_2/tests/game/test_node_engine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from classes.data.button_dat import ButtonDat
from classes.entities.employee import Employee
import pytest
from button_2.classes.data.button_dat import ButtonDat
from button_2.classes.entities.employee import Employee
from button_2.classes.game.node_engine import NodeEngine

button_dat = ButtonDat()
employee = Employee(button_dat)
@pytest.fixture
def node_engine():
button_dat = ButtonDat()
employee = Employee(button_dat)
return NodeEngine(button_dat, employee)

def test_node_engine_attributes(node_engine):
assert hasattr(node_engine, 'button_dat')
Expand All @@ -12,10 +17,9 @@ def test_node_engine_attributes(node_engine):

def test_node_engine_methods(node_engine):
assert callable(node_engine.select_next_edge)
# assert that next edge attribute is unset at init
assert node_engine.next_edge is None
# assert that select_next_edge sets next_edge
node_engine.select_next_edge()
assert node_engine.next_edge is not None
# assert that next_edge is in button_dat.nodes_df.nodes
assert node_engine.next_edge in button_dat.nodes_df.nodes
assert node_engine.next_edge in (
node_engine.button_dat.nodes_df.node.tolist()
)