CPJLoader.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonLang;
  5. using CommonUI.Display;
  6. using CommonLang.Xml;
  7. using CommonLang.IO;
  8. using System.Xml;
  9. using System.IO;
  10. namespace CommonUI.Cell
  11. {
  12. abstract public class CPJLoader : IDisposable
  13. {
  14. readonly public HashMap<String, ImagesSet> ImgTable = new HashMap<String, ImagesSet>();
  15. readonly public HashMap<String, SpriteSet> SprTable = new HashMap<String, SpriteSet>();
  16. readonly public HashMap<String, MapSet> MapTable = new HashMap<String, MapSet>();
  17. readonly public HashMap<String, WorldSet> WorldTable = new HashMap<String, WorldSet>();
  18. abstract public Image LoadImage(string img);
  19. /**
  20. * input "{1234},{5678}"
  21. * return [1234][5678]
  22. */
  23. public static String[] GetArray2D(String text)
  24. {
  25. text = text.Replace('{', ' ');
  26. String[] texts = text.Split(new string[] { "}," }, StringSplitOptions.RemoveEmptyEntries);
  27. for (int i = texts.Length - 1; i >= 0; --i)
  28. {
  29. texts[i] = texts[i].Trim();
  30. }
  31. return texts;
  32. }
  33. /**
  34. * input 3,123,4,5678
  35. * return [123] [5678]
  36. * @param text
  37. * @return
  38. */
  39. public static String[] GetArray1D(String text)
  40. {
  41. TextInputStream reader = new TextInputStream(new StringReader(text), null);
  42. List<String> list = new List<String>();
  43. try
  44. {
  45. String line = reader.GetUTF();
  46. while (!string.IsNullOrEmpty(line))
  47. {
  48. list.Add(line);
  49. line = reader.GetUTF();
  50. }
  51. }
  52. catch (Exception e) { }
  53. return list.ToArray();
  54. }
  55. /**
  56. * input 3,123,4,5678
  57. * return [123] [5678]
  58. * @param text
  59. * @return
  60. */
  61. public static String GetArray1DLines(String text)
  62. {
  63. TextInputStream reader = new TextInputStream(new StringReader(text), null);
  64. StringBuilder ret = new StringBuilder();
  65. try
  66. {
  67. String line = reader.GetUTF();
  68. while (!string.IsNullOrEmpty(line))
  69. {
  70. ret.Append(line + "\n");
  71. line = reader.GetUTF();
  72. }
  73. }
  74. catch (Exception e) { }
  75. return ret.ToString();
  76. }
  77. public void Dispose()
  78. {
  79. if (ImgTable != null)
  80. {
  81. ImgTable.Clear();
  82. }
  83. if (SprTable != null)
  84. {
  85. SprTable.Clear();
  86. }
  87. if (MapTable != null)
  88. {
  89. MapTable.Clear();
  90. }
  91. if (WorldTable != null)
  92. {
  93. WorldTable.Clear();
  94. }
  95. }
  96. public string DefaultSpriteName
  97. {
  98. get
  99. {
  100. foreach (string name in SprTable.Keys)
  101. {
  102. return name;
  103. }
  104. return null;
  105. }
  106. }
  107. public string DefaultImageName
  108. {
  109. get
  110. {
  111. foreach (string name in ImgTable.Keys)
  112. {
  113. return name;
  114. }
  115. return null;
  116. }
  117. }
  118. public string DefaultMapName
  119. {
  120. get
  121. {
  122. foreach (string name in MapTable.Keys)
  123. {
  124. return name;
  125. }
  126. return null;
  127. }
  128. }
  129. public string DefaultWorldName
  130. {
  131. get
  132. {
  133. foreach (string name in WorldTable.Keys)
  134. {
  135. return name;
  136. }
  137. return null;
  138. }
  139. }
  140. }
  141. public class CPJLoaderXML : CPJLoader
  142. {
  143. private string path;
  144. private String image_type;
  145. private bool image_tile;
  146. private bool image_group;
  147. public CPJLoaderXML(string file)
  148. {
  149. this.path = Resource.FormatPath(file);
  150. XmlDocument doc = XmlUtil.LoadXML(path);
  151. if(doc == null)
  152. {
  153. throw new Exception("XmlDocument load error " + file);
  154. }
  155. XmlElement element = doc.DocumentElement;
  156. foreach (XmlNode node in element.ChildNodes)
  157. {
  158. if (node is XmlElement)
  159. {
  160. XmlElement e = (XmlElement)node;
  161. if (e.Name.Equals("IMAGE_TYPE"))
  162. {
  163. image_type = e.InnerText.Trim();
  164. }
  165. else if (e.Name.Equals("IMAGE_TILE"))
  166. {
  167. image_tile = Boolean.Parse(e.InnerText.Trim());
  168. }
  169. else if (e.Name.Equals("IMAGE_GROUP"))
  170. {
  171. image_group = Boolean.Parse(e.InnerText.Trim());
  172. }
  173. else if (e.Name.Equals("level"))
  174. {
  175. initLevel(e);
  176. }
  177. else if (e.Name.Equals("resource"))
  178. {
  179. initResource(e);
  180. }
  181. }
  182. }
  183. }
  184. private void initResource(XmlElement resource)
  185. {
  186. foreach (XmlNode node in resource.ChildNodes)
  187. {
  188. if (node is XmlElement)
  189. {
  190. XmlElement e = (XmlElement)node;
  191. if (e.Name.Equals("images"))
  192. {
  193. ImagesSet im = initImages(e);
  194. ImgTable.Add(im.Name, im);
  195. }
  196. else if (e.Name.Equals("map"))
  197. {
  198. MapSet ms = initMap(e);
  199. MapTable.Add(ms.Name, ms);
  200. }
  201. else if (e.Name.Equals("sprite"))
  202. {
  203. SpriteSet ss = initSprite(e);
  204. SprTable.Add(ss.Name, ss);
  205. }
  206. }
  207. }
  208. }
  209. private ImagesSet initImages(XmlElement images)
  210. {
  211. ImagesSet set = new ImagesSet(
  212. int.Parse(images.Attributes["index"].Value),
  213. images.Attributes["name"].Value);
  214. set.Count = int.Parse(images.Attributes[("size")].Value);
  215. set.ClipsX = new int[set.Count];
  216. set.ClipsY = new int[set.Count];
  217. set.ClipsW = new int[set.Count];
  218. set.ClipsH = new int[set.Count];
  219. set.ClipsKey = new String[set.Count];
  220. String output_file = images.Attributes["output_file"].Value;
  221. String output_type = images.Attributes["output_type"].Value;
  222. if (!string.IsNullOrEmpty(output_file))
  223. {
  224. set.Extention = output_file;
  225. }
  226. else
  227. {
  228. set.Extention = image_type;
  229. }
  230. if (output_type.Contains("tile"))
  231. {
  232. set.IsTiles = true;
  233. }
  234. else
  235. {
  236. set.IsTiles = image_tile;
  237. }
  238. if (images.HasAttribute("all_width"))
  239. {
  240. set.TotalW = int.Parse(images.Attributes["all_width"].Value);
  241. }
  242. if (images.HasAttribute("all_height"))
  243. {
  244. set.TotalH = int.Parse(images.Attributes["all_height"].Value);
  245. }
  246. if (images.HasAttribute("total_split"))
  247. {
  248. set.SplitSize = int.Parse(images.Attributes["total_split"].Value);
  249. }
  250. foreach (XmlNode node in images.ChildNodes)
  251. {
  252. if (node is XmlElement)
  253. {
  254. XmlElement e = (XmlElement)node;
  255. if (e.Name.Equals("clip"))
  256. {
  257. int index = int.Parse(e.Attributes["index"].Value);
  258. set.ClipsX[index] = int.Parse(e.Attributes["x"].Value);
  259. set.ClipsY[index] = int.Parse(e.Attributes["y"].Value);
  260. set.ClipsW[index] = int.Parse(e.Attributes["width"].Value);
  261. set.ClipsH[index] = int.Parse(e.Attributes["height"].Value);
  262. set.ClipsKey[index] = e.Attributes["data"].Value;
  263. }
  264. else if (e.Name.Equals("ImageInfo"))
  265. {
  266. set.ImageInfo = e.Value;
  267. }
  268. else if (e.Name.Equals("Append"))
  269. {
  270. set.AppendData = GetArray1DLines(e.Attributes["data"].Value);
  271. }
  272. }
  273. }
  274. return set;
  275. }
  276. private MapSet initMap(XmlElement map)
  277. {
  278. MapSet set = new MapSet(
  279. int.Parse(map.Attributes["index"].Value),
  280. map.Attributes["name"].Value);
  281. set.ImagesName = map.Attributes["images_name"].Value;
  282. set.XCount = int.Parse(map.Attributes["xcount"].Value);
  283. set.YCount = int.Parse(map.Attributes["ycount"].Value);
  284. set.CellW = int.Parse(map.Attributes["cellw"].Value);
  285. set.CellH = int.Parse(map.Attributes["cellh"].Value);
  286. set.LayerCount = int.Parse(map.Attributes["layer_count"].Value);
  287. int cdCount = int.Parse(map.Attributes["cd_part_count"].Value);
  288. set.BlocksType = new BlockType[cdCount];
  289. set.BlocksMask = new int[cdCount];
  290. set.BlocksX1 = new int[cdCount];
  291. set.BlocksY1 = new int[cdCount];
  292. set.BlocksX2 = new int[cdCount];
  293. set.BlocksY2 = new int[cdCount];
  294. set.BlocksW = new int[cdCount];
  295. set.BlocksH = new int[cdCount];
  296. set.TerrainTile = new int[set.LayerCount, set.YCount, set.XCount];
  297. set.TerrainFlip = new int[set.LayerCount, set.YCount, set.XCount];
  298. set.TerrainFlag = new int[set.LayerCount, set.YCount, set.XCount];
  299. foreach (XmlNode node in map.ChildNodes)
  300. {
  301. if (node is XmlElement)
  302. {
  303. XmlElement e = (XmlElement)node;
  304. if (e.Name.Equals("cd_part"))
  305. {
  306. int index = int.Parse(e.Attributes["index"].Value);
  307. set.BlocksType[index] = "rect".Equals(e.Attributes["type"].Value) ?
  308. BlockType.CD_TYPE_RECT : BlockType.CD_TYPE_LINE;
  309. set.BlocksMask[index] = int.Parse(e.Attributes["mask"].Value);
  310. set.BlocksX1[index] = int.Parse(e.Attributes["x1"].Value);
  311. set.BlocksY1[index] = int.Parse(e.Attributes["y1"].Value);
  312. set.BlocksX2[index] = int.Parse(e.Attributes["x2"].Value);
  313. set.BlocksY2[index] = int.Parse(e.Attributes["y2"].Value);
  314. set.BlocksW[index] = int.Parse(e.Attributes["width"].Value);
  315. set.BlocksH[index] = int.Parse(e.Attributes["height"].Value);
  316. }
  317. else if (e.Name.Equals("layer"))
  318. {
  319. int layerIndex = int.Parse(e.Attributes["index"].Value);
  320. String[] tile_matrix = GetArray2D(e.Attributes["tile_matrix"].Value);
  321. String[] flip_matrix = GetArray2D(e.Attributes["flip_matrix"].Value);
  322. String[] flag_matrix = GetArray2D(e.Attributes["flag_matrix"].Value);
  323. for (int y = 0; y < set.YCount; y++)
  324. {
  325. String[] tline = tile_matrix[y].Split(',');
  326. String[] fline = flip_matrix[y].Split(',');
  327. String[] cline = flag_matrix[y].Split(',');
  328. for (int x = 0; x < set.XCount; x++)
  329. {
  330. set.TerrainTile[layerIndex, y, x] = int.Parse(tline[x]);
  331. set.TerrainFlip[layerIndex, y, x] = int.Parse(fline[x]);
  332. set.TerrainFlag[layerIndex, y, x] = int.Parse(cline[x]);
  333. }
  334. }
  335. }
  336. else if (e.Name.Equals("Append"))
  337. {
  338. set.AppendData = GetArray1DLines(e.Attributes["data"].Value);
  339. }
  340. }
  341. }
  342. return set;
  343. }
  344. private SpriteSet initSprite(XmlElement sprite)
  345. {
  346. SpriteSet set = new SpriteSet(
  347. int.Parse(sprite.Attributes["index"].Value),
  348. sprite.Attributes["name"].Value);
  349. set.ImagesName = sprite.Attributes["images_name"].Value;
  350. if (sprite.HasAttribute("complexMode"))
  351. {
  352. set.ComplexMode = Boolean.Parse(sprite.Attributes["complexMode"].Value);
  353. }
  354. else
  355. {
  356. set.ComplexMode = false;
  357. }
  358. int scenePartCount = int.Parse(sprite.Attributes["scene_part_count"].Value);
  359. int sceneFrameCount = int.Parse(sprite.Attributes["scene_frame_count"].Value);
  360. int cdCount = int.Parse(sprite.Attributes["cd_part_count"].Value);
  361. int collidesCount = int.Parse(sprite.Attributes["cd_frame_count"].Value);
  362. int animateCount = int.Parse(sprite.Attributes["animate_count"].Value);
  363. set.PartX = new float[scenePartCount];
  364. set.PartY = new float[scenePartCount];
  365. set.PartZ = new float[scenePartCount];
  366. set.PartTileID = new int[scenePartCount];
  367. set.PartTileTrans = new Trans[scenePartCount];
  368. set.PartAlpha = new float[scenePartCount];
  369. set.PartRotate = new float[scenePartCount];
  370. set.PartScaleX = new float[scenePartCount];
  371. set.PartScaleY = new float[scenePartCount];
  372. set.PartAnchorX = new float[scenePartCount];
  373. set.PartAnchorY = new float[scenePartCount];
  374. set.Parts = new short[sceneFrameCount][];
  375. set.BlocksMask = new int[cdCount];
  376. set.BlocksX1 = new float[cdCount];
  377. set.BlocksY1 = new float[cdCount];
  378. set.BlocksW = new float[cdCount];
  379. set.BlocksH = new float[cdCount];
  380. set.Blocks = new short[collidesCount][];
  381. set.AnimateCount = animateCount;
  382. set.AnimateNames = new String[animateCount];
  383. set.FrameAnimate = new short[animateCount][];
  384. set.FrameAlpha = new float[animateCount][];
  385. set.FrameCDMap = new short[animateCount][];
  386. set.FrameCDAtk = new short[animateCount][];
  387. set.FrameCDDef = new short[animateCount][];
  388. set.FrameCDExt = new short[animateCount][];
  389. set.FrameDatas = new String[animateCount][];
  390. //NodeList list = sprite.getChildNodes();
  391. foreach (XmlNode node in sprite.ChildNodes)
  392. {
  393. if (node is XmlElement)
  394. {
  395. XmlElement e = (XmlElement)node;
  396. if (e.Name.Equals("scene_part"))
  397. {
  398. int index = int.Parse(e.Attributes["index"].Value);
  399. set.PartTileID[index] = int.Parse(e.Attributes["tile"].Value);
  400. set.PartX[index] = float.Parse(e.Attributes["x"].Value);
  401. set.PartY[index] = float.Parse(e.Attributes["y"].Value);
  402. set.PartZ[index] = float.Parse(e.Attributes["z"].Value);
  403. set.PartTileTrans[index] = (Trans)byte.Parse(e.Attributes["trans"].Value);
  404. set.PartAlpha[index] = float.Parse(e.Attributes["alpha"].Value, System.Globalization.CultureInfo.InvariantCulture);
  405. set.PartRotate[index] = float.Parse(e.Attributes["rotate"].Value, System.Globalization.CultureInfo.InvariantCulture);
  406. set.PartScaleX[index] = float.Parse(e.Attributes["scaleX"].Value, System.Globalization.CultureInfo.InvariantCulture);
  407. set.PartScaleY[index] = float.Parse(e.Attributes["scaleY"].Value, System.Globalization.CultureInfo.InvariantCulture);
  408. if (e.HasAttribute("anchorX"))
  409. {
  410. set.PartAnchorX[index] = float.Parse(e.Attributes["anchorX"].Value, System.Globalization.CultureInfo.InvariantCulture);
  411. set.PartAnchorY[index] = float.Parse(e.Attributes["anchorY"].Value, System.Globalization.CultureInfo.InvariantCulture);
  412. }
  413. }
  414. else if (e.Name.Equals("scene_frame"))
  415. {
  416. int index = int.Parse(e.Attributes["index"].Value);
  417. int frameCount = int.Parse(e.Attributes["data_size"].Value);
  418. set.Parts[index] = new short[frameCount];
  419. if (frameCount > 0)
  420. {
  421. String[] data = e.Attributes["data"].Value.Split(',');
  422. for (int f = 0; f < frameCount; f++)
  423. {
  424. set.Parts[index][f] = short.Parse(data[f]);
  425. }
  426. }
  427. }
  428. else if (e.Name.Equals("cd_part"))
  429. {
  430. int index = int.Parse(e.Attributes["index"].Value);
  431. set.BlocksMask[index] = int.Parse(e.Attributes["mask"].Value);
  432. set.BlocksX1[index] = float.Parse(e.Attributes["x1"].Value);
  433. set.BlocksY1[index] = float.Parse(e.Attributes["y1"].Value);
  434. set.BlocksW[index] = float.Parse(e.Attributes["width"].Value);
  435. set.BlocksH[index] = float.Parse(e.Attributes["height"].Value);
  436. }
  437. else if (e.Name.Equals("cd_frame"))
  438. {
  439. int index = int.Parse(e.Attributes["index"].Value);
  440. int frameCount = int.Parse(e.Attributes["data_size"].Value);
  441. set.Blocks[index] = new short[frameCount];
  442. if (frameCount > 0)
  443. {
  444. String[] data = e.Attributes["data"].Value.Split(',');
  445. for (int f = 0; f < frameCount; f++)
  446. {
  447. set.Blocks[index][f] = short.Parse(data[f]);
  448. }
  449. }
  450. }
  451. else if (e.Name.Equals("frames"))
  452. {
  453. TextInputStream AnimateNamesReader = new TextInputStream(
  454. new StringReader(e.Attributes["names"].Value), null);
  455. String[] frame_counts = e.Attributes["counts"].Value.Split(',');
  456. String[] frame_animate = GetArray2D(e.Attributes["animates"].Value);
  457. String[] frame_cd_map = GetArray2D(e.Attributes["cd_map"].Value);
  458. String[] frame_cd_atk = GetArray2D(e.Attributes["cd_atk"].Value);
  459. String[] frame_cd_def = GetArray2D(e.Attributes["cd_def"].Value);
  460. String[] frame_cd_ext = GetArray2D(e.Attributes["cd_ext"].Value);
  461. String[] frame_alpha = GetArray2D(e.Attributes["alpha"].Value);
  462. for (int i = 0; i < animateCount; i++)
  463. {
  464. set.AnimateNames[i] = AnimateNamesReader.GetUTF();
  465. int frameCount = int.Parse(frame_counts[i]);
  466. String[] animate = frame_animate[i].Split(',');
  467. String[] cd_map = frame_cd_map[i].Split(',');
  468. String[] cd_atk = frame_cd_atk[i].Split(',');
  469. String[] cd_def = frame_cd_def[i].Split(',');
  470. String[] cd_ext = frame_cd_ext[i].Split(',');
  471. String[] alpha = frame_alpha[i].Split(',');
  472. set.FrameAnimate[i] = new short[frameCount];
  473. set.FrameCDMap[i] = new short[frameCount];
  474. set.FrameCDAtk[i] = new short[frameCount];
  475. set.FrameCDDef[i] = new short[frameCount];
  476. set.FrameCDExt[i] = new short[frameCount];
  477. set.FrameAlpha[i] = new float[frameCount];
  478. for (int f = 0; f < frameCount; f++)
  479. {
  480. set.FrameAnimate[i][f] = short.Parse(animate[f]);
  481. set.FrameCDMap[i][f] = short.Parse(cd_map[f]);
  482. set.FrameCDAtk[i][f] = short.Parse(cd_atk[f]);
  483. set.FrameCDDef[i][f] = short.Parse(cd_def[f]);
  484. set.FrameCDExt[i][f] = short.Parse(cd_ext[f]);
  485. set.FrameAlpha[i][f] = float.Parse(alpha[f]);
  486. }
  487. }
  488. if (e.HasAttribute("fdata"))
  489. {
  490. String[] frame_datas = GetArray2D(e.Attributes["fdata"].Value);
  491. for (int i = 0; i < animateCount; i++)
  492. {
  493. int frameCount = int.Parse(frame_counts[i]);
  494. TextInputStream frameDataReader = new TextInputStream(
  495. new StringReader(frame_datas[i]));
  496. set.FrameDatas[i] = new String[frameCount];
  497. for (int f = 0; f < frameCount; f++)
  498. {
  499. set.FrameDatas[i][f] = frameDataReader.GetUTF();
  500. }
  501. }
  502. }
  503. }
  504. else if (e.Name.Equals("Append"))
  505. {
  506. set.AppendData = GetArray1DLines(e.Attributes["data"].Value);
  507. }
  508. }
  509. }
  510. return set;
  511. }
  512. private void initLevel(XmlElement level)
  513. {
  514. foreach (XmlNode node in level.ChildNodes)
  515. {
  516. if (node is XmlElement)
  517. {
  518. XmlElement e = (XmlElement)node;
  519. if (e.Name.Equals("world"))
  520. {
  521. WorldSet ws = initWorld(e);
  522. WorldTable.Add(ws.Name, ws);
  523. }
  524. }
  525. }
  526. }
  527. private WorldSet initWorld(XmlElement world)
  528. {
  529. WorldSet set = new WorldSet(
  530. int.Parse(world.Attributes["index"].Value),
  531. world.Attributes["name"].Value);
  532. set.GridXCount = int.Parse(world.Attributes["grid_x_count"].Value);
  533. set.GridYCount = int.Parse(world.Attributes["grid_y_count"].Value);
  534. set.GridW = int.Parse(world.Attributes["grid_w"].Value);
  535. set.GridH = int.Parse(world.Attributes["grid_h"].Value);
  536. set.Width = int.Parse(world.Attributes["width"].Value);
  537. set.Height = int.Parse(world.Attributes["height"].Value);
  538. // int maps_count = int.Parse(world.Attributes["unit_count_map"]);
  539. // int sprs_count = int.Parse(world.Attributes["unit_count_sprite"]);
  540. // int wpss_count = int.Parse(world.Attributes["waypoint_count"]);
  541. // int wrss_count = int.Parse(world.Attributes["region_count"]);
  542. set.Data = GetArray1DLines(world.Attributes["data"].Value);
  543. int terrains_count = set.GridXCount * set.GridYCount;
  544. set.Terrian = new int[set.GridXCount, set.GridYCount];
  545. String[] terrains = world.Attributes["terrain"].Value.Split(',');
  546. for (int i = 0; i < terrains_count; i++)
  547. {
  548. int x = i / set.GridYCount;
  549. int y = i % set.GridYCount;
  550. set.Terrian[x, y] = int.Parse(terrains[i]);
  551. }
  552. //NodeList list = world.getChildNodes();
  553. foreach (XmlNode node in world.ChildNodes)
  554. {
  555. if (node is XmlElement)
  556. {
  557. XmlElement e = (XmlElement)node;
  558. if (e.Name.Equals("unit_map"))
  559. {
  560. WorldSet.MapObject map = new WorldSet.MapObject();
  561. map.Index = int.Parse(e.Attributes["index"].Value);
  562. map.UnitName = e.Attributes["map_name"].Value;
  563. map.MapID = e.Attributes["id"].Value;
  564. map.X = int.Parse(e.Attributes["x"].Value);
  565. map.Y = int.Parse(e.Attributes["y"].Value);
  566. try
  567. {
  568. map.Priority = int.Parse(e.Attributes["priority"].Value);
  569. }
  570. catch (Exception e2) { }
  571. map.ImagesID = e.Attributes["images"].Value;
  572. map.Data = GetArray1DLines(e.Attributes["map_data"].Value);
  573. set.Maps.Add(map.Index, map);
  574. }
  575. else if (e.Name.Equals("unit_sprite"))
  576. {
  577. WorldSet.SpriteObject spr = new WorldSet.SpriteObject();
  578. spr.Index = int.Parse(e.Attributes["index"].Value);
  579. spr.UnitName = e.Attributes["spr_name"].Value;
  580. spr.SprID = e.Attributes["id"].Value;
  581. spr.Anim = int.Parse(e.Attributes["animate_id"].Value);
  582. spr.Frame = int.Parse(e.Attributes["frame_id"].Value);
  583. spr.X = int.Parse(e.Attributes["x"].Value);
  584. spr.Y = int.Parse(e.Attributes["y"].Value);
  585. try
  586. {
  587. spr.Priority = int.Parse(e.Attributes["priority"].Value);
  588. }
  589. catch (Exception e2) { }
  590. spr.ImagesID = e.Attributes["images"].Value;
  591. spr.Data = GetArray1DLines(e.Attributes["spr_data"].Value);
  592. set.Sprs.Add(spr.Index, spr);
  593. }
  594. else if (e.Name.Equals("unit_image"))
  595. {
  596. WorldSet.ImageObject img = new WorldSet.ImageObject();
  597. img.Index = int.Parse(e.Attributes["index"].Value);
  598. img.UnitName = e.Attributes["img_name"].Value;
  599. img.ImagesID = e.Attributes["id"].Value;
  600. img.TileID = int.Parse(e.Attributes["tile_id"].Value);
  601. img.ImgAnchor = (ImageAnchor)Enum.Parse(typeof(ImageAnchor), e.Attributes["anchor"].Value);
  602. img.ImgTrans = (ImageTrans)Enum.Parse(typeof(ImageTrans), e.Attributes["trans"].Value);
  603. img.X = int.Parse(e.Attributes["x"].Value);
  604. img.Y = int.Parse(e.Attributes["y"].Value);
  605. try
  606. {
  607. img.Priority = int.Parse(e.Attributes["priority"].Value);
  608. }
  609. catch (Exception e2) { }
  610. img.Data = GetArray1DLines(e.Attributes["img_data"].Value);
  611. set.Imgs.Add(img.Index, img);
  612. }
  613. else if (e.Name.Equals("waypoint"))
  614. {
  615. WorldSet.WaypointObject wp = new WorldSet.WaypointObject();
  616. wp.Index = int.Parse(e.Attributes["index"].Value);
  617. wp.X = int.Parse(e.Attributes["x"].Value);
  618. wp.Y = int.Parse(e.Attributes["y"].Value);
  619. wp.Data = GetArray1DLines(e.Attributes["path_data"].Value);
  620. set.WayPoints.Add(wp.Index, wp);
  621. }
  622. else if (e.Name.Equals("region"))
  623. {
  624. WorldSet.RegionObject wr = new WorldSet.RegionObject();
  625. wr.Index = int.Parse(e.Attributes["index"].Value);
  626. wr.X = int.Parse(e.Attributes["x"].Value);
  627. wr.Y = int.Parse(e.Attributes["y"].Value);
  628. wr.W = int.Parse(e.Attributes["width"].Value);
  629. wr.H = int.Parse(e.Attributes["height"].Value);
  630. wr.Data = GetArray1DLines(e.Attributes["region_data"].Value);
  631. set.Regions.Add(wr.Index, wr);
  632. }
  633. else if (e.Name.Equals("event"))
  634. {
  635. WorldSet.EventObject ev = new WorldSet.EventObject();
  636. ev.Index = int.Parse(e.Attributes["index"].Value);
  637. ev.ID = int.Parse(e.Attributes["id"].Value);
  638. ev.X = int.Parse(e.Attributes["x"].Value);
  639. ev.Y = int.Parse(e.Attributes["y"].Value);
  640. ev.EventName = e.Attributes["event_name"].Value;
  641. ev.EventFile = e.Attributes["event_file"].Value;
  642. ev.Data = e.Attributes["event_data"].Value;
  643. set.Events.Add(ev.Index, ev);
  644. }
  645. }
  646. }
  647. foreach (XmlNode node in world.ChildNodes)
  648. {
  649. if (node is XmlElement)
  650. {
  651. XmlElement e = (XmlElement)node;
  652. if (e.Name.Equals("waypoint_link"))
  653. {
  654. int start = int.Parse(e.Attributes["start"].Value);
  655. int end = int.Parse(e.Attributes["end"].Value);
  656. set.WayPoints.Get(start).Nexts.Put(end, set.WayPoints.Get(end));
  657. }
  658. }
  659. }
  660. return set;
  661. }
  662. public override Image LoadImage(string imgpath)
  663. {
  664. string output_dir = path.Substring(0, path.LastIndexOf('/'));
  665. Image ret = Driver.Instance.createImage(output_dir + "/" + imgpath);
  666. return ret;
  667. }
  668. }
  669. public class CPJLoaderBIN : CPJLoader
  670. {
  671. #region Constants
  672. private static readonly int VERSION_VALUE_1001 = 0x01000001;
  673. private static readonly int VERSION_VALUE_1002 = 0x01000002;
  674. private static readonly int VERSION_VALUE_2000 = 0x02000000;
  675. private static readonly byte[] VERSION = new byte[] { 0, 0, 0, 0 };
  676. private static readonly byte[] CE_HEAD_START = new byte[] { (byte)'C', (byte)'E', (byte)'F', (byte)'S' };
  677. private static readonly byte[] CE_IMG_START = new byte[] { (byte)'C', (byte)'E', (byte)'I', (byte)'M' };
  678. private static readonly byte[] CE_SPR_START = new byte[] { (byte)'C', (byte)'E', (byte)'S', (byte)'P' };
  679. private static readonly byte[] CE_MAP_START = new byte[] { (byte)'C', (byte)'E', (byte)'M', (byte)'P' };
  680. private static readonly byte[] CE_WORLD_START = new byte[] { (byte)'C', (byte)'E', (byte)'W', (byte)'D' };
  681. #endregion
  682. private byte[] version = new byte[VERSION.Length];
  683. private long filesize;
  684. private string path;
  685. private string image_type;
  686. private bool image_tile;
  687. private bool image_group;
  688. public int VersionValue { get; private set; }
  689. public CPJLoaderBIN(string file)
  690. {
  691. this.path = Resource.FormatPath(file);
  692. var stream = Resource.LoadDataAsStream(path);
  693. if (stream != null)
  694. {
  695. try
  696. {
  697. var input = new InputStream(stream, null);
  698. byte[] head_trunk = new byte[4];
  699. input.GetRawData(head_trunk, 0, head_trunk.Length);
  700. if (!CUtils.ArraysEqual(head_trunk, CE_HEAD_START))
  701. {
  702. throw new Exception("Unknow File Type : CE_HEAD_START");
  703. }
  704. input.GetRawData(version, 0, version.Length);
  705. this.filesize = input.GetS64();
  706. this.image_group = input.GetBool();
  707. this.image_tile = input.GetBool();
  708. this.image_type = input.GetUTF();
  709. this.VersionValue = 0;
  710. for (int i = 0; i < version.Length; i++)
  711. {
  712. VersionValue |= (((int)version[i]) << (i * 8));
  713. }
  714. {
  715. // ///////////////////////////////////////////
  716. {
  717. input.GetRawData(head_trunk, 0, head_trunk.Length);
  718. if (!CUtils.ArraysEqual(head_trunk, CE_IMG_START))
  719. {
  720. throw new Exception("Unknow File Type : CE_IMG_START");
  721. }
  722. int imgSize = input.GetS32();
  723. for (int i = 0; i < imgSize; i++)
  724. {
  725. ImagesSet im = readImagesSet(input);
  726. base.ImgTable.Put(im.Name, im);
  727. }
  728. }
  729. // ///////////////////////////////////////////
  730. {
  731. input.GetRawData(head_trunk, 0, head_trunk.Length);
  732. if (!CUtils.ArraysEqual(head_trunk, CE_SPR_START))
  733. {
  734. throw new Exception("Unknow File Type : CE_SPR_START");
  735. }
  736. int sprSize = input.GetS32();
  737. for (int i = 0; i < sprSize; i++)
  738. {
  739. SpriteSet im = readSpriteSet(input);
  740. base.SprTable.Put(im.Name, im);
  741. }
  742. }
  743. // ///////////////////////////////////////////
  744. {
  745. input.GetRawData(head_trunk, 0, head_trunk.Length);
  746. if (!CUtils.ArraysEqual(head_trunk, CE_MAP_START))
  747. {
  748. throw new Exception("Unknow File Type : CE_MAP_START");
  749. }
  750. int mapSize = input.GetS32();
  751. for (int i = 0; i < mapSize; i++)
  752. {
  753. MapSet im = readMapSet(input);
  754. base.MapTable.Put(im.Name, im);
  755. }
  756. }
  757. // ///////////////////////////////////////////
  758. {
  759. input.GetRawData(head_trunk, 0, head_trunk.Length);
  760. if (!CUtils.ArraysEqual(head_trunk, CE_WORLD_START))
  761. {
  762. throw new Exception("Unknow File Type : CE_WORLD_START");
  763. }
  764. int wdSize = input.GetS32();
  765. for (int i = 0; i < wdSize; i++)
  766. {
  767. WorldSet im = readWorldSet(input);
  768. base.WorldTable.Put(im.Name, im);
  769. }
  770. }
  771. // ///////////////////////////////////////////
  772. }
  773. }
  774. finally
  775. {
  776. stream.Dispose();
  777. }
  778. }
  779. }
  780. private ImagesSet readImagesSet(InputStream bis)
  781. {
  782. ImagesSet im = new ImagesSet(
  783. bis.GetS32(),
  784. bis.GetUTF());
  785. im.Count = bis.GetS32();
  786. im.ClipsX = new int[im.Count];
  787. im.ClipsY = new int[im.Count];
  788. im.ClipsW = new int[im.Count];
  789. im.ClipsH = new int[im.Count];
  790. im.ClipsKey = new String[im.Count];
  791. for (int i = 0; i < im.Count; i++)
  792. {
  793. if (bis.GetBool())
  794. {
  795. im.ClipsX[i] = bis.GetS32();
  796. im.ClipsY[i] = bis.GetS32();
  797. im.ClipsW[i] = bis.GetS32();
  798. im.ClipsH[i] = bis.GetS32();
  799. im.ClipsKey[i] = bis.GetUTF();
  800. }
  801. }
  802. im.Extention = bis.GetUTF();
  803. im.IsTiles = bis.GetBool();
  804. im.ImageInfo = bis.GetUTF();
  805. if (this.VersionValue >= VERSION_VALUE_1002)
  806. {
  807. im.TotalW = bis.GetS32();
  808. im.TotalH = bis.GetS32();
  809. im.SplitSize = bis.GetS32();
  810. }
  811. im.AppendData = bis.GetUTF();
  812. return im;
  813. }
  814. private SpriteSet readSpriteSet(InputStream bis)
  815. {
  816. SpriteSet im = new SpriteSet(
  817. bis.GetS32(),
  818. bis.GetUTF());
  819. im.ImagesName = bis.GetUTF();
  820. if (this.VersionValue >= VERSION_VALUE_1001)
  821. {
  822. im.ComplexMode = bis.GetBool();
  823. }
  824. {
  825. int partCount = bis.GetS32();
  826. im.PartX = new float[partCount];
  827. im.PartY = new float[partCount];
  828. im.PartZ = new float[partCount];
  829. im.PartTileID = new int[partCount];
  830. im.PartTileTrans = new Trans[partCount];
  831. im.PartAlpha = new float[partCount];
  832. im.PartRotate = new float[partCount];
  833. im.PartScaleX = new float[partCount];
  834. im.PartScaleY = new float[partCount];
  835. im.PartAnchorX = new float[partCount];
  836. im.PartAnchorY = new float[partCount];
  837. for (int i = 0; i < partCount; i++)
  838. {
  839. if (this.VersionValue >= VERSION_VALUE_2000)
  840. {
  841. im.PartX[i] = bis.GetF32();
  842. im.PartY[i] = bis.GetF32();
  843. im.PartZ[i] = bis.GetF32();
  844. }
  845. else
  846. {
  847. im.PartX[i] = bis.GetS16();
  848. im.PartY[i] = bis.GetS16();
  849. im.PartZ[i] = bis.GetS16();
  850. }
  851. im.PartTileID[i] = bis.GetS32();
  852. im.PartTileTrans[i] = bis.GetEnum8<Trans>();
  853. im.PartAlpha[i] = bis.GetF32();
  854. im.PartRotate[i] = bis.GetF32();
  855. im.PartScaleX[i] = bis.GetF32();
  856. im.PartScaleY[i] = bis.GetF32();
  857. im.PartAnchorX[i] = bis.GetF32();
  858. im.PartAnchorY[i] = bis.GetF32();
  859. }
  860. im.Parts = new short[bis.GetS32()][];
  861. for (int i = 0; i < im.Parts.Length; i++)
  862. {
  863. im.Parts[i] = new short[bis.GetS32()];
  864. for (int j = 0; j < im.Parts[i].Length; j++)
  865. {
  866. im.Parts[i][j] = bis.GetS16();
  867. }
  868. }
  869. }
  870. {
  871. int cdCount = bis.GetS32();
  872. im.BlocksMask = new int[cdCount];
  873. im.BlocksX1 = new float[cdCount];
  874. im.BlocksY1 = new float[cdCount];
  875. im.BlocksW = new float[cdCount];
  876. im.BlocksH = new float[cdCount];
  877. for (int i = 0; i < cdCount; i++)
  878. {
  879. im.BlocksMask[i] = bis.GetS32();
  880. if (this.VersionValue >= VERSION_VALUE_2000)
  881. {
  882. im.BlocksX1[i] = bis.GetF32();
  883. im.BlocksY1[i] = bis.GetF32();
  884. im.BlocksW[i] = bis.GetF32();
  885. im.BlocksH[i] = bis.GetF32();
  886. }
  887. else
  888. {
  889. im.BlocksX1[i] = bis.GetS16();
  890. im.BlocksY1[i] = bis.GetS16();
  891. im.BlocksW[i] = bis.GetS16();
  892. im.BlocksH[i] = bis.GetS16();
  893. }
  894. }
  895. im.Blocks = new short[bis.GetS32()][];
  896. for (int i = 0; i < im.Blocks.Length; i++)
  897. {
  898. im.Blocks[i] = new short[bis.GetS32()];
  899. for (int j = 0; j < im.Blocks[i].Length; j++)
  900. {
  901. im.Blocks[i][j] = bis.GetS16();
  902. }
  903. }
  904. }
  905. {
  906. im.AnimateCount = bis.GetS32();
  907. im.AnimateNames = new String[im.AnimateCount];
  908. im.FrameAnimate = new short[im.AnimateCount][];
  909. im.FrameCDMap = new short[im.AnimateCount][];
  910. im.FrameCDAtk = new short[im.AnimateCount][];
  911. im.FrameCDDef = new short[im.AnimateCount][];
  912. im.FrameCDExt = new short[im.AnimateCount][];
  913. im.FrameAlpha = new float[im.AnimateCount][];
  914. im.FrameDatas = new String[im.AnimateCount][];
  915. for (int i = 0; i < im.AnimateCount; i++)
  916. {
  917. im.AnimateNames[i] = bis.GetUTF();
  918. int frameCount = bis.GetS32();
  919. im.FrameAnimate[i] = new short[frameCount];
  920. im.FrameCDMap[i] = new short[frameCount];
  921. im.FrameCDAtk[i] = new short[frameCount];
  922. im.FrameCDDef[i] = new short[frameCount];
  923. im.FrameCDExt[i] = new short[frameCount];
  924. im.FrameAlpha[i] = new float[frameCount];
  925. im.FrameDatas[i] = new String[frameCount];
  926. for (int j = 0; j < frameCount; j++)
  927. {
  928. im.FrameAnimate[i][j] = bis.GetS16();
  929. im.FrameCDMap[i][j] = bis.GetS16();
  930. im.FrameCDAtk[i][j] = bis.GetS16();
  931. im.FrameCDDef[i][j] = bis.GetS16();
  932. im.FrameCDExt[i][j] = bis.GetS16();
  933. im.FrameAlpha[i][j] = bis.GetF32();
  934. im.FrameDatas[i][j] = bis.GetUTF();
  935. }
  936. }
  937. }
  938. im.AppendData = bis.GetUTF();
  939. return im;
  940. }
  941. private MapSet readMapSet(InputStream bis)
  942. {
  943. MapSet im = new MapSet(
  944. bis.GetS32(),
  945. bis.GetUTF());
  946. im.ImagesName = bis.GetUTF();
  947. im.XCount = bis.GetS32();
  948. im.YCount = bis.GetS32();
  949. im.CellW = bis.GetS32();
  950. im.CellH = bis.GetS32();
  951. im.LayerCount = bis.GetS32();
  952. int blockCount = bis.GetS32();
  953. im.BlocksType = new BlockType[blockCount];
  954. im.BlocksMask = new int[blockCount];
  955. im.BlocksX1 = new int[blockCount];
  956. im.BlocksY1 = new int[blockCount];
  957. im.BlocksX2 = new int[blockCount];
  958. im.BlocksY2 = new int[blockCount];
  959. im.BlocksW = new int[blockCount];
  960. im.BlocksH = new int[blockCount];
  961. for (int i = 0; i < blockCount; i++)
  962. {
  963. im.BlocksType[i] = (BlockType)bis.GetS32();
  964. im.BlocksMask[i] = bis.GetS32();
  965. im.BlocksX1[i] = bis.GetS32();
  966. im.BlocksY1[i] = bis.GetS32();
  967. im.BlocksX2[i] = bis.GetS32();
  968. im.BlocksY2[i] = bis.GetS32();
  969. im.BlocksW[i] = bis.GetS32();
  970. im.BlocksH[i] = bis.GetS32();
  971. }
  972. im.TerrainTile = new int[im.LayerCount, im.YCount, im.XCount];
  973. im.TerrainFlip = new int[im.LayerCount, im.YCount, im.XCount];
  974. im.TerrainFlag = new int[im.LayerCount, im.YCount, im.XCount];
  975. for (int i = 0; i < im.LayerCount; i++)
  976. {
  977. for (int y = 0; y < im.YCount; y++)
  978. {
  979. for (int x = 0; x < im.XCount; x++)
  980. {
  981. im.TerrainTile[i, y, x] = bis.GetS32();
  982. im.TerrainFlip[i, y, x] = bis.GetS32();
  983. im.TerrainFlag[i, y, x] = bis.GetS32();
  984. }
  985. }
  986. }
  987. im.AppendData = bis.GetUTF();
  988. return im;
  989. }
  990. private WorldSet readWorldSet(InputStream bis)
  991. {
  992. WorldSet im = new WorldSet(
  993. bis.GetS32(),
  994. bis.GetUTF());
  995. im.GridXCount = bis.GetS32();
  996. im.GridYCount = bis.GetS32();
  997. im.GridW = bis.GetS32();
  998. im.GridH = bis.GetS32();
  999. im.Width = bis.GetS32();
  1000. im.Height = bis.GetS32();
  1001. im.Terrian = new int[im.GridXCount, im.GridYCount];
  1002. for (int x = 0; x < im.GridXCount; x++)
  1003. {
  1004. for (int y = 0; y < im.GridYCount; y++)
  1005. {
  1006. im.Terrian[x, y] = bis.GetS32();
  1007. }
  1008. }
  1009. {
  1010. {
  1011. int sprsCount = bis.GetS32();
  1012. for (int i = 0; i < sprsCount; i++)
  1013. {
  1014. WorldSet.SpriteObject o = new WorldSet.SpriteObject();
  1015. o.Index = bis.GetS32();
  1016. o.UnitName = bis.GetUTF();
  1017. o.SprID = bis.GetUTF();
  1018. o.ImagesID = bis.GetUTF();
  1019. o.Anim = bis.GetS32();
  1020. o.Frame = bis.GetS32();
  1021. o.X = bis.GetS32();
  1022. o.Y = bis.GetS32();
  1023. o.Priority = bis.GetS32();
  1024. o.Data = bis.GetUTF();
  1025. im.Sprs.Put(o.Index, o);
  1026. }
  1027. }
  1028. {
  1029. int mapsCount = bis.GetS32();
  1030. for (int i = 0; i < mapsCount; i++)
  1031. {
  1032. WorldSet.MapObject o = new WorldSet.MapObject();
  1033. o.Index = bis.GetS32();
  1034. o.UnitName = bis.GetUTF();
  1035. o.MapID = bis.GetUTF();
  1036. o.ImagesID = bis.GetUTF();
  1037. o.X = bis.GetS32();
  1038. o.Y = bis.GetS32();
  1039. o.Priority = bis.GetS32();
  1040. o.Data = bis.GetUTF();
  1041. im.Maps.Put(o.Index, o);
  1042. }
  1043. }
  1044. {
  1045. int imgsCount = bis.GetS32();
  1046. for (int i = 0; i < imgsCount; i++)
  1047. {
  1048. WorldSet.ImageObject o = new WorldSet.ImageObject();
  1049. o.Index = bis.GetS32();
  1050. o.UnitName = bis.GetUTF();
  1051. o.ImagesID = bis.GetUTF();
  1052. o.TileID = bis.GetS32();
  1053. o.X = bis.GetS32();
  1054. o.Y = bis.GetS32();
  1055. o.Priority = bis.GetS32();
  1056. o.ImgAnchor = (ImageAnchor)bis.GetS32();
  1057. o.ImgTrans = (ImageTrans)bis.GetS32();
  1058. o.Data = bis.GetUTF();
  1059. im.Imgs.Put(o.Index, o);
  1060. }
  1061. }
  1062. {
  1063. int wpCount = bis.GetS32();
  1064. for (int i = 0; i < wpCount; i++)
  1065. {
  1066. WorldSet.WaypointObject o = new WorldSet.WaypointObject();
  1067. o.Index = bis.GetS32();
  1068. o.X = bis.GetS32();
  1069. o.Y = bis.GetS32();
  1070. o.Data = bis.GetUTF();
  1071. int nextCount = bis.GetS32();
  1072. for (int j = 0; j < nextCount; j++)
  1073. {
  1074. int nid = bis.GetS32();
  1075. o.Nexts.Put(nid, null);
  1076. }
  1077. im.WayPoints.Put(o.Index, o);
  1078. }
  1079. foreach (WorldSet.WaypointObject o in im.WayPoints.Values)
  1080. {
  1081. foreach (int nid in o.Nexts.Keys)
  1082. {
  1083. o.Nexts.Put(nid, im.WayPoints.Get(nid));
  1084. }
  1085. }
  1086. }
  1087. {
  1088. int rgCount = bis.GetS32();
  1089. for (int i = 0; i < rgCount; i++)
  1090. {
  1091. WorldSet.RegionObject o = new WorldSet.RegionObject();
  1092. o.Index = bis.GetS32();
  1093. o.X = bis.GetS32();
  1094. o.Y = bis.GetS32();
  1095. o.W = bis.GetS32();
  1096. o.H = bis.GetS32();
  1097. o.Data = bis.GetUTF();
  1098. im.Regions.Put(o.Index, o);
  1099. }
  1100. }
  1101. {
  1102. int evCount = bis.GetS32();
  1103. for (int i = 0; i < evCount; i++)
  1104. {
  1105. WorldSet.EventObject o = new WorldSet.EventObject();
  1106. o.Index = bis.GetS32();
  1107. o.ID = bis.GetS64();
  1108. o.EventName = bis.GetUTF();
  1109. o.EventFile = bis.GetUTF();
  1110. o.X = bis.GetS32();
  1111. o.Y = bis.GetS32();
  1112. o.Data = bis.GetUTF();
  1113. im.Events.Put(o.Index, o);
  1114. }
  1115. }
  1116. }
  1117. im.Data = bis.GetUTF();
  1118. return im;
  1119. }
  1120. public override Image LoadImage(string imgpath)
  1121. {
  1122. string output_dir = path.Substring(0, path.LastIndexOf('/'));
  1123. Image ret = Driver.Instance.createImage(output_dir + "/" + imgpath);
  1124. return ret;
  1125. }
  1126. }
  1127. }