/
main.py
162 lines (129 loc) · 3.68 KB
/
main.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Connection libraries
import pygame
import codecs
import os
# Connecting files
from settings import *
from common import *
# Connecting classes
from launcher import Launcher
from create import Create
from play import Play
# Main class
class Main:
def __init__(self):
pygame.init()
# Setting variables
self.pathToProjects = ""
# Getting launcher settings
self.getLauncherSettings()
# Launcher window
self.window = pygame.display.set_mode(SIZE)
pygame.display.set_caption("Launcher")
# Launcher icon
launcherIcon = loadImage("launcher/icon.png")
pygame.display.set_icon(launcherIcon)
# Current folder
self.currentFolder = os.getcwd()
# Boolean variables
self.running = True
# Clock
self.clock = pygame.time.Clock()
# Launcher
self.launcher = Launcher()
# Create
self.create = Create(self.pathToProjects)
# Path
self.path = ""
# Gameloop
self.loop()
# Getting launcher settings
def getLauncherSettings(self):
settings = codecs.open("launcher/settings.vn", "r", "utf-8")
content = clearLines(settings.read().split("\n"))
for line in content:
line = line.replace(" ", "")
setting, value = line.split("=")
if setting == "PATHTOPROJECTS": self.pathToProjects = value
self.pathToProjects = os.getcwd() + "/projects/"
# Handling events
def events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.end()
# Handling buttons
for button in self.launcher.buttons:
if event.type == pygame.MOUSEMOTION:
if mouseCollision(button.xy, button.wh, event.pos):
button.hover = True
else: button.hover = False
if event.type == pygame.MOUSEBUTTONDOWN:
if mouseCollision(button.xy, button.wh, event.pos):
button.click = True
self.buttonActions(button)
else: button.click = False
# Handling links
for link in self.launcher.links:
if event.type == pygame.MOUSEMOTION:
if mouseCollision(link.xy, link.twh, event.pos):
link.hover = True
else: link.hover = False
if event.type == pygame.MOUSEBUTTONDOWN:
if mouseCollision(link.xy, link.twh, event.pos):
link.selected = True
else: link.selected = False
# Button actions
def buttonActions(self, button):
# Start selected project
if button.name == "startproject":
# Getting the name of the selected project
projectname = ""
for link in self.launcher.links:
if link.selected == True: projectname = link.rtrn
if projectname == "": return
self.startProject(projectname)
# Create new project
elif button.name == "createproject":
self.create.createProject("new")
self.launcher.createProjectList()
# Updating the list of projects
elif button.name == "updatelistcprojects":
self.launcher.createProjectList()
# Deleting the selected project
elif button.name == "deleteproject":
projectname = ""
for link in self.launcher.links:
if link.selected == True: projectname = link.rtrn
if projectname == "": return
self.create.deleteProject(projectname)
self.launcher.createProjectList()
# Intermediant calculations
def update(self):
self.clock.tick(FPS)
self.events()
# Rendering game objects
def render(self):
self.window.fill(WHITE)
# scImage(self.window, "launcher/background.jpg", (0,0), SIZE)
self.launcher.drawObjects(self.window)
pygame.display.update()
# Gameloop
def loop(self):
while self.running:
self.update()
self.render()
# Start project
def startProject(self, projectName):
self.path = self.pathToProjects + projectName
self.end()
# Turn off the launcher
def end(self):
self.running = False
# Start launcher
main = Main()
path = main.path
pygame.quit()
if path != "":
# Start project
Play(path)
pygame.quit()