Bugfix : génération du texte de l'aide par bpy (non par bge)

This commit is contained in:
Philippe Roy 2023-02-16 15:04:18 +01:00
parent aecb2c9085
commit ac6f90d245
3 changed files with 84 additions and 67 deletions

Binary file not shown.

View File

@ -8,8 +8,8 @@
<worldPosition.z>20.22315788269043</worldPosition.z>
</cam>
<screen>
<width>784</width>
<height>441</height>
<width>1557</width>
<height>875</height>
<quality>4</quality>
</screen>
</config>

147
rp_doc.py
View File

@ -246,7 +246,7 @@ rp_python_text=""" Python est un langage de \n programmation interprété open s
Python vise à être visuellement épuré \n avec une syntaxe clairement séparée \n des mécanismes de bas niveau.\n
Python possède beaucoup de \n bibliothèques spécialisées.
Multiplateformes et multiparadigme,
il est utilisé dans de nombreux \n contextes : scriptage, calcul numérique, \n prototypage, enseignement, ou encore \n comme langage de commande \n pour de nombreux logiciels."""
il est utilisé dans de nombreux \n contextes : scriptage, prototypage, \n calcul numérique, enseignement, ou \n encore comme langage de commande."""
rp_python_url=[["python.org","https://python.org"], ["AFPy","https://www.afpy.org"]]
card_description.update({"python-card" : [rp_python_title, rp_python_text, rp_python_url]})
@ -291,7 +291,8 @@ def init():
scene.objects["mission_"+str(scene.objects['Points']['mission'])+"-card-text"].color = color_doc_mission
# Chargement du texte
text_load()
# text_load()
text_dynamic_load() # en dynamique
# Mémorisation de la position des pages
for page in chap:
@ -313,7 +314,8 @@ def open():
scene.objects['Doc'].worldPosition = [0, -21, 15.8]
scene.objects['Doc_close'].color = color_doc_chap
scene.objects['Doc'].setVisible(True,True)
text_hide()
# text_hide()
text_dynamic_hide()
# Placer le nouveau chapitre
name_chap = scene.objects['Doc']['page_chap']
@ -362,11 +364,13 @@ def open():
name_fct = scene.objects['Doc_chap-'+name_chap]['page_fct']
scene.objects['Doc_title']['Text'] = card_description[name_fct][0]
scene.objects['Doc_title'].setVisible(True, False)
text_show(name_fct)
text_dynamic_show(name_fct)
# text_show(name_fct)
else:
scene.objects['Doc_title']['Text'] = " "
scene.objects['Doc_title'].setVisible(False,True)
text_hide()
text_dynamic_hide()
# text_hide()
##
# Fermeture du livre
@ -473,7 +477,8 @@ def chapter(cont):
scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']].worldPosition.y = scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['init_ly']
scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']].worldPosition.z = scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['init_lz']
if scene.objects['Doc']['page_chap'] != "general" and scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['page_fct'] !="":
text_hide(scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['page_fct'])
# text_hide(scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['page_fct'])
text_dynamic_hide(scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['page_fct'])
# Placer le nouveau chapitre
name_chap= obj.name[4:-7]
@ -523,66 +528,13 @@ def chapter(cont):
name_fct = scene.objects['Doc_chap-'+name_chap]['page_fct']
scene.objects['Doc_title']['Text'] = card_description[name_fct][0]
scene.objects['Doc_title'].setVisible(True, False)
text_show(name_fct)
text_dynamic_show(name_fct)
# text_show(name_fct)
else:
scene.objects['Doc_title']['Text'] = " "
scene.objects['Doc_title'].setVisible(False,True)
text_hide()
##
# Cacher le texte
##
def text_hide(card=None):
if card is None:
for card in card_description:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(False, False)
else:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+card].setVisible(False, False)
##
# Afficher le texte
##
def text_show(card=None):
if card is None:
for card in card_description:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(True, False)
else:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+card].setVisible(True, False)
##
# Préchargement des textes
##
def text_load():
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-ref']['Text'] = ""
# Création des objets 3D
for card in card_description:
lines = card_description[card][1].split("\n")
for i in range (13):
doc_text= scene.addObject('Doc_text-l'+str(i+1), None, 0.00, True)
# doc_text= scene.addObject('Doc_text-l'+str(i+1), scene.objects['Terrain'])
# doc_text= scene.addObject('Doc_text-l'+str(i+1), scene.objects['Doc'] )
doc_text.setParent(scene.objects['Doc'])
doc_text.name = 'Doc_text-l'+str(i+1)+'-'+str(card)
doc_text.worldPosition.x = scene.objects['Doc_text-l'+str(i+1)+'-ref'].worldPosition.x
doc_text.worldPosition.y = scene.objects['Doc_text-l'+str(i+1)+'-ref'].worldPosition.y
doc_text.worldPosition.z = scene.objects['Doc_text-l'+str(i+1)+'-ref'].worldPosition.z
doc_text.setVisible(False, False)
if i >= len(lines):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=""
else:
if len(lines[i]) ==0:
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=""
else:
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=lines[i]
text_dynamic_hide()
# text_hide()
##
# Afficher les details de la fonction à partir d'une carte
@ -598,7 +550,9 @@ def card (cont):
# Enlever l'ancienne carte
if scene.objects['Doc_chap-'+name_chap]['page_fct'] !="":
text_hide(scene.objects['Doc_chap-'+name_chap]['page_fct'])
# text_dynamic_hide(name_old_fct)
# text_hide(scene.objects['Doc_chap-'+name_chap]['page_fct'])
text_dynamic_hide(scene.objects['Doc_chap-'+name_chap]['page_fct'])
# Placer la carte de la mission active
if scene.objects['Doc_chap-'+name_chap]['page_fct'] == "mission_"+str(scene.objects['Points']['mission'])+"-card":
@ -617,7 +571,8 @@ def card (cont):
scene.objects[name_fct+'-text'].color = color_doc_activate
scene.objects['Doc_title']['Text'] = card_description[name_fct][0]
scene.objects['Doc_title'].setVisible(True, False)
text_show(name_fct)
# text_show(name_fct)
text_dynamic_show(name_fct)
# URL Python
if name_chap == "python":
@ -670,6 +625,68 @@ def python_link (cont):
i= cont.owner.name[15:-7]
webbrowser.open(card_description[name_fct][2][int(i)][1])
###############################################################################
# Génération dynamique des pages
###############################################################################
##
# Cacher le texte
##
def text_dynamic_hide(card=None):
if card is None:
for card in card_description:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(False, False)
else:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+card].setVisible(False, False)
##
# Afficher le texte
##
def text_dynamic_show(card=None):
if card is None:
for card in card_description:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(True, False)
else:
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+card].setVisible(True, False)
##
# Préchargement des textes
##
def text_dynamic_load():
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-ref']['Text'] = ""
# Création des objets 3D
for card in card_description:
lines = card_description[card][1].split("\n")
for i in range (13):
doc_text= scene.addObject('Doc_text-l'+str(i+1), None, 0.00, True)
doc_text.setParent(scene.objects['Doc'])
doc_text.name = 'Doc_text-l'+str(i+1)+'-'+str(card)
doc_text.worldPosition.x = scene.objects['Doc_text-l'+str(i+1)+'-ref'].worldPosition.x
doc_text.worldPosition.y = scene.objects['Doc_text-l'+str(i+1)+'-ref'].worldPosition.y
doc_text.worldPosition.z = scene.objects['Doc_text-l'+str(i+1)+'-ref'].worldPosition.z
doc_text.setVisible(False, False)
if i >= len(lines):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=""
else:
if len(lines[i]) ==0:
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=""
else:
# scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=lines[i]
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].blenderObject.data.body=lines[i] # Bug de la propriétés 'Text' (UPBGE) -> passage par 'body' de bpy (Blender)
###############################################################################
# Store
###############################################################################
##
# Texte pour le store
##