#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Created by: python.exe -m py2exe mygame.py -O -W setup.py


import platform
import os
from distutils.core import setup
import py2exe

class Target(object):
    '''Target is the baseclass for all executables that are created.
    It defines properties that are shared by all of them.
    '''
    def __init__(self, **kw):
        self.__dict__.update(kw)

        # the VersionInfo resource, uncomment and fill in those items
        # that make sense:
        
        # The 'version' attribute MUST be defined, otherwise no versioninfo will be built:
        # self.version = "1.0"
        
        # self.company_name = "Company Name"
        # self.copyright = "Copyright Company Name © 2013"
        # self.legal_copyright = "Copyright Company Name © 2013"
        # self.legal_trademark = ""
        # self.product_version = "1.0.0.0"
        # self.product_name = "Product Name"

        # self.private_build = "foo"
        # self.special_build = "bar"

    def copy(self):
        return Target(**self.__dict__)

    def __setitem__(self, name, value):
        self.__dict__[name] = value

RT_BITMAP = 2
RT_MANIFEST = 24

# A manifest which specifies the executionlevel
# and windows common-controls library version 6

manifest_template = '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    version="5.0.0.0"
    processorArchitecture="*"
    name="%(prog)s"
    type="win32"
  />
  <description>%(prog)s</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
            level="%(level)s"
            uiAccess="false">
        </requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>
'''



mygame = Target(
    script = "mygame.py",
    dest_base = "MyGame",
    icon_resource = [(1, r"pico2d.ico")],


    other_resources = [(RT_MANIFEST, 1, (manifest_template % dict(prog="mygame", level="asInvoker")).encode("utf-8"))]
    )

py2exe_options = dict(
    packages = [],
    optimize=1,
    compressed=True, # uncompressed may or may not have a faster startup
    bundle_files=2,
    dist_dir='dist',
    )

sound_folder = "./sound/"
ui_folder = "./UI/"
golem_folder = "./resource/enemy/golem/"
skeleton_folder = "./resource/enemy/skeleton/"
vampire_folder = "./resource/enemy/vampire/"
zombie_folder = "./resource/enemy/zombie/"
skill_folder = "./resource/skill/"
team1_folder = "./resource/team/ch1/"
team2_folder = "./resource/team/ch2/"
team3_folder = "./resource/team/ch3/"
team4_folder = "./resource/team/ch4/"
if platform.architecture()[0] == '32bit':
    sdl_folder = './SDL2/x86/'
else:
    sdl_folder = './SDL2/x64/'

sdl_dlls = [sdl_folder + file_name for file_name in os.listdir(sdl_folder)]
sound_dlls = [sound_folder + file_name for file_name in os.listdir(sound_folder)]
ui_dlls = [ui_folder + file_name for file_name in os.listdir(ui_folder)]

golem_dlls = [golem_folder + file_name for file_name in os.listdir(golem_folder)]
skeleton_dlls = [skeleton_folder + file_name for file_name in os.listdir(skeleton_folder)]
vampire_dlls = [vampire_folder + file_name for file_name in os.listdir(vampire_folder)]
zombie_dlls = [zombie_folder + file_name for file_name in os.listdir(zombie_folder)]
skill_dlls = [skill_folder + file_name for file_name in os.listdir(skill_folder)]

team1_dlls = [team1_folder + file_name for file_name in os.listdir(team1_folder)]
team2_dlls = [team2_folder + file_name for file_name in os.listdir(team2_folder)]
team3_dlls = [team3_folder + file_name for file_name in os.listdir(team3_folder)]
team4_dlls = [team4_folder + file_name for file_name in os.listdir(team4_folder)]

setup(name="name",
      windows=[mygame],
      data_files=[ (ui_folder,ui_dlls),(sound_folder,sound_dlls), (golem_folder,golem_dlls),(skeleton_folder,skeleton_dlls),(vampire_folder,vampire_dlls), (zombie_folder, zombie_dlls),  (skill_folder,skill_dlls),(team1_folder,team1_dlls),(team2_folder,team2_dlls), (team3_folder, team3_dlls) , (team4_folder, team4_dlls) ,(sdl_folder, sdl_dlls)  ],
      zipfile=None,
      options={"py2exe": py2exe_options},
      )

