diff --git a/ropy-32.blend b/ropy-32.blend index f0ce265..0b89079 100644 Binary files a/ropy-32.blend and b/ropy-32.blend differ diff --git a/rp.py b/rp.py index 62a717f..7e77703 100644 --- a/rp.py +++ b/rp.py @@ -3,11 +3,9 @@ import bpy # Blender import aud # Sounds import math import mathutils -# import numpy as np import time import sys import os -# import webbrowser # Lien internet import threading # Multithreading import subprocess # Multiprocessus import xml.etree.ElementTree as ET # Creating/parsing XML file @@ -37,17 +35,17 @@ import rp_about # About # 3D scene manipulation : manip_* ############################################################################### -# Debug flag +# UPBGE scene scene = bge.logic.getCurrentScene() -scene.objects['Commands']['debug_fps']=False +eevee = bpy.context.scene.eevee scene.objects['Commands']['script'] = os.path.join(os.getcwd(), "rp_cmd.py") # Script par défaut # Memory sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender -# UPBGE scene -eevee = bpy.context.scene.eevee +# FPS fps_time=0.0 +scene.objects['Commands']['debug_fps']=False # Config file rp_config = ET.parse('rp_config.xml') @@ -108,11 +106,10 @@ def points_maj (cont): scene.objects['Book_level']['Text'] = "Niveau actuel : "+str(scene.objects['Points']['level']) # Maj du fichier de config (sound : data/mission/level -> [1][1].text) lors d'une augmentation de niveau - if scene.objects['Points']['level']>int(rp_config_tree[1][1].text): + if scene.objects['Points']['level']>int(rp_config_tree[1][1].text) and scene.objects['Points']['level_new_flag']: rp_config_tree[1][1].text=str(scene.objects['Points']['level']) - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) + config_save() + scene.objects['Points']['level_new_flag']=False # Nbligne if scene.objects['Points-Nbligne-text']['Text']!=str(scene.objects['Points']['nbligne']): @@ -121,7 +118,7 @@ def points_maj (cont): # Position du Rover obj=scene.objects['Rover'] obj['w_position']=str(round(obj.worldPosition.x,3))+","+str(round(obj.worldPosition.y,3))+","+str(round(obj.worldPosition.z,3)) - + ############################################################################### # Terrain ############################################################################### @@ -233,6 +230,10 @@ def python_validation(file): scene.objects['Cmd-text'].setVisible(False,False) return True +## +# Exécuter le script +## + def terrain_run (): # Pause @@ -316,12 +317,6 @@ def terrain_speed (obj): scene.objects['Commands']['speed']=speed_mode[i-1] scene.objects['Text_speed']['Text']=speed_mode_txt[i-1] - # Maj du fichier de config (vitesse du jeu : data/config/speed -> [0][0].text) - rp_config_tree[0][0].text=str(scene.objects['Commands']['speed']) - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) - ## # Grille ## @@ -375,12 +370,6 @@ def sound_set (): scene.objects['Cmd-text']['Text']= "Muet" # scene.objects['Cmd-text'].setVisible(True,False) - # Maj du fichier de config (sound : data/config/sound -> [0][1].text) - rp_config_tree[0][1].text=str(scene.objects['Commands']['sound']) - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) - def sound_unset (): scene.objects['Sound-cmd'].suspendPhysics() scene.objects['Sound-cmd'].setVisible(False,False) @@ -392,12 +381,6 @@ def sound_unset (): scene.objects['Cmd-text']['Text']= "Rétablir le son" # scene.objects['Cmd-text'].setVisible(True,False) - # Maj du fichier de config (sound : data/config/sound -> [0][1].text) - rp_config_tree[0][1].text=str(scene.objects['Commands']['sound']) - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) - ############################################################################### # Commandes ############################################################################### @@ -478,17 +461,6 @@ def cmd_init(cont): scene.objects['Mouse_main'].setVisible(False,False) bge.render.showMouse(True) - # Speed - # Read config (game speed : data/config/speed -> [0][0].text) - speed_mode=[0.25, 0.5, 1,2,4,10] - speed_mode_txt=["1/4", "1/2", "1", "2","4","10"] - if scene.objects['Points']['upgrade_speed'] : - scene.objects['Commands']['speed']=float(rp_config_tree[0][0].text) - else: - scene.objects['Commands']['speed']=1.00 - i=speed_mode.index(scene.objects['Commands']['speed']) - scene.objects['Text_speed']['Text']=speed_mode_txt[i] - # Missions # Read config (mission actuelle : data/mission/current -> [1][0].text) # Read config (niveau atteint : data/mission/level -> [1][1].text) @@ -500,8 +472,28 @@ def cmd_init(cont): scene.objects['Book_level']['Text'] = "Niveau actuel : "+str(scene.objects['Points']['level']) # Upgrade + # Read config (upgrades choisis : data/upgrade/ -> [2][i].text) + upgrade_card=("battery", "beacon", "paint", "speed") + scene.objects['Points']['upgrade_nb'] =0 + for i in range(len(upgrade_card)): + if rp_config_tree[2][i].text == "True": + scene.objects['Points']['upgrade_'+upgrade_card[i]]=True + scene.objects['Points']['upgrade_nb'] +=1 + scene.objects["Store-"+upgrade_card[i]+"-card"]['upgraded'] = True + scene.objects['Points']['upgrade_credit']= scene.objects['Points']['level']- 1 - scene.objects['Points']['upgrade_nb'] upgrade_maj() - + + # Speed + # Read config (game speed : data/config/speed -> [0][0].text) + speed_mode=[0.25, 0.5, 1,2,4,10] + speed_mode_txt=["1/4", "1/2", "1", "2","4","10"] + if scene.objects['Points']['upgrade_speed'] : + scene.objects['Commands']['speed']=float(rp_config_tree[0][0].text) + else: + scene.objects['Commands']['speed']=1.00 + i=speed_mode.index(scene.objects['Commands']['speed']) + scene.objects['Text_speed']['Text']=speed_mode_txt[i] + # Windows windows=("Doc", "Doc_chap-general", "Doc_chap-missions", "Doc_chap-rover", "Doc_chap-python", "About", "Task") for window in windows: @@ -711,21 +703,25 @@ def mode(cont): else: # Sortir du jeu terrain_stop () - # Maj du fichier de config (position de la camera : data/config/cam_x,y,z -> [0][2][0].text, [0][2][1].text, [0][2][2].text) + # MAJ du fichier de config + # Position de la camera : data/config/cam_x,y,z -> [0][2][0].text, [0][2][1].text, [0][2][2].text) rp_config_tree[0][2][0].text=str(scene.objects['Camera']['current_lx']) rp_config_tree[0][2][1].text=str(scene.objects['Camera']['current_ly']) rp_config_tree[0][2][2].text=str(scene.objects['Camera']['current_lz']) - - # Maj du fichier de config (screen size : data/config/screen/width, height, quality-> [0][3][0].text, [0][3][1].text, [0][3][2].text) + # Ecran : data/config/screen/width, height, quality-> [0][3][0].text, [0][3][1].text, [0][3][2].text) screen_width = bge.render.getWindowWidth() screen_height = bge.render.getWindowHeight() rp_config_tree[0][3][0].text=str(screen_width) rp_config_tree[0][3][1].text=str(screen_height) rp_config_tree[0][3][2].text=str(scene.objects['About']['quality']) - - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) + # Son : data/config/sound -> [0][1].text + rp_config_tree[0][1].text=str(scene.objects['Commands']['sound']) + # Vitesse du jeu : data/config/speed -> [0][0].text) + rp_config_tree[0][0].text=str(scene.objects['Commands']['speed']) + # Mission et level : data/mission/level -> [1][0].text, [1][1].text) + rp_config_tree[1][0].text=str(scene.objects['Points']['mission']) + rp_config_tree[1][1].text=str(scene.objects['Points']['level']) + config_save() # Sortir bge.logic.endGame() @@ -1039,7 +1035,6 @@ def tablet_open (): scene.objects['Commands'].setVisible(False,True) scene.active_camera = scene.objects["Camera-Hud"] scene.objects['Camera'].setVisible(False,True) - scene.objects['Doc-cmd-colbox'].suspendPhysics (True) # Ouvrir la tablette @@ -1055,9 +1050,8 @@ def tablet_close (): # Maj du fichier de config (mission actuelle : data/mission/current -> [1][0].text) rp_config_tree[1][0].text=str(scene.objects['Points']['mission']) - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) + print ("tablet close") + config_save() # Overlay scene.objects['Points'].setVisible(True,True) @@ -1234,16 +1228,9 @@ def task_close_click(cont): def upgrade_maj(): - # Read config (upgrades choisis : data/upgrade/ -> [2][i].text) - upgrade_card=("battery", "beacon", "paint", "speed") - scene.objects['Points']['upgrade_nb'] =0 - for i in range(len(upgrade_card)): - if rp_config_tree[2][i].text == "True": - scene.objects['Points']['upgrade_'+upgrade_card[i]]=True - scene.objects['Points']['upgrade_nb'] +=1 - scene.objects["Store-"+upgrade_card[i]+"-card"]['upgraded'] = True - scene.objects['Points']['upgrade_credit']= scene.objects['Points']['level']- 1 - scene.objects['Points']['upgrade_nb'] - + print ("upgrade_maj") + print ("speed : ", scene.objects['Points']['upgrade_speed']) + # Batterie if scene.objects['Points']['upgrade_battery'] : scene.objects['St-Panels-3'].setVisible(True,True) @@ -1294,7 +1281,6 @@ def store_open (): def store_close(): rp_store.close() scene.objects['Terrain']['manip_mode']=0 # Enlever la fenêtre modale - # Maj du fichier de config (upgrade : data/upgrade/i -> [2][i].text) upgrade_card=("battery", "beacon", "paint", "speed") for i in range(len(upgrade_card)): @@ -1302,9 +1288,8 @@ def store_close(): rp_config_tree[2][i].text="True" else: rp_config_tree[2][i].text="False" - buffer_xml = ET.tostring(rp_config_tree) - with open("rp_config.xml", "wb") as f: - f.write(buffer_xml) + print ("store close") + config_save() # Overlay scene.objects['Points'].setVisible(True,True) @@ -1351,7 +1336,6 @@ def store_close(): scene.objects['Task-cmd'].restorePhysics() scene.objects['Task-cmd-Hl'].setVisible(False,True) - # Maj de l'interface upgrade_maj() @@ -1372,6 +1356,10 @@ def store_close_click(cont): # Fichier ############################################################################### +## +# Sélectionner le fichier de commandes +## + def file_open(): # Terminer le processus file précédent @@ -1385,11 +1373,106 @@ def file_open(): else: # Qt5 ne s'installe pas bien sur Windows -> wxPython scene.objects['Commands']['file_proc'] = subprocess.Popen([sys.executable, os.path.join(os.getcwd(), "rp_file_wx.py")], stdout=subprocess.PIPE, encoding = 'utf8') + # Récupérer le nom du fchier stout = scene.objects['Commands']['file_proc'].communicate() if stout[0][:-1] != 'None': scene.objects['Commands']['script'] = stout[0][:-1] scene.objects['Script-text']['Text']=scene.objects['Commands']['script'] + config_load() +## +# Sauvegarder la configuration +## + +def config_save(): + buffer_xml = ET.tostring(rp_config_tree) + fichier_xml=os.path.join(os.path.split((scene.objects['Commands']['script']))[0], "rp_config.xml") + with open(fichier_xml, "wb") as f: + f.write(buffer_xml) + +## +# Chargement de la configuration +## + +def config_load(): + print ("config load") + fichier_xml=os.path.join(os.path.split((scene.objects['Commands']['script']))[0], "rp_config.xml") + rp_config2 = ET.parse(fichier_xml) + rp_config_tree2 = rp_config2.getroot() + print (rp_config_tree2[2][0].text) + print (rp_config_tree2[2][1].text) + print (rp_config_tree2[2][2].text) + print (rp_config_tree2[2][3].text) + + # Configuration de l'écran + bge.render.setWindowSize(int(rp_config_tree2[0][3][0].text),int(rp_config_tree2[0][3][1].text)) + quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA') + scene.objects['About']['quality'] = int(rp_config_tree2[0][3][2].text) + if quality_eevee[scene.objects['About']['quality']] == 'NOSMAA': + eevee.smaa_quality= 'LOW' + eevee.use_eevee_smaa = False + else: + eevee.use_eevee_smaa = True + eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']] + + # Init de la carte + # Read config (mission actuelle : data/mission/current -> [1][0].text) + scene.objects['Points']['mission']=int(rp_config_tree2[1][0].text) + rp_map.map_init() + scene.objects['Terrain']['thread_cmd']=False + rp_map.map_reset() + + # Récupération de la position de la caméra + scene.objects['Camera']['current_lx'] = float(rp_config_tree2[0][2][0].text) + scene.objects['Camera']['current_ly'] = float(rp_config_tree2[0][2][1].text) + scene.objects['Camera']['current_lz'] = float(rp_config_tree2[0][2][2].text) + scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['current_lx'] + scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['current_ly'] + scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['current_lz'] + + # UI : Sounds + # Read config (sound : data/config/sound -> [0][1].text) + if rp_config_tree2[0][1].text == "True": + sound_set () + else: + sound_unset () + # audiodev.unlock() + + # Missions + # Read config (mission actuelle : data/mission/current -> [1][0].text) + # Read config (niveau atteint : data/mission/level -> [1][1].text) + scene.objects['Points']['mission']=int(rp_config_tree2[1][0].text) + scene.objects['Points']['mission_init']= scene.objects['Points']['mission'] + scene.objects['Points']['level']=int(rp_config_tree2[1][1].text) + scene.objects['Points-Map-text']['Text']="Mission "+str(scene.objects['Points']['mission']) + scene.objects['Book_mission']['Text'] = "Mission en cours : "+str(scene.objects['Points']['mission']) + scene.objects['Book_level']['Text'] = "Niveau actuel : "+str(scene.objects['Points']['level']) + + # Upgrade + upgrade_card=("battery", "beacon", "paint", "speed") + scene.objects['Points']['upgrade_nb'] =0 + for i in range(len(upgrade_card)): + if rp_config_tree2[2][i].text == "True": + scene.objects['Points']['upgrade_'+upgrade_card[i]]=True + scene.objects['Points']['upgrade_nb'] +=1 + scene.objects["Store-"+upgrade_card[i]+"-card"]['upgraded'] = True + else: + scene.objects['Points']['upgrade_'+upgrade_card[i]]=False + scene.objects["Store-"+upgrade_card[i]+"-card"]['upgraded'] = False + scene.objects['Points']['upgrade_credit']= scene.objects['Points']['level']- 1 - scene.objects['Points']['upgrade_nb'] + upgrade_maj() + + # Speed + # Read config (game speed : data/config/speed -> [0][0].text) + speed_mode=[0.25, 0.5, 1,2,4,10] + speed_mode_txt=["1/4", "1/2", "1", "2","4","10"] + if scene.objects['Points']['upgrade_speed'] : + scene.objects['Commands']['speed']=float(rp_config_tree2[0][0].text) + else: + scene.objects['Commands']['speed']=1.00 + i=speed_mode.index(scene.objects['Commands']['speed']) + scene.objects['Text_speed']['Text']=speed_mode_txt[i] + ############################################################################### # About ############################################################################### @@ -1421,6 +1504,8 @@ def about_close(): scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['current_lx'] scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['current_ly'] scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['current_lz'] + print ("about close") + config_save() ## # Click pour fermer le about @@ -1430,79 +1515,3 @@ def about_close_click(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : sound_play (snd_close) about_close() - -# ## -# # Configuration de l'écran -# ## - -# def get_near_pos(array,value): -# array = np.asarray(array) -# idx = (np.abs(array-value)).argmin() -# return idx - -# def about_screen_up(cont): -# if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : -# screen_width_mode=[640, 960, 1280, 1920] -# screen_height_mode=[360, 540, 720,1080] -# screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"] -# i = get_near_pos(screen_width_mode, bge.render.getWindowWidth()) -# if i>=0 and i<3 : -# screen_width=screen_width_mode[i+1] -# screen_height=screen_height_mode[i+1] -# scene.objects['About_screen']['Text']= "SCREEN SIZE : "+str(screen_width) +" x "+str(screen_height) -# bge.render.setWindowSize(screen_width,screen_height) - -# # Boutons < et > -# if screen_width <=640: -# scene.objects['About_screen-down'].setVisible(False,True) -# scene.objects['About_screen-down-colbox'].suspendPhysics (True) -# else: -# scene.objects['About_screen-down'].setVisible(True,True) -# scene.objects['About_screen-down-colbox'].restorePhysics() -# if screen_width >= 1920: -# scene.objects['About_screen-up'].setVisible(False,True) -# scene.objects['About_screen-up-colbox'].suspendPhysics (True) -# else: -# scene.objects['About_screen-up'].setVisible(True,True) -# scene.objects['About_screen-up-colbox'].restorePhysics() - -# # Maj du fichier de config (screen size : data/config/screen/width-> [0][3][0].text) -# rp_config_tree[0][3][0].text=str(screen_width) -# rp_config_tree[0][3][1].text=str(screen_height) -# buffer_xml = ET.tostring(rp_config_tree) -# with open("rp_config.xml", "wb") as f: -# f.write(buffer_xml) - -# def about_screen_down(cont): -# if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : -# screen_width_mode=[640, 960, 1280, 1920] -# screen_height_mode=[360, 540, 720,1080] -# screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"] -# i = get_near_pos(screen_width_mode, bge.render.getWindowWidth()) -# if i>0 and i<=3 : -# screen_width=screen_width_mode[i-1] -# screen_height=screen_height_mode[i-1] -# scene.objects['About_screen']['Text']= "SCREEN SIZE : "+str(screen_width) +" x "+str(screen_height) -# bge.render.setWindowSize(screen_width,screen_height) - -# # Boutons < et > -# if screen_width <=640: -# scene.objects['About_screen-down'].setVisible(False,True) -# scene.objects['About_screen-down-colbox'].suspendPhysics (True) -# else: -# scene.objects['About_screen-down'].setVisible(True,True) -# scene.objects['About_screen-down-colbox'].restorePhysics() -# if screen_width >= 1920: -# scene.objects['About_screen-up'].setVisible(False,True) -# scene.objects['About_screen-up-colbox'].suspendPhysics (True) -# else: -# scene.objects['About_screen-up'].setVisible(True,True) -# scene.objects['About_screen-up-colbox'].restorePhysics() - -# # Maj du fichier de config (screen size : data/config/screen/width-> [0][3][0].text) -# rp_config_tree[0][3][0].text=str(screen_width) -# rp_config_tree[0][3][1].text=str(screen_height) -# buffer_xml = ET.tostring(rp_config_tree) -# with open("rp_config.xml", "wb") as f: -# f.write(buffer_xml) - diff --git a/rp_config.xml b/rp_config.xml index 670a9a1..a175395 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -8,8 +8,8 @@ 20.22315788269043 - 1632 - 918 + 1641 + 924 1 diff --git a/rp_file_qt.py b/rp_file_qt.py index 899e53a..6239008 100644 --- a/rp_file_qt.py +++ b/rp_file_qt.py @@ -3,9 +3,9 @@ from PyQt5 import QtWidgets from PyQt5.QtWidgets import QApplication, QFileDialog ############################################################################### -# twin_file_qt.py +# rp_file_qt.py # @title: Selecteur de fichier (pyQt5) -# @project: Blender-EduTech +# @project: Ropy (Blender-EduTech) # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2023 Philippe Roy diff --git a/rp_file_wx.py b/rp_file_wx.py index f956cc7..747fc3c 100644 --- a/rp_file_wx.py +++ b/rp_file_wx.py @@ -1,9 +1,9 @@ import wx ############################################################################### -# twin_file_wx.py +# rp_file_wx.py # @title: Selecteur de fichier (wxPython) -# @project: Blender-EduTech +# @project: Ropy (Blender-EduTech) # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2023 Philippe Roy @@ -19,4 +19,4 @@ openFileDialog = wx.FileDialog(frame, "Sélection du fichier de commande", "", " openFileDialog.ShowModal() print(openFileDialog.GetPath()) -openFileDialog.Destroy() \ No newline at end of file +openFileDialog.Destroy() diff --git a/rp_lib.py b/rp_lib.py index 979f60c..0ec18d5 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -952,6 +952,7 @@ def rover_goal (): # Level if scene.objects['Points']['mission']==scene.objects['Points']['level']: scene.objects['Points']['level']+=1 + scene.objects['Points']['level_new_flag']=True ## # Forage diff --git a/rp_map1.py b/rp_map1.py index 0767d75..9b26732 100644 --- a/rp_map1.py +++ b/rp_map1.py @@ -392,7 +392,8 @@ def objectif_control(x,y): def rp_cmd_txtcount (text_list, n): # print (os.getcwd()) - file = open('rp_cmd.py', 'r') + # file = open('rp_cmd.py', 'r') + file = open(scene.objects['Commands']['script'], 'r') file_txt = file.read() for text in text_list: if file_txt.count (text) >= n: