Commit 6b969ee4 authored by alban's avatar alban

Added a functionnality to replace null field by their default value.

parent c2e05825
# This file defines global variables to describe a sign, as so as functions to
# load a sign from a file or to write it.
extends Node
onready var shapeList = preload("res://resources/pictures/body/hand-shapes/shapes.tres")
......@@ -6,9 +9,9 @@ var sName # the name of the sign (a string)
var hands # the number of hands (1 or 2)
var symType # null or 3 letters : H|V - G|C|D - A|C
var NDHmove # In case of a 2-hands sign, true if the dominated hand moves.
var shape
var DHanimShape # Same as shapeName[0], should be removed later.
var NDHanimShape # Same as shapeName[1], should be removed later.
var shape # ???
var DHanimShape # Same as shapeName[DH_INIT], should be removed later.
var NDHanimShape # Same as shapeName[NDH_INIT], should be removed later.
# Some parameters are defined by arrays of size 4. The meaning of the
# indices are:
......@@ -22,7 +25,7 @@ const NDH_FINAL = 3
# The following variables are arrays of size 4. Look at the previous constants
# the signification of which fields.
var shapeName
var bodyPart
var bodyPart # TODO: move it in another file, as it is not used here
var distance
var palmOr
var ftOr
......@@ -35,6 +38,15 @@ var traj
var inRepNum # the number of inner repetitions, in { 1 ; 1.5 ; 2 ; 2.5 ; 3 }
var outRepNum # the number of outter repetitions, in { 1 ; 1.5 ; 2 ; 2.5 ; 3 }
# The default values for different parameters:
const DEFAULT_TRAJECTORY = "straight"
const DEFAULT_REP_NUM = 1
const DEFAULT_DISTANCE = 1
const DEFAULT_SHAPE = "moufle"
const DEFAULT_PLACEMENT = "left breast"
const DEFAULT_REF_POINT = "palm"
const DEFAULT_ORIENTATION = [0, 0, 0]
var state # 0 for initial and 1 for final
var handState
var index
......@@ -52,7 +64,7 @@ var FacialUnit
func init():
"""Initialize the global variables to default values."""
"""Initialize the global variables to null."""
sName = null
hands = 2
symType = null
......@@ -71,7 +83,7 @@ func init():
same = false
traj = null
inRepNum = null
outRepNum = null # in { 1 ; 1.5 ; 2 ; 2.5 ; 3 }
outRepNum = null
state = 0
handState = 0
......@@ -113,8 +125,8 @@ func createSign():
if NDHmove == null or !NDHmove:
HandUnit[NDH_FINAL] = null
InitialState = {
NDH = HandUnit[NDH_FINAL],
DH = HandUnit[NDH_INIT]
NDH = HandUnit[NDH_INIT],
DH = HandUnit[DH_INIT]
}
FinalState = {
......@@ -182,8 +194,9 @@ func readSign():
handRefPoint[DH_INIT] = the_sign.InitialState.DH.Location.refPoint
placement[DH_INIT] = the_sign.InitialState.DH.Location.place
distance[DH_INIT] = the_sign.InitialState.DH.Location.distance
palmOr[DH_INIT] = [0,0,0]
if the_sign.InitialState.DH.Orientation.palm != null:
palmOr[DH_INIT] = [0,0,0]
palmOr[DH_INIT][0] = the_sign.InitialState.DH.Orientation.palm.r
palmOr[DH_INIT][1] = the_sign.InitialState.DH.Orientation.palm.f
palmOr[DH_INIT][2] = the_sign.InitialState.DH.Orientation.palm.u
......@@ -201,9 +214,9 @@ func readSign():
handRefPoint[DH_FINAL] = the_sign.FinalState.DH.Location.refPoint
placement[DH_FINAL] = the_sign.FinalState.DH.Location.place
distance[DH_FINAL] = the_sign.FinalState.DH.Location.distance
palmOr[DH_FINAL] = [0,0,0]
ftOr[DH_FINAL] = [0,0,0]
if the_sign.FinalState.DH.Orientation.palm != null:
palmOr[DH_FINAL] = [0,0,0]
ftOr[DH_FINAL] = [0,0,0]
palmOr[DH_FINAL][0] = the_sign.FinalState.DH.Orientation.palm.r
palmOr[DH_FINAL][1] = the_sign.FinalState.DH.Orientation.palm.f
palmOr[DH_FINAL][2] = the_sign.FinalState.DH.Orientation.palm.u
......@@ -224,13 +237,15 @@ func readSign():
handRefPoint[NDH_INIT] = the_sign.InitialState.NDH.Location.refPoint
placement[NDH_INIT] = the_sign.InitialState.NDH.Location.place
distance[NDH_INIT] = the_sign.InitialState.NDH.Location.distance
palmOr[NDH_INIT] = [0,0,0]
if the_sign.InitialState.NDH.Orientation.palm != null:
palmOr[NDH_INIT] = [0,0,0]
palmOr[NDH_INIT][0] = the_sign.InitialState.NDH.Orientation.palm.r
palmOr[NDH_INIT][1] = the_sign.InitialState.NDH.Orientation.palm.f
palmOr[NDH_INIT][2] = the_sign.InitialState.NDH.Orientation.palm.u
ftOr[NDH_INIT] = [0,0,0]
if the_sign.InitialState.NDH.Orientation.fingertips != null:
ftOr[NDH_INIT] = [0,0,0]
ftOr[NDH_INIT][0] = the_sign.InitialState.NDH.Orientation.fingertips.r
ftOr[NDH_INIT][1] = the_sign.InitialState.NDH.Orientation.fingertips.f
ftOr[NDH_INIT][2] = the_sign.InitialState.NDH.Orientation.fingertips.u
......@@ -243,13 +258,15 @@ func readSign():
handRefPoint[NDH_FINAL] = the_sign.FinalState.NDH.Location.refPoint
placement[NDH_FINAL] = the_sign.FinalState.NDH.Location.place
distance[NDH_FINAL] = the_sign.FinalState.NDH.Location.distance
palmOr[NDH_FINAL] = [0,0,0]
if the_sign.FinalState.NDH.Orientation.palm != null:
palmOr[NDH_FINAL] = [0,0,0]
palmOr[NDH_FINAL][0] = the_sign.FinalState.NDH.Orientation.palm.r
palmOr[NDH_FINAL][1] = the_sign.FinalState.NDH.Orientation.palm.f
palmOr[NDH_FINAL][2] = the_sign.FinalState.NDH.Orientation.palm.u
ftOr[NDH_FINAL] = [0,0,0]
if the_sign.FinalState.NDH.Orientation.fingertips != null:
ftOr[NDH_FINAL] = [0,0,0]
ftOr[NDH_FINAL][0] = the_sign.FinalState.NDH.Orientation.fingertips.r
ftOr[NDH_FINAL][1] = the_sign.FinalState.NDH.Orientation.fingertips.f
ftOr[NDH_FINAL][2] = the_sign.FinalState.NDH.Orientation.fingertips.u
......@@ -258,6 +275,64 @@ func readSign():
print("No such file in the directory")
return(false)
func fillDefaultArray(array, default, symmetry):
"""Given an array of 4 elements, fill the values with a default value.
If the argument symmetry is set to the string "left-right", the dominant
hand parameter is set to the symmetric of the dominated hand parameter."""
if array[NDH_INIT] == null:
array[NDH_INIT] = default
if array[NDH_FINAL] == null:
array[NDH_FINAL] = array[NDH_INIT]
if array[DH_INIT] == null:
if symmetry == "left-right":
# array[NDH_INIT] should be a placement. We should replace it by its
# symmetric. To do so, we just need to replace the first "left" by "right"
# and conversly.
if array[NDH_INIT].find("left") == 0:
array[DH_INIT] = array[NDH_INIT].replace("left", "right")
elif array[NDH_INIT].find("right") == 0:
array[DH_INIT] = array[NDH_INIT].replace("right", "left")
else:
array[NDH_INIT] = array[DH_INIT]
else:
array[NDH_INIT] = array[DH_INIT]
if array[DH_FINAL] == null:
array[DH_FINAL] = array[DH_INIT]
func fillDefaultValues():
"""Fill the fields to null to their default value, according to the format.
"""
# TODO: give a default value to "NDH_MOVE"
fillDefaultArray(shapeName, DEFAULT_SHAPE, null)
fillDefaultArray(distance, DEFAULT_DISTANCE, null)
fillDefaultArray(palmOr, DEFAULT_ORIENTATION, null)
fillDefaultArray(ftOr, DEFAULT_ORIENTATION, null)
fillDefaultArray(handRefPoint, DEFAULT_REF_POINT, null)
fillDefaultArray(placement, DEFAULT_PLACEMENT, "left-right")
if inRepNum == null:
inRepNum = DEFAULT_REP_NUM
if outRepNum == null:
outRepNum = DEFAULT_REP_NUM
if traj == null:
traj = DEFAULT_TRAJECTORY
DHanimShape = shape[DH_INIT]
NDHanimShape = shape[NDH_INIT]
# Did I forget anything?
# some functions to test the replacement by default values.
func _ready():
yaml = preload("res://addons/godot-yaml/gdyaml.gdns").new()
init()
\ No newline at end of file
init()
test()
func test():
sName = "Personne"
readSign()
signDescription = createSign()
var text = yaml.print(signDescription)
print("Initial YAML file:\n%s" % text)
fillDefaultValues()
signDescription = createSign()
text = yaml.print(signDescription)
print("\nAfter default values:\n%s" % text)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment