-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.php
executable file
·188 lines (149 loc) · 6.16 KB
/
parser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
// Contains errors generated during the parsing
$err = array();
// Test s'il existe des scenes en doublon
$scenesIds = array();
$spritesIds = array();
$usedAsChilds = array();
foreach ($petri['scenes'] as $s) {
if (in_array($s['id'], $scenesIds))
$err[] = "The scene with id <b>".$s['id']."</b> is duplicated.";
else
array_push($scenesIds, $s['id']);
// Test s'il existe des scenes en doublon
if (isset($s['sprites'])) {
$spritesIds[$s['id']] = array();
foreach($s['sprites'] as $sprite) {
if (in_array($sprite['id'], $spritesIds[$s['id']]))
$err[] = "The sprite with id <b>".$sprite['id']."</b> in the scene <b>".$s['id']."</b> is duplicated.";
else
array_push($spritesIds[$s['id']], $sprite['id']);
}
$usedAsChilds[$s['id']] = array();
foreach ($s['sprites'] as $sprite) {
$childsId = (!isset($sprite['childs']) || count($sprite['childs']) == 0) ? null : $sprite['childs'];
if (is_array($childsId)) {
foreach ($childsId as $child) {
if (!in_array($child, $spritesIds[$s['id']]))
$err[] = "The sprite with id <b>".$child."</b> is used as child of the sprite <b>".$sprite['id']."</b> but does not exist.";
}
if (in_array($child, $usedAsChilds[$s['id']])) {
$err[] = "The sprite <b>".$child."</b> is used as child by many different container sprites. This is not allowed.";
}
$usedAsChilds[$s['id']] = array_merge($usedAsChilds[$s['id']], $childsId);
}
}
}
}
// Si pas d'erreurs de doublons, traitement des données
if (count($err) <= 0) {
// Scenes =======================================================
$sceneArray = array();
// On parcours chaque scenes
foreach ($petri['scenes'] as $s) {
$scene = new Scene($s);
// Sprites --------------------------------
if (isset($s['sprites'])) {
foreach ($s['sprites'] as $sprite) {
// Fetch de tous les tableaux
$props = array();
foreach ($SPRITE_ATTR_TO_FETCH as $attrName) {
if (isset($sprite[$attrName])) {
$props[$attrName] = $sprite[$attrName];
}
}
if (isset($sprite['clone'])) {
$count = (isset($sprite['count'])) ? $sprite['count'] : 1;
for($i = 0; $i < $count; ++$i) {
$newSprite = clone $scene->getSprite($sprite['clone']);
$newSprite->setId(uniqid($sprite['id']));
$newSprite->addProps($props);
if (isset($sprite['animations']))
$newSprite->addAnimations($sprite['animations']);
$scene->addSprite($newSprite);
}
} else {
$value = isset($sprite['value']) ? $sprite['value'] : NULL;
$childsId = (!isset($sprite['childs']) || count($sprite['childs']) == 0) ? null : $sprite['childs'];
$newSprite = new Sprite($sprite['nature'], $sprite['id'], $value, $props, $childsId);
if (isset($sprite['animations']))
$newSprite->addAnimations($sprite['animations']);
// Ajout du sprite à la scene
$scene->addSprite($newSprite);
}
}
$scene->processSpritesChilds();
}
// ----------------------------------------
// Ajout de la scene
$sceneArray[$s['id']] = $scene;
}
// ==============================================================
// Groupement des scenes dans des pages =========================
$views = array();
if (isset($petri['views'])) {
// Pour chaque vue, on utilise le tableau avec les scene ayant le flag isInView=true
foreach ($petri['views'] as $view) {
$viewObj = new View($view['id'], isset($view['title']) ? $view['title'] : "");
if (isset($view['scenes'])) {
foreach($view['scenes'] as $frame) {
if (!isset($sceneArray[$frame['scene-id']]))
array_push($err, "The scene <b>".$frame['scene-id']."</b> is embedded into the view <b>".$view['id']."</b>, but this scene does not exist.");
else
$viewObj->addScene($frame['frame-id'], $sceneArray[$frame['scene-id']], $frame['style']);
}
} else {
array_push($err, "The view <b>".$view['id']."</b> does not contain any scene.");
}
array_push($views, $viewObj);
}
}
// ==============================================================
// Transitions ==================================================
if (isset($petri['transitions'])) {
foreach($petri['transitions'] as $trans) {
$assocOut = array();
foreach ($trans['associationOut']['regles'] as $aO) {
$dests = array();
foreach($aO['dest'] as $dest) {
if (!isset($dest['targets'])) $dest['targets'] = null;
if (!isset($dest['js'])) $dest['js'] = null;
if (!isset($dest['id'])) $dest['id'] = null;
array_push($dests, new Dest($dest['type'], $dest['id'], $dest['targets'], $dest['js']));
}
$assocOut[$aO['id']] = $dests;
}
foreach ($trans['associationIn']['regles'] as $aI) {
$dests = $assocOut[$aI['id']];
foreach ($aI['scenes'] as $sceneFrom) {
$transition = new Transition($aI['id'], null);
// Creation des evenements pour chaque sprites de la scene
foreach ($aI['sprites'] as $sprite) {
$split = explode('.', $sprite);
if (count($split) != 2) {
$err[] = "The rule id=".$aI['id']." of the transition id=".$trans['id']." is malformed. The sprites must have the shape <i>spriteId.eventName</i>";
}
$eventType = $split[1];
$elemTrigger = $split[0];
$event = new Event($eventType, $elemTrigger, $dests);
// Ajout de l'evenement à la transition
$transition->addEvent($event);
}
// Attachenement de la transition à la scene
if (!isset($sceneArray[$sceneFrom]))
array_push($err, "A transition is attached to the scene <b>".$sceneFrom."</b>, but this scene does not exist");
else
$sceneArray[$sceneFrom]->bindTransition($transition);
}
}
}
}
// ==============================================================
// On définit la page index =====================================
$index = isset($petri['index']) ? $petri['index'] : null;
// ==============================================================
// Récupération des dépendences personnalisées de l'utilisateur==
$dependencies = isset($petri['include']) ? $petri['include'] : null;
// ==============================================================
}
?>