Bugfix : affichage du texte de la documentation : mise en cache du texte

This commit is contained in:
Philippe Roy 2022-11-25 18:51:13 +01:00
parent c3811494ac
commit a01f0c1195
8 changed files with 9 additions and 103 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

112
rp_doc.py
View File

@ -1,7 +1,6 @@
import bge # Bibliothèque Blender Game Engine (UPBGE)
import rp_map1 # Map definition
import webbrowser
import time
###############################################################################
# rp_doc.py
@ -259,7 +258,6 @@ def init():
# Chargement du texte
text_load()
text_load2()
# Mémorisation de la position des pages
chap=("general", "missions", "rover", "python")
@ -282,6 +280,7 @@ 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()
# Placer le nouveau chapitre
name_chap = scene.objects['Doc']['page_chap']
@ -290,9 +289,6 @@ def open():
scene.objects['Doc_chap-'+name_chap].worldPosition = scene.objects['Doc'].worldPosition
scene.objects['Doc_chap-'+name_chap].setVisible(True,True)
# scene.objects['Doc_text-l1-forward-card'].setVisible(True, False)
# scene.objects['Doc_text-l1-ref'].setVisible(True, False)
# Affichage ou pas du bouton de selection de la mission
if name_chap == "missions":
name_fct = scene.objects['Doc_chap-missions']['page_fct']
@ -339,53 +335,6 @@ def open():
scene.objects['Doc_title'].setVisible(False,True)
text_hide()
scene.objects['Doc_text-l1-ref'].setVisible(True, False)
print (scene.objects['Doc_text-l1-forward-card']['Text'])
scene.objects['Doc_text-l1-forward-card'].setVisible(True, False)
scene.objects['Doc_text-l1-forward-card'].worldPosition.x = scene.objects['Doc_text-l1-ref'].worldPosition.x
scene.objects['Doc_text-l1-forward-card'].worldPosition.y = scene.objects['Doc_text-l1-ref'].worldPosition.y
scene.objects['Doc_text-l1-forward-card'].worldPosition.z = scene.objects['Doc_text-l1-ref'].worldPosition.z
# text_load2()
# scene.objects['Doc_text-l1-forward-card']['text_def']= scene.objects['Doc_text-l1-forward-card']['Text']
# scene.objects['Doc_text-l1-forward-card']['redraw']=True
# print (scene.objects['Doc_text-l1-forward-card']['Text'])
# old_text=scene.objects['Doc_text-l1-forward-card']['Text']
# print (old_text)
# scene.objects['Doc_text-l1-forward-card']['Text']="eeee"
# scene.objects['Doc_text-l1-forward-card']['Text']=old_text
# scene.objects['Doc_text-l1-forward-card']['Text']=" rp_avancer()"
# scene.objects['Doc_text-l1-forward-card']['Text']=old_text
# doc_tempo (0.1)
# scene.objects['Doc_text-l1-forward-card'].setVisible(False, False)
# rp_tempo(0.1)
# scene.objects['Doc_text-l1-forward-card'].setVisible(False, False)
# scene.objects['Doc_text-l1-forward-card']['Text']="eeee"
def text_redraw(cont):
print ("text_redraw")
obj = cont.owner
print (obj['text_def'] +":" + obj['Text'])
obj['Text']= obj['text_def']
obj.setVisible(True, False)
print (obj['Text'])
scene.objects['Doc_text-l1-forward-card']['redraw']=False
scene.objects['Doc_text-l1-sleep-card']['Text']="rr"
# scene.objects['Doc_text-l1-forward-card']['Text']="eeee"
# if card is None:
# for card in card_description:
# print ("hide:", card)
# for i in range (13):
# scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(False, False)
# else:
# print ("hide:", card)
# for i in range (13):
# scene.objects['Doc_text-l'+str(i+1)+'-'+card].setVisible(False, False)
##
# Fermeture du livre
##
@ -490,6 +439,8 @@ def chapter(cont):
scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']].worldPosition.x = scene.objects["Doc_chap-"+scene.objects['Doc']['page_chap']]['init_lx']
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'])
# Placer le nouveau chapitre
name_chap= obj.name[4:-7]
@ -552,11 +503,9 @@ def chapter(cont):
def text_hide(card=None):
if card is None:
for card in card_description:
print ("hide:", card)
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(False, False)
else:
print ("hide:", card)
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+card].setVisible(False, False)
@ -567,41 +516,23 @@ def text_hide(card=None):
def text_show(card=None):
if card is None:
for card in card_description:
# print ("show:", card)
for i in range (13):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].setVisible(True, False)
else:
# print ("show:", card)
lines = card_description[card][1].split("\n")
for i in range (13):
# print ("show avant:", scene.objects['Doc_text-l'+str(i+1)+'-'+card].name, scene.objects['Doc_text-l'+str(i+1)+'-'+card]['Text'])
if i >= len(lines):
text=""
else:
if len(lines[i]) ==0:
text=""
else:
text=lines[i]
# if scene.objects['Doc_text-l'+str(i+1)+'-'+card]['Text'] != text:
# scene.objects['Doc_text-l'+str(i+1)+'-'+card]['Text'] = text
print ("text", text)
# text="hh"
idcard="Doc_text-l"+str(i+1)+"-"+card
scene.objects[idcard]['Text'] = str(text)
scene.objects[idcard].setVisible(True, False)
# print ("show après:", scene.objects['Doc_text-l'+str(i+1)+'-'+card].name, scene.objects['Doc_text-l'+str(i+1)+'-'+card]['Text'])
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'] = ""
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:
print ("create:", card)
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'])
@ -612,13 +543,6 @@ def text_load():
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)
print ("create:", doc_text.name)
def text_load2():
for card in card_description:
lines = card_description[card][1].split("\n")
print ("load:", lines)
for i in range (13):
if i >= len(lines):
scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text']=""
else:
@ -626,8 +550,6 @@ def text_load2():
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)]['Text']=str(card)
print ("load:", scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)].name, scene.objects['Doc_text-l'+str(i+1)+'-'+str(card)]['Text'])
##
# Afficher les details de la fonction à partir d'une carte
@ -643,7 +565,8 @@ 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'])
# Placer la carte de la mission active
if scene.objects['Doc_chap-'+name_chap]['page_fct'] == "mission_"+str(scene.objects['Points']['mission'])+"-card":
scene.objects[scene.objects['Doc_chap-'+name_chap]['page_fct']].color = color_doc_mission
@ -732,23 +655,6 @@ def upgrade_talk (card):
else:
return ""
###############################################################################
# Temporisation
###############################################################################
# Temporisation basée sur l'horloge de l'OS
def doc_sleep (duration):
time.sleep(duration)
# Temporisation basée par l'horloge de UPBGE
def doc_tempo (duration):
# time.sleep(duration*(1/scene.objects['Commands']['speed']))
scene.objects['Commands']['time']=0
while scene.objects['Commands']['time']<duration*(1/scene.objects['Commands']['speed']):
print (scene.objects['Commands']['time'])
# time.sleep(0.001)
###############################################################################
# Sounds
###############################################################################