DanisRace/Scripts/Cinema.py
Victorious Children Studios 594e088a83 07-07-24
2024-07-13 16:15:50 +03:00

185 lines
5.8 KiB
Python

# This script will make the cinema work.
import bge
import aud
def Main(w):
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
obj = cont.owner
inCinema = scene.objects["CinemaColider"]["InCinema"]
def cTprint(t):
cText = scene.objects["CinemaText"]
if cText["Text"] != t:
cText["Text"] = t
print(t)
black = scene.objects["CinemaScreen.Black"]
# Play the movie
if obj.get("Movie"):
cTprint("")
if not obj.get("Video"):
movieTexture = bge.texture.VideoFFmpeg(obj.get("Movie"))
print(dir(movieTexture))
texture = bge.texture.Texture(obj, 0, 0)
texture.source = movieTexture
texture.source.play()
texture.refresh(False)
width, height = movieTexture.size
obj.scaling[1] = obj.scaling[1] / height * 1080
device = aud.Device()
sound = aud.Sound(obj.get("Movie"))
obj["Sound"] = device.play(sound)
obj["Video"] = texture
obj["Time"] = bge.logic.getRealTime()
obj["StartTime"] = bge.logic.getRealTime()
obj["soundref"] = 100
black.visible = False
elif inCinema:
if obj.get("iTimer", 0):
obj["iTimer"] = obj.get("iTimer", 1) -1
# Move the audio forward
if 87 in bge.logic.globalDict["keys"] and not obj.get("iTimer", 0):
obj["AudOffset"] = obj.get("AudOffset", 0) + 0.25
obj["iTimer"] = 10
elif 85 in bge.logic.globalDict["keys"] and not obj.get("iTimer", 0):
obj["AudOffset"] = obj.get("AudOffset", 0) - 0.25
obj["iTimer"] = 10
if bge.logic.getRealTime() - obj["Time"] > (1/30):
obj["Video"].source.refresh()#obj["Sound"].position)
obj["Video"].refresh(False)
obj["Time"] = bge.logic.getRealTime()
#print(obj["Video"].source.framerate)
#print("Video Refreshed at:", obj["Time"], obj["Sound"].position)
if not obj["soundref"]:
try:
obj["Sound"].position = bge.logic.getRealTime()-obj["StartTime"]+obj.get("AudOffset", 0)
except:
obj["Movie"] = None
obj["Video"] = None
black.visible = True
obj.scaling[1] = 1
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")]
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")] + "/"
obj["soundref"] = 100
else:
obj["soundref"] -= 1
else:
obj["Sound"].stop()
obj["Video"].source.stop()
obj["Movie"] = None
obj["Video"] = None
obj.scaling[1] = 1
black.visible = True
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")]
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")] + "/"
# FILE MANAGER ( I know I'm crazy )
elif inCinema:
import os
obj["cTfolder"] = obj.get("cTfolder", "/")
obj["cTselect"] = obj.get("cTselect", 0)
# Files and folders
formats = [".mp4", ".ogg", ".ogv", ".avi"]
try:
listdir = []
for i in os.listdir(obj["cTfolder"]):
for format in formats:
if not os.path.isfile(obj["cTfolder"]+i) or i.endswith(format):
listdir.append(i)
break
listdir = list(sorted(listdir))
except:
listdir = []
obj["Movie"] = obj["cTfolder"][:-1]
if not listdir:
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")]
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")] + "/"
if obj.get("iTimer", 0):
obj["iTimer"] = obj.get("iTimer", 1) -1
# Up and down
if 72 in bge.logic.globalDict["keys"] and not obj.get("iTimer", 0):
obj["cTselect"] = ( obj["cTselect"] -1 ) % len(listdir)
obj["iTimer"] = 10
bge.logic.globalDict["SoundDevice"].play(bge.logic.globalDict["sounds"]["checkpoint"]["sound"]) # Play a Ding
elif 70 in bge.logic.globalDict["keys"] and not obj.get("iTimer", 0):
obj["cTselect"] = ( obj["cTselect"] +1 ) % len(listdir)
obj["iTimer"] = 10
bge.logic.globalDict["SoundDevice"].play(bge.logic.globalDict["sounds"]["checkpoint"]["sound"]) # Play a Ding
elif 7 in bge.logic.globalDict["keys"] and not obj.get("iTimer", 0):
obj["cTfolder"] = obj["cTfolder"] + listdir[obj["cTselect"]] + "/"
obj["cTselect"] = 0
obj["iTimer"] = 10
bge.logic.globalDict["SoundDevice"].play(bge.logic.globalDict["sounds"]["checkpoint"]["sound"]) # Play a Ding
elif 59 in bge.logic.globalDict["keys"] and not obj.get("iTimer", 0):
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")]
obj["cTfolder"] = obj["cTfolder"][:obj["cTfolder"].rfind("/")] + "/"
obj["cTselect"] = 0
obj["iTimer"] = 10
bge.logic.globalDict["SoundDevice"].play(bge.logic.globalDict["sounds"]["checkpoint"]["sound"]) # Play a Ding
# Drawing
t = "[ "+obj["cTfolder"]+" ]\n\n"
for n, f in enumerate(listdir[max(0,obj["cTselect"]-5):max(0,obj["cTselect"]-5)+10]):
if listdir[obj["cTselect"]] == f:
t = t + " [ "
else:
t = t + " "
t = t+f
if listdir[obj["cTselect"]] == f:
t = t + " ] "
else:
t = t + " "
t = t + "\n"
cTprint(t)