# Path: Ecstatica/Event.py
# class EventType(object):
# class Event(object):
# class NextSceneEvent(Event):
#     def __init__(self, typeid, index_type, value1_type, value2_type, value3_type, priority):
# def createEventFromTextData(index_text, event_type_name, value1_text, value2_text, value3_text):
#     def __init__(self, index, event_type, value1, value2, value3):
#     def __str__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, index, value1, value2, value3, uk_data):
#     def __str__(self):
# def extractEventVector3(event):
# def extractEventAngles3(event):


import struct
import itertools
import codecs
import unittest
from . import Fixpoint
from . import Event
from .Event import ev_NO_EVENT
from . import FantFile 
from . import FANTLoad
    stringlist += struct.pack('b', 0)
    return stringlist

def fantifyEventList(eventlist):
    '''    
    '''
    #by default, we always construct a terminal event and attach it to the list
    #but if the last event in the given list is already a NO_EVENT-event, we omit our own
    attach_terminal_event = True
    
    eventliststr = b""
    for event in eventlist:
        eventliststr += struct.pack(">hhhhh", event.event_type, event.index, event.value1, event.value2, event.value3)
        if event.event_type == Event.ev_NEXT_SCENE and event.index != 0: #special case! We have to attach data
            #eventliststr += struct.pack(">" + "".join(itertools.repeat("b", len(event.uk_data))), event.uk_data)
            eventliststr += event.uk_data.encode("ascii")
            eventliststr += struct.pack("b", 0)
        elif event.event_type == Event.ev_NO_EVENT:
            assert event == eventlist[-1] #make sure this is the last event in the list!
            attach_terminal_event = False
            
    if attach_terminal_event:
        #we append a ZERO-event to mark the end of the event list    
        
        #In the original ECSTATICA data files, I found that the NO-EVENT-Events have actually specific values for value1, value2, value3
        #I use these values here
        #Except in one case: When the list of events is completele empty. So we do this differentiation here too...
        if len(eventlist) > 0:
            eventliststr += struct.pack('>HhHHH', ev_NO_EVENT, 0, 0x160a, 0x004d, 0xd0f7)
        else:

# Path: Ecstatica/Event.py
# class EventType(object):
# class Event(object):
# class NextSceneEvent(Event):
#     def __init__(self, typeid, index_type, value1_type, value2_type, value3_type, priority):
# def createEventFromTextData(index_text, event_type_name, value1_text, value2_text, value3_text):
#     def __init__(self, index, event_type, value1, value2, value3):
#     def __str__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __init__(self, index, value1, value2, value3, uk_data):
#     def __str__(self):
# def extractEventVector3(event):
# def extractEventAngles3(event):


# Path: Ecstatica/FANTSave.py
import struct
import itertools
import codecs
import unittest
from . import Fixpoint
from . import Event
from .Event import ev_NO_EVENT
from . import FantFile 
from . import FANTLoad

    stringlist += struct.pack('b', 0)
    return stringlist

def fantifyEventList(eventlist):
    '''    
    '''
    #by default, we always construct a terminal event and attach it to the list
    #but if the last event in the given list is already a NO_EVENT-event, we omit our own
    attach_terminal_event = True
    
    eventliststr = b""
    for event in eventlist:
        eventliststr += struct.pack(">hhhhh", event.event_type, event.index, event.value1, event.value2, event.value3)
        if event.event_type == Event.ev_NEXT_SCENE and event.index != 0: #special case! We have to attach data
            #eventliststr += struct.pack(">" + "".join(itertools.repeat("b", len(event.uk_data))), event.uk_data)
            eventliststr += event.uk_data.encode("ascii")
            eventliststr += struct.pack("b", 0)
        elif event.event_type == Event.ev_NO_EVENT:
            assert event == eventlist[-1] #make sure this is the last event in the list!
            attach_terminal_event = False
            
    if attach_terminal_event:
        #we append a ZERO-event to mark the end of the event list    
        
        #In the original ECSTATICA data files, I found that the NO-EVENT-Events have actually specific values for value1, value2, value3
        #I use these values here
        #Except in one case: When the list of events is completele empty. So we do this differentiation here too...
        if len(eventlist) > 0:
            eventliststr += struct.pack('>HhHHH', ev_NO_EVENT, 0, 0x160a, 0x004d, 0xd0f7)
        else:

            eventliststr += struct.pack(">hhhhh", Event.ev_NO_EVENT, 0, 0, 0, 0)