1 | @XML_TOOLS Version "2.0"
|
---|
2 |
|
---|
3 | @CUSTOM_CODE
|
---|
4 | <code>
|
---|
5 | function contains(fullStringOrArray, subString){
|
---|
6 | return fullStringOrArray.indexOf(subString)!=-1;
|
---|
7 | }
|
---|
8 |
|
---|
9 | function removeFromArray(_array, _value){
|
---|
10 | _array.splice(_array.indexOf(_value), 1);
|
---|
11 | }
|
---|
12 |
|
---|
13 | var myBuilder = new JSXMLBuilder();
|
---|
14 | myBuilder.load($xmlData);
|
---|
15 |
|
---|
16 | var elements = myBuilder.elements[0];
|
---|
17 |
|
---|
18 | var particles = elements.childElement("Animation").childElement("Particles");
|
---|
19 |
|
---|
20 |
|
---|
21 | if(!elements.childElement("Animation").childElement("Attacks")){ // if no attacks found ignore file
|
---|
22 | return;
|
---|
23 | }
|
---|
24 |
|
---|
25 | var attackElement = elements.childElement("Animation").childElement("Attacks").childElement("Attack");
|
---|
26 |
|
---|
27 | var int_start,int_end,array_bones;
|
---|
28 |
|
---|
29 | // gather all the necessary info
|
---|
30 | int_start=attackElement.childElement("Start").text;
|
---|
31 | int_end=attackElement.childElement("End").text;
|
---|
32 | array_bones=attackElement.childElement("Bones").text.split(" ");
|
---|
33 |
|
---|
34 | // Check if any of the existing particles correspond to the same bone and glass_break
|
---|
35 | for (var i=0; (particles.childElement(i)); i++){ // the condition is to check if the child element exists (!= undefined)
|
---|
36 | var currElement=particles.childElement(i);
|
---|
37 |
|
---|
38 | if(contains(array_bones,currElement.childElement("Bone").text) && currElement.childElement("Name").text=="glass_break"){
|
---|
39 | removeFromArray(array_bones,currElement.childElement("Bone").text); // not necessary to add
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | // Insert the new glass particles
|
---|
44 | for (var i = 0; i < array_bones.length; i++) {
|
---|
45 | if( (contains(array_bones[i],"Foot")) && !contains(array_bones[i],"Calf") && !contains(array_bones[i],"Tight")
|
---|
46 | || (contains(array_bones[i],"Fist")) && !contains(array_bones[i],"Wrist")){
|
---|
47 | myBuilder.addElementAt("Particle","",
|
---|
48 | "<Start>"+int_start+"</Start>\
|
---|
49 | <End>"+int_end+"</End>\
|
---|
50 | <Bone>"+array_bones[i]+"</Bone>\
|
---|
51 | <Name>glass_break</Name>",particles.index+1,particles.level+1);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | $xmlData=myBuilder.generateXML(); // update the global variable with the new XML
|
---|
56 | </code> |
---|