Bugfix : inspection du code par astroid, affichage du feuillage et affichage des forages

This commit is contained in:
Philippe Roy 2023-12-28 17:00:24 +01:00
parent 9fca493f2b
commit 14221c863c
9 changed files with 100 additions and 42 deletions

Binary file not shown.

Binary file not shown.

30
rp.py
View File

@ -10,9 +10,7 @@ import threading # Multithreading
import subprocess # Multiprocessus
import xml.etree.ElementTree as ET # Creating/parsing XML file
import runpy # Exécution de script Python légère (sans import)
# from pylint import epylint as lint # Mesure de la qualité d'un code Python
# from pylint import run_pylint # Mesure de la qualité d'un code Python
# from pylint.lint import Run as pylint_run
import astroid # Inspection de script Python (Pylint)
import rp_map1 as rp_map # Map definition
import rp_doc # Documentation
@ -235,7 +233,6 @@ def python_validation(file):
stout_lines = stout[0].split("\n")
for stout_line in stout_lines:
print ("Pylint :", stout_line) # Affichage console
return False
# Absence d'erreur
@ -244,6 +241,30 @@ def python_validation(file):
scene.objects['Cmd-text'].setVisible(False,False)
return True
##
# Inspection du code Python : détection des appels
#
# Call(func=<Name.rp_marquer l.1 at 0x7f0d137ebaf0>,
# args=[],
# keywords=[])
##
def python_inspect(file):
functions=[]
file_buff = open(file, 'r')
file_txt = file_buff.read()
file_lines= file_txt.split("\n")
for i in range (len(file_lines)):
try:
node = astroid.extract_node(file_lines[i])
# print (node)
if str(node).find ("Call(func=<Name.") > -1:
functions.append(str(node)[16:str(node).find ("l.1")-1])
except:
pass
file_buff.close()
return functions
##
# Exécuter le script
##
@ -286,6 +307,7 @@ def terrain_run ():
scene.objects['Rover']['stop'] = False
scene.objects['Points-Twins-text']['Text'] = "Connection fermée."
if python_validation(scene.objects['Commands']['script']):
scene.objects['Commands']['functions'] = python_inspect(scene.objects['Commands']['script'])
runpy.run_path(scene.objects['Commands']['script'], run_name='start') # Execution du script utilisateur
# Arrêt de la pause

View File

@ -425,6 +425,7 @@ def quality_apply(quality, start_flag=False):
eevee.use_volumetric_shadows = False
eevee.shadow_cascade_size='64'
eevee.shadow_cube_size='64'
bpy.data.particles["Feuillage"].count = 100
# scene.objects['terrain-scatter.001'].setVisible(False,True)
# scene.objects['terrain-scatter.002'].setVisible(False,True)
@ -441,6 +442,7 @@ def quality_apply(quality, start_flag=False):
eevee.use_volumetric_shadows = False
eevee.shadow_cascade_size='1024'
eevee.shadow_cube_size='512'
bpy.data.particles["Feuillage"].count = 100
# scene.objects['terrain-scatter.001'].setVisible(False,True)
# scene.objects['terrain-scatter.002'].setVisible(False,True)
@ -457,6 +459,7 @@ def quality_apply(quality, start_flag=False):
eevee.use_volumetric_shadows = False
eevee.shadow_cascade_size='1024'
eevee.shadow_cube_size='512'
bpy.data.particles["Feuillage"].count = 100
# scene.objects['terrain-scatter.001'].setVisible(True,True)
# scene.objects['terrain-scatter.002'].setVisible(True,True)
@ -473,6 +476,7 @@ def quality_apply(quality, start_flag=False):
eevee.use_volumetric_shadows = False
eevee.shadow_cascade_size='1024'
eevee.shadow_cube_size='512'
bpy.data.particles["Feuillage"].count = 500
# scene.objects['terrain-scatter.001'].setVisible(True,True)
# scene.objects['terrain-scatter.002'].setVisible(True,True)
@ -489,5 +493,6 @@ def quality_apply(quality, start_flag=False):
eevee.use_volumetric_shadows = True
eevee.shadow_cascade_size='4096'
eevee.shadow_cube_size='4096'
bpy.data.particles["Feuillage"].count = 1000
# scene.objects['terrain-scatter.001'].setVisible(True,True)
# scene.objects['terrain-scatter.002'].setVisible(True,True)

View File

@ -1,5 +1,4 @@
import time
import inspect
from rp_lib import * # Bibliothèque Ropy
###############################################################################
@ -26,18 +25,33 @@ from rp_lib import * # Bibliothèque Ropy
# Commandes
###############################################################################
def mrp_avancer():
pass
def commandes():
# print ("inspect :", inspect.isfunction(mrp_avancer()))
print ('Go go go ...')
# mrp_avancer()
# mrp_avancer()
# mrp_avancer()
print ('okok')
rp_gauche()
rp_avancer()
rp_avancer()
rp_droite()
for i in range (3):
while rp_detect()==False:
rp_avancer()
rp_marquer()
rp_droite()
while rp_detect()==False:
rp_avancer()
# rp_avancer()
# rp_droite()
# for i in range (4):
# rp_avancer()
# rp_marquer()
# rp_droite()
# for i in range (3):
# rp_avancer()
# rp_marquer()
rp_fin() # A garder

View File

@ -1,15 +1,15 @@
<data>
<config>
<speed>2.0</speed>
<speed>4.0</speed>
<sound>False</sound>
<cam>
<worldPosition.x>4.116782188415527</worldPosition.x>
<worldPosition.y>-39.253841400146484</worldPosition.y>
<worldPosition.z>29.45159339904785</worldPosition.z>
<worldPosition.x>-3.7522060871124268</worldPosition.x>
<worldPosition.y>-18.188343048095703</worldPosition.y>
<worldPosition.z>15.865280151367188</worldPosition.z>
</cam>
<screen>
<width>1599</width>
<height>900</height>
<width>1639</width>
<height>922</height>
<quality>4</quality>
</screen>
</config>
@ -18,9 +18,9 @@
<level>6</level>
</mission>
<upgrade>
<battery>False</battery>
<beacon>False</beacon>
<paint>False</paint>
<battery>True</battery>
<beacon>True</beacon>
<paint>True</paint>
<speed>True</speed>
</upgrade>
</data>

View File

@ -281,9 +281,14 @@ def rp_avancer (twins=True):
scene.objects['Rv-Wheel-left-front'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
scene.objects['Rv-Wheel-left-mid'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
scene.objects['Rv-Wheel-left-rear'].playAction('Wheel-Avancer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
while scene.objects['Rv-Wheel-right-front'].isPlayingAction(): # Forçage du redraw
# scene.objects['Camera'].applyMovement((0, 0, 0), True)
scene.objects['Sun'].applyMovement((0, 0, 0), True)
# Forçage du redraw
while scene.objects['Rv-Wheel-right-front'].isPlayingAction():
rp_sleep(0.1)
# rp_tempo (0.1)
# # pass
# # scene.objects['Camera'].applyMovement((0, 0, 0), True)
# scene.objects['Sun'].applyMovement((0, 0, 0), True)
rp_tempo (0.1)
# Contrôle objectif
@ -829,7 +834,7 @@ def rover_colision_montain (back):
scene.objects['Rv-Wheel-left-rear'].playAction('Wheel-Reculer', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
# Forçage du redraw
while scene.objects['Rv-Wheel-right-front'].isPlayingAction(): # Forçage du redraw
while scene.objects['Rv-Wheel-right-front'].isPlayingAction():
scene.objects['Sun'].applyMovement((0, 0, 0), True)
rp_tempo (0.1)
return True

View File

@ -1,9 +1,9 @@
import bge # Bibliothèque Blender Game Engine (UPBGE)
import bpy # Blender
import random
import inspect
from rp_lib import * # Bibliothèque Ropy
import os
import runpy # Exécution de script Python légère (sans import)
###############################################################################
# rp_map1.py
@ -153,18 +153,15 @@ def map_init():
filename=object_name)
scene.objects['Terrain']['size'] = [-15,-11,15,10] # Map size
scene.objects['Terrain-plane'].setVisible(False,True) # Plan de conception (Blender)
scene.objects['Terrain']['map_tile_station']= [[-9,2],[-9,3]]
# Détection des emplacements des colisions de montagne
# scene.objects['Terrain']['map_tile_montain']= []
# for obj_i in scene.objects:
# if "terrain_sideCliff" in obj_i.name or "terrain_sideCorner" in obj_i.name or "terrain_sideCornerInner" in obj_i.name:
# scene.objects['Terrain']['map_tile_montain'].append([round(obj_i.worldPosition.x), round(obj_i.worldPosition.y)])
# Montagne
scene.objects['Terrain']['map_tile_montain'] = [[-9, -1], [1, -9], [-14, -8], [-12, -10], [-11, -10], [-10, -10], [-9, -10], [-11, 1], [-14, 3], [-14, 4], [-14, -7], [-12, 1], [2, -7], [-12, 10],
[-11,10], [-10, 10], [-9, 10], [-8, 10], [-4, 7], [-2, 6], [4, 10], [5, 10], [1, 8], [2, -6], [6, 10], [7, 10], [8, 10], [9, 10], [10, 10], [11, 10],
[14,7], [-14, -1], [13, 8], [-14, 0], [-14, -2], [8, -1], [-15, -7], [-15, -8], [-15, -9], [-15, -6], [-8, -10], [-7, -10], [10, -1], [15, 5], [11, -1],
[14, 9], [15, 10], [12, -1], [4, -9], [5, -9], [6, -9], [3, -10], [7, -10], [-14, -11], [-6, -11], [3, -11], [7, -11], [0, -11], [0, 1], [-1, 0], [13, 7],
[13, 6], [13, 5], [1, 1], [0, -1], [14, 10], [13, 9], [14, 8], [14, 6], [12, 10], [15, 9], [15, 3], [9, -1], [7, -1], [15, 8], [15, 7], [6, -1], [2, -5],
[14, 9], [15, 10], [12, -1], [4, -9], [5, -9], [6, -9], [3, -10], [7, -10], [-14, -11], [-6, -11], [3, -11], [7, -11], [0, -11], [13, 7],
[13, 6], [13, 5], [14, 10], [13, 9], [14, 8], [14, 6], [12, 10], [15, 9], [15, 3], [9, -1], [7, -1], [15, 8], [15, 7], [6, -1], [2, -5],
[2, -4], [2, -3], [2, -2], [5, -1], [4, -1], [3, -1], [3, 10], [-1, 6], [0, -10], [-13, -9], [1, -8], [-12, -3], [-9, -2], [-12, -5], [-13, -6], [-13, 5],
[-13, 6], [-14, 8], [-13, 2], [-10, -3], [-13, 9], [-7, 9], [-14, 7], [-6, 8], [-5, 7], [-3, 6], [0, 6], [1, 7], [2, 9], [-10, 1], [-9, 0], [-15, 2],
[-14,1], [-14, -10], [-14, -5], [-13, -4], [-13, -3], [2, -1], [13, 4], [14, 3], [15, 6], [13, -1], [14, -2], [-6, -10], [15, -3], [14, 5], [3, -9],
@ -174,6 +171,18 @@ def map_init():
[2,10], [2, 10], [13, 10], [13, 10], [13, -2], [13, -2], [-15, -10], [-15, -10], [1, -10], [1, -10], [-15, 1], [-15, 1], [-15, -5], [-15, -5], [-14, -4],
[-14, -4], [-14, -3], [-14, -3], [-15, 8], [-15, 8], [14, 4], [14, 4], [-15, 7], [-15, 7], [2, -8], [2, -8]]
# Visualisation des cases montagne
# for i in range (len (scene.objects['Terrain']['map_tile_montain'])):
# beacon_montain= scene.addObject("Beacon", scene.objects['Terrain'])
# beacon_montain.worldPosition=[scene.objects['Terrain']['map_tile_montain'][i][0],scene.objects['Terrain']['map_tile_montain'][i][1],0.2]
# beacon_montain.setVisible(True,True)
# Détection des emplacements des colisions de montagne
# scene.objects['Terrain']['map_tile_montain']= []
# for obj_i in scene.objects:
# if "terrain_sideCliff" in obj_i.name or "terrain_sideCorner" in obj_i.name or "terrain_sideCornerInner" in obj_i.name:
# scene.objects['Terrain']['map_tile_montain'].append([round(obj_i.worldPosition.x), round(obj_i.worldPosition.y)])
# Couleurs
rp_couleur_init()
@ -351,10 +360,14 @@ def objectif_control(x,y):
# Mission 2 (fonction)
if scene.objects['Points']['mission']==2:
if [x,y] in scene.objects['Terrain']['map_aim']: # Aim
# print ("Objectif : ok")
if len(scene.objects['Terrain']['map_tile_beacon'])>=6: # 6 balises posées mini
# print ("6 balises posées : ok")
if scene.objects['Points']['nbligne'] <=40: # 40 lignes de code maxi
txt=["def mrp_avancer():", "def mrp_avancer() :", "def mrp_avancer ():", "def mrp_avancer () :"] # Présence de "def mrp_avancer():"
if rp_cmd_txtcount(txt, 1):
# print ("40 lignes de code maxi : ok")
# print (scene.objects['Commands']['functions'])
if scene.objects['Commands']['functions'].count("mrp_avancer")>=3: # Au moins 3 appels de "mrp_avancer()"
# print ("Fonction mrp_avancer : ok")
return True
# Mission 3 (structure alternative)
@ -370,8 +383,7 @@ def objectif_control(x,y):
if rp_cmd_txtcount(txt, 2):
return True
else:
txt=["def mrp_avancer_nbpas"] # Présence de "def mrp_avancer_nbpas"
if rp_cmd_txtcount(txt, 1):
if scene.objects['Commands']['functions'].count("mrp_avancer_nbpas")>=2: # Au moins 2 appels de "mrp_avancer_nbpas()"
txt=["for" ] # Présence de "for i in range" 1x
if rp_cmd_txtcount(txt, 1):
txt=["in range" ]
@ -386,8 +398,7 @@ def objectif_control(x,y):
if rp_cmd_txtcount(txt, 2):
return True
else:
txt=["def mrp_avancer_mur():", "def mrp_avancer_mur() :", "def mrp_avancer_mur ():", "def mrp_avancer_mur () :"] # Présence de "def mrp_avancer_mur():"
if rp_cmd_txtcount(txt, 1):
if scene.objects['Commands']['functions'].count("mrp_avancer_mur")>=2: # Au moins 2 appels de "mrp_avancer_mur()"
txt=["while" ] # Présence de "while" 1x
if rp_cmd_txtcount(txt, 1):
return True
@ -396,13 +407,12 @@ def objectif_control(x,y):
if scene.objects['Points']['mission']==6:
if [x,y] in scene.objects['Terrain']['map_aim']: # Cibles
if [x,y] not in scene.objects['Terrain']['map_aim_hit']: # Cibles atteintes
rover_drill(x,y)
scene.objects['Terrain']['map_aim_hit'].append([x,y])
if len (scene.objects['Terrain']['map_aim_hit'])==10 : # Toutes les cibles atteintes
return True
# Objectif pas atteint
return False

View File

@ -14,6 +14,8 @@ from pylint import run_pylint
# print (sys.argv[0])
# print (sys.argv[1])
# run_pylint(argv=["--version"])
# Détection des erreurs
run_pylint(argv=["--errors-only", sys.argv[1]])
# run_pylint(argv=["--disable=line-too-long", sys.argv[1]])
sys.exit(0)