File indexing completed on 2024-12-15 05:07:27
0001 <?php 0002 0003 0004 0005 0006 0007 0008 /*import json 0009 import sys, getopt 0010 from pprint import pprint 0011 from enum import Enum 0012 import os*/ 0013 0014 0015 class ModeEdition extends SplEnum { 0016 const __functionault = self::NONE; 0017 0018 const NONE = 0 0019 const MINIMAL = 1 0020 const COMPLETE = 2 0021 } 0022 0023 0024 0025 /*function Usage(): 0026 print("Usage") 0027 print("") 0028 print("-h, --help; show this documentation") 0029 print("-i, --input <file>; path to input file") 0030 print("-o, --output <file>; path to output file, should not exist") 0031 print("-c, --complete; change the sheet to use v1.9 SDK, may change the look of some items.") 0032 print("-m, --minimal; change the sheet to make it work on v1.9") 0033 */ 0034 0035 0036 function createNewField($data) { 0037 $newKeys=array("additionnalBottomCode","additionnalHeadCode","additionnalImport"); 0038 foreach( $newKeys as &$key) 0039 { 0040 if(in_array($key, $data)) 0041 { 0042 $data[$newKey]=""; 0043 } 0044 } 0045 return $data; 0046 } 0047 0048 0049 function uuidAndPageCount($data,$key,$pageCount) 0050 { 0051 $data['uuid']=$key; 0052 $data['pageCount']=$pageCount; 0053 return $data; 0054 } 0055 0056 0057 function updateImage($data) { 0058 $key=""; 0059 $pageCount=0; 0060 foreach( data['background'] as &$p) 0061 { 0062 $p['filename']=""; 0063 $p['isBg']=True; 0064 $pageCount+=1; 0065 if( len(key) == 0) 0066 { 0067 $tmp=p['key']; 0068 $key=tmp[0:tmp.find("_")]; 0069 } 0070 else 0071 { 0072 $tmp=p['key']; 0073 $p['key']="{}{}".format(key,tmp[tmp.find("_"):]); 0074 } 0075 } 0076 0077 return array(data,key,pageCount); 0078 } 0079 0080 0081 function qmlIncludeMinimal(data) 0082 { 0083 #print("qmlIncludeMinimal") 0084 pattern="import \"qrc:/resources/qml/\""; 0085 newPat="import Rolisteam 1.0"; 0086 qml = data['qml']; 0087 qml = qml.replace(pattern,newPat); 0088 data['qml'] = qml; 0089 return data; 0090 } 0091 0092 function qmlIncludeComplete(data) 0093 { 0094 #print("qmlIncludeComplete") 0095 pattern="import \"qrc:/resources/qml/\""; 0096 newPat="import Rolisteam 1.1"; 0097 qml = data['qml']; 0098 qml = qml.replace(pattern,newPat); 0099 data['qml'] = qml; 0100 return data; 0101 } 0102 0103 function changeDiceButton(data) 0104 { 0105 #print("DiceButton") 0106 qml = data['qml']; 0107 inCheck=False; 0108 result=[]; 0109 foreach( line in qml.splitlines()) 0110 { 0111 if(line.find("DiceButton")>-1) 0112 { 0113 inCheck=True; 0114 } 0115 if(line.find("textColor")>-1 and inCheck) 0116 { 0117 line=line.replace("textColor","color"); 0118 } 0119 elif(line.find("color:")>-1 and inCheck) 0120 { 0121 line=line.replace("color","backgroundColor"); 0122 inCheck=False; 0123 } 0124 result.append(line); 0125 } 0126 0127 data['qml']="\n".join(result); 0128 return data; 0129 } 0130 0131 function changeTextFieldField(data) 0132 { 0133 #print("TextFieldField") 0134 qml = data['qml']; 0135 inCheck=False; 0136 result=[]; 0137 foreach (line in qml.splitlines()) 0138 { 0139 if(line.find("TextFieldField")>-1) 0140 {inCheck=True} 0141 if(line.find("textColor")>-1 and inCheck) 0142 { 0143 line=line.replace("textColor","color"); 0144 } 0145 else if(line.find("color:")>-1 and inCheck) 0146 { 0147 line=line.replace("color","backgroundColor"); 0148 inCheck=False; 0149 } 0150 result.append(line); 0151 } 0152 data['qml']="\n".join(result); 0153 return data; 0154 } 0155 0156 function changeTextArea(data) 0157 { 0158 #print("changeTextArea") 0159 qml = data['qml']; 0160 inCheck=False; 0161 result=[]; 0162 foreach (qml.splitlines() as $line) 0163 { 0164 if($line.find("TextAreaField")>-1) 0165 { 0166 inCheck=True; 0167 } 0168 if($line.find("textColor")>-1 and inCheck) 0169 { 0170 $line=$line.replace("textColor","color"); 0171 } 0172 else if($line.find("color:")>-1 and inCheck) 0173 { 0174 $line=$line.replace("color","backgroundColor") 0175 $inCheck=False; 0176 } 0177 $result.append($line); 0178 } 0179 0180 $data['qml']="\n".join($result) 0181 return $data; 0182 } 0183 0184 function changeCheckbox($data) 0185 { 0186 #print("changeCheckbox") 0187 qml = data['qml']; 0188 inCheck=False; 0189 result=[]; 0190 for line in qml.splitlines(): 0191 if(line.find("CheckBoxField")>-1): 0192 inCheck=True; 0193 if(line.find("textColor")>-1 and inCheck): 0194 line=line.replace("textColor","borderColor"); 0195 if(line.find("color:")>-1 and inCheck): 0196 inCheck=False; 0197 line="\n"; 0198 result.append(line); 0199 0200 data['qml']="\n".join(result); 0201 return data; 0202 } 0203 0204 function changeTextInputField(data) 0205 { 0206 #print("changeTextInputField") 0207 qml = data['qml']; 0208 inCheck=False; 0209 result=[]; 0210 foreach(qml.splitlines() as &$line) 0211 { 0212 if(line.find("TextInputField")>-1) 0213 { 0214 inCheck=True; 0215 } 0216 if(line.find("textColor")>-1 and inCheck) 0217 { 0218 line=line.replace("textColor","color"); 0219 } 0220 else if(line.find("color")>-1 and inCheck) 0221 { 0222 line=line.replace("color","backgroundColor"); 0223 inCheck=False; 0224 } 0225 0226 0227 0228 result.append(line); 0229 0230 } 0231 data['qml']="\n".join(result); 0232 return data; 0233 } 0234 0235 function completeChange(data) 0236 { 0237 array = updateImage(data); 0238 data = array[0]; 0239 key = array[1]; 0240 pageCount = array[2]; 0241 data = uuidAndPageCount(data,key,pageCount); 0242 data = qmlIncludeComplete(data); 0243 data = changeCheckbox(data); 0244 data = changeTextInputField(data); 0245 data = changeTextArea(data); 0246 data = changeTextFieldField(data); 0247 data = changeDiceButton(data); 0248 return data; 0249 } 0250 0251 function minimalChange(data) 0252 { 0253 array = updateImage(data); 0254 data = array[0]; 0255 key = array[1]; 0256 pageCount=array[2]; 0257 data = uuidAndPageCount(data,key,pageCount); 0258 data = qmlIncludeMinimal(data); 0259 return data; 0260 } 0261 0262 function loadFile($path) 0263 { 0264 $handle=fopen($path, 'r'); 0265 $data=json_decode($handle); 0266 return $data; 0267 } 0268 0269 function saveFile($path,$data) 0270 { 0271 $handle= fopen(path, 'w'); 0272 fwrite($handle, json_encode($data)); 0273 fclose($handle); 0274 } 0275 0276 function main() 0277 { 0278 $mode=$_POST['complete'] ? ModeEdition.COMPLETE : ModeEdition.COMPLETE; 0279 $inputFile=$_FILES['uploadedfile']['tmp_name']; 0280 $outputFile=replace($_FILES['uploadedfile']['name'],"rcs",'_fixed.rcs'); 0281 0282 if ($mode == ModeEdition.NONE) 0283 echo ("Error: no edition mode: minimal or complete") 0284 0285 data=loadFile($inputFile) 0286 0287 if $mode == ModeEdition.MINIMAL: 0288 $data = minimalChange($data); 0289 elif mode == ModeEdition.COMPLETE: 0290 $data = completeChange($data); 0291 0292 saveFile($outputFile, $data); 0293 } 0294 if(!empty($_POST['submit'])) 0295 main(); 0296 ?> 0297 0298 <html> 0299 <header> 0300 </header> 0301 <body> 0302 <form method="post" action=""> 0303 <input type="file" value="" id="source" name="source"/><br/> 0304 <label for="complete">Use 1.9 style:</label><input type="checkbox" value="" id="complete" name="complete" /><br/> 0305 <input type="submit" name="convert" value="convert" id="convert" /><br/> 0306 </form> 0307 </body> 0308 </html>