Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathieu Loiseau
MagicWord
Commits
e65f684e
Commit
e65f684e
authored
May 27, 2019
by
Arnaud Bey
Browse files
WIP fixing objectives JS
parent
b4e4bc67
Changes
4
Hide whitespace changes
Inline
Side-by-side
application/src/MagicWordBundle/Entity/ObjectiveType/Constraint.php
View file @
e65f684e
...
...
@@ -64,7 +64,6 @@ class Constraint extends Objective
'type'
=>
$this
->
discr
,
'numberToFind'
=>
$this
->
numberToFind
,
'features'
=>
$this
->
feature
?
$this
->
feature
->
getId
()
:
null
,
);
return
$jsonArray
;
...
...
application/src/MagicWordBundle/Entity/Round.php
View file @
e65f684e
...
...
@@ -283,17 +283,15 @@ class Round implements \JsonSerializable
];
}
foreach
(
$this
->
getConstraints
()
as
$constraint
)
{
$jsonArray
[
'constraints'
][]
=
[
'id'
=>
$constraint
->
getId
(),
'numberToFind'
=>
$constraint
->
getNumberToFind
(),
'category'
=>
$constraint
->
getCategory
()
?
$constraint
->
getCategory
()
->
getId
()
:
null
,
'gender'
=>
$constraint
->
getGender
()
?
$constraint
->
getGender
()
->
getId
()
:
null
,
'number'
=>
$constraint
->
getNumber
()
?
$constraint
->
getNumber
()
->
getId
()
:
null
,
'tense'
=>
$constraint
->
getTense
()
?
$constraint
->
getTense
()
->
getId
()
:
null
,
'mood'
=>
$constraint
->
getMood
()
?
$constraint
->
getMood
()
->
getId
()
:
null
,
'person'
=>
$constraint
->
getPerson
()
?
$constraint
->
getPerson
()
->
getId
()
:
null
,
];
foreach
(
$this
->
getConstraints
()
as
$c
)
{
$constraint
=
[];
$constraint
[
"id"
]
=
$c
->
getId
();
$constraint
[
"numberToFind"
]
=
$c
->
getNumberToFind
();
foreach
(
$c
->
getFeatures
()
as
$feature
)
{
$constraint
[
$feature
->
getLabel
()]
=
$feature
->
getValue
();
}
$jsonArray
[
'constraints'
][]
=
$constraint
;
}
}
...
...
application/src/MagicWordBundle/Resources/public/js/play/objective-constraint.js
View file @
e65f684e
var
objectiveConstraint
=
{
properties
:
[
"
category
"
,
"
number
"
,
"
gender
"
,
"
person
"
,
"
mood
"
,
"
tense
"
],
constraintRealized
:
[],
add
:
function
(
inflection
){
var
infos
=
gridJSON
.
inflections
[
inflection
.
toLowerCase
()].
infos
;
var
incrementedObjs
=
[];
for
(
var
i
=
0
;
i
<
infos
.
length
;
i
++
)
{
currentInflectionInfos
=
infos
[
i
];
for
(
var
j
=
0
;
j
<
roundJSON
.
constraints
.
length
;
j
++
)
{
var
objective
=
roundJSON
.
constraints
[
j
];
if
(
this
.
isPertinent
(
objective
,
currentInflectionInfos
)){
if
(
$
.
inArray
(
objective
.
id
,
incrementedObjs
)
==
-
1
)
{
objectives
.
updateProgress
(
objective
.
id
);
this
.
constraintRealized
.
push
(
objective
.
id
);
incrementedObjs
.
push
(
objective
.
id
);
if
(
this
.
checkCompletion
(
objective
)){
objectives
.
considerAsDone
(
objective
.
id
);
activity
.
sendObjectiveDone
(
objective
.
id
);
}
}
}
properties
:
[
"
category
"
,
"
number
"
,
"
gender
"
,
"
person
"
,
"
mood
"
,
"
tense
"
],
constraintRealized
:
[],
add
:
function
(
inflection
)
{
var
infos
=
gridJSON
.
inflections
[
inflection
.
toLowerCase
()].
features
;
var
incrementedObjs
=
[];
for
(
var
i
=
0
;
i
<
infos
.
length
;
i
++
)
{
currentInflectionInfos
=
infos
[
i
];
for
(
var
j
=
0
;
j
<
roundJSON
.
constraints
.
length
;
j
++
)
{
var
objective
=
roundJSON
.
constraints
[
j
];
if
(
this
.
isPertinent
(
objective
,
currentInflectionInfos
))
{
if
(
$
.
inArray
(
objective
.
id
,
incrementedObjs
)
==
-
1
)
{
objectives
.
updateProgress
(
objective
.
id
);
this
.
constraintRealized
.
push
(
objective
.
id
);
incrementedObjs
.
push
(
objective
.
id
);
if
(
this
.
checkCompletion
(
objective
))
{
objectives
.
considerAsDone
(
objective
.
id
);
activity
.
sendObjectiveDone
(
objective
.
id
);
}
}
},
countByObjective
:
function
(
objectiveId
){
var
count
=
0
;
for
(
var
i
=
0
;
i
<
this
.
constraintRealized
.
length
;
++
i
){
if
(
this
.
constraintRealized
[
i
]
==
objectiveId
){
count
++
;
}
}
return
count
;
},
isPertinent
:
function
(
objective
,
infos
){
for
(
var
i
=
0
;
i
<
this
.
properties
.
length
;
i
++
)
{
var
property
=
this
.
properties
[
i
];
if
(
objective
[
property
]
!=
null
&&
objective
[
property
]
!=
infos
[
property
])
{
return
false
;
};
}
}
}
}
},
countByObjective
:
function
(
objectiveId
)
{
var
count
=
0
;
for
(
var
i
=
0
;
i
<
this
.
constraintRealized
.
length
;
++
i
)
{
if
(
this
.
constraintRealized
[
i
]
==
objectiveId
)
{
count
++
;
}
}
return
true
;
},
checkCompletion
:
function
(
objective
){
if
(
this
.
countByObjective
(
objective
.
id
)
==
objective
.
numberToFind
){
return
true
;
}
return
count
;
},
isPertinent
:
function
(
objective
,
infos
)
{
for
(
var
i
=
0
;
i
<
this
.
properties
.
length
;
i
++
)
{
var
property
=
this
.
properties
[
i
];
if
(
objective
[
property
]
!=
null
&&
objective
[
property
]
!=
infos
[
property
])
{
return
false
;
};
}
return
true
;
},
checkCompletion
:
function
(
objective
)
{
if
(
this
.
countByObjective
(
objective
.
id
)
==
objective
.
numberToFind
)
{
return
true
;
}
return
false
;
}
}
application/src/MagicWordBundle/Resources/public/js/play/objective-findword.js
View file @
e65f684e
...
...
@@ -5,7 +5,7 @@ var findword = {
this
.
found
(
roundJSON
.
findWords
[
inflectionLower
],
inflection
);
return
true
;
}
else
{
var
lemmaIds
=
gridJSON
.
inflections
[
inflectionLower
].
lemma
Ids
;
var
lemmaIds
=
gridJSON
.
inflections
[
inflectionLower
].
root
Ids
;
for
(
var
i
=
0
;
i
<
lemmaIds
.
length
;
i
++
)
{
for
(
var
key
in
roundJSON
.
findWords
)
{
if
(
!
roundJSON
.
findWords
.
hasOwnProperty
(
key
))
continue
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment