File size: 2,779 Bytes
a61ba58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from core.constants import GameConfig
from typing import List

class GameState:
    def __init__(self):
        self.story_beat = GameConfig.STORY_BEAT_INTRO
        self.story_history = []
        self.current_time = GameConfig.STARTING_TIME
        self.current_location = GameConfig.STARTING_LOCATION
        # Universe information
        self.universe_style = None
        self.universe_genre = None
        self.universe_epoch = None
        self.universe_story = None
        
    def reset(self):
        """Reset game state while keeping universe information."""
        # Save universe info
        universe_style = self.universe_style
        universe_genre = self.universe_genre
        universe_epoch = self.universe_epoch
        universe_story = self.universe_story
        
        # Reset game state
        self.story_beat = GameConfig.STORY_BEAT_INTRO
        self.story_history = []
        self.current_time = GameConfig.STARTING_TIME
        self.current_location = GameConfig.STARTING_LOCATION
        
        # Restore universe info
        self.universe_style = universe_style
        self.universe_genre = universe_genre
        self.universe_epoch = universe_epoch
        self.universe_story = universe_story
        
    def set_universe(self, style: str, genre: str, epoch: str, base_story: str):
        """Configure the game universe."""
        self.universe_style = style
        self.universe_genre = genre
        self.universe_epoch = epoch
        self.universe_story = base_story
        
    def has_universe(self) -> bool:
        """Check if universe is configured."""
        return all([
            self.universe_style is not None,
            self.universe_genre is not None,
            self.universe_epoch is not None,
            self.universe_story is not None
        ])

    def format_history(self) -> str:
        """Format story history for the prompt."""
        if not self.story_history:
            return ""
            
        segments = []
        for entry in self.story_history:
            segment = entry['segment']
            if entry['player_choice']:
                segment += f"\n[Choix du joueur: {entry['player_choice']}]"
            segments.append(segment)
        
        return "\n\n---\n\n".join(segments)

    def add_to_history(self, segment_text: str, choice_made: str, image_prompts: List[str], time: str, location: str):
        """Add a segment to history with essential information."""
        self.story_history.append({
            "segment": segment_text,
            "player_choice": choice_made,
            "time": time,
            "location": location,
            "image_prompts": image_prompts
        })
        self.current_time = time
        self.current_location = location