Advertisement
Guest User

Form1.cs

a guest
Apr 14th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.32 KB | None | 0 0
  1. using Protocol;
  2. using Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6. using System.Reflection;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using Igor;
  10. using System.Drawing;
  11.  
  12. namespace CdbTest
  13. {
  14.  
  15. public partial class Form1 : Form
  16. {
  17.  
  18. //int sizex = 100;
  19. //int sizey = 36;
  20. //int sizez = 40;
  21. int sizex = 36;
  22. int sizey = 100;
  23. int sizez = 36;
  24. BlockMap3D importedmap;
  25. static List<Color> ColorArray = new List<Color>();
  26.  
  27. public static readonly Random random = new Random();
  28.  
  29. public Form1()
  30. {
  31. InitializeComponent();
  32. source.Lines = @"C:\bnl\UserData\CustomMaps\map_sr2_maze.bnlbin".Split('▀');
  33. save_to.Lines = @"C:\bnl\UserData\CustomMaps\map_generated.bnlbin".Split('▀');
  34. textBox4.Lines = @"140.png".Split('▀');
  35. numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
  36. }
  37.  
  38. public class BlockArrayMap3D2 : global::BlockMap3D
  39. {
  40. //private global::Block[][][] storage;
  41. public Block[][][] storage { get; set; }
  42.  
  43. public BlockArrayMap3D2(global::Vector3s size) : this((int)size.x, (int)size.y, (int)size.z)
  44. {
  45. }
  46.  
  47. public BlockArrayMap3D2(int sizeX, int sizeY, int sizeZ) : base(sizeX, sizeY, sizeZ)
  48. {
  49. this.storage = new global::Block[base.SizeX][][];
  50. for (int i = 0; i < base.SizeX; i++)
  51. {
  52. this.storage[i] = new global::Block[base.SizeY][];
  53. for (int j = 0; j < base.SizeY; j++)
  54. {
  55. this.storage[i][j] = new global::Block[base.SizeZ];
  56. }
  57. }
  58. }
  59.  
  60. protected override global::Block Get(int x, int y, int z)
  61. {
  62. return this.storage[x][y][z];
  63. }
  64.  
  65. protected override void Set(int x, int y, int z, global::Block block)
  66. {
  67. this.storage[x][y][z] = block;
  68. }
  69.  
  70. public global::Block Get2(int x, int y, int z)
  71. {
  72. return this.storage[x][y][z];
  73. }
  74.  
  75. public void Set2(int x, int y, int z, global::Block block)
  76. {
  77. // Debug.WriteLine("set2 params: " + x + " " + z);
  78. this.storage[x][y][z] = block;
  79. }
  80. public void Set3(int x, int y, int z, global::Block block)
  81. {
  82. // Debug.WriteLine("set2 params: " + x + " " + z);
  83. //if (this.storage[x][y][z].Id == 18 && block.Id == 10) { throw new Exception(); }
  84. //if (this.storage[x][y][z].Id == 16) { Console.WriteLine("jumppad"); throw new Exception(); }
  85. if (this.storage[x][y][z].Id == 53) { throw new Exception(); }
  86. if (this.storage[x][y][z].Id == 0 || this.storage[x][y][z].Id == 10)
  87. this.storage[x][y][z] = block;
  88. //if (this.storage[x][y][z].Id != 0) { throw new Exception(); }
  89. //this.storage[x][y][z] = block;
  90. }
  91. public void Set4(int x, int y, int z, global::Block block)
  92. {
  93. // Debug.WriteLine("set2 params: " + x + " " + z);
  94. //if (this.storage[x][y][z].Id == 18 && block.Id == 10) { throw new Exception(); }
  95. //if (this.storage[x][y][z].Id == 16) { Console.WriteLine("jumppad"); throw new Exception(); }
  96. if (this.storage[x][y][z].Id == 53) { throw new Exception(); }
  97. //if (this.storage[x][y][z].Id != 0) { throw new Exception(); }
  98. this.storage[x][y][z] = block;
  99. }
  100. }
  101.  
  102.  
  103. // MapGenerator
  104. public static BlockArrayMap3D2 GenerateRandom(global::Vector3s size, int air)
  105. {
  106. global::MapGenerator.FixSize(ref size);
  107. Random rand = new Random();
  108. BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
  109. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  110. {
  111. if (rand.Next(0, 100) < air)
  112. {
  113. block.Id = 0;
  114. }
  115. else
  116. {
  117. byte next = utils.whitelist();
  118. //if(pos.x % 4 == 0 && pos.y % 4 == 0 && pos.z % 4 == 0)
  119. //{
  120. // Debug.WriteLine("" + pos.x + pos.y + pos.z);
  121. //}
  122. block.Id = next;
  123. }
  124. });
  125. return blockArrayMap3D;
  126. }
  127.  
  128. // MapGenerator
  129. public BlockArrayMap3D2 GenerateTerrain(global::Vector3s size, float feature)
  130. {
  131. float towerfeature = (float)numericUpDown14.Value;
  132. OpenSimplexNoise osn = new OpenSimplexNoise();
  133. MapGenerator.FixSize(ref size);
  134. BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
  135. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  136. {
  137. //double something = osn.Evaluate(pos.x, pos.y, pos.z);
  138. //int id = (int)((something + 1) * (size.y / 2));
  139. //Debug.WriteLine(id);
  140. //block.Id = (byte)id;
  141. block.Id = 0;
  142. });
  143. int whileHeight = 0;
  144. for (int x = 0; x < size.x - 1; x++)
  145. {
  146. for (int z = 0; z < size.z - 1; z++)
  147. {
  148. Block turf = new Block();
  149. turf.Id = 5;
  150. double something = osn.Evaluate(x / feature, z / feature);
  151. int height = (int)((something + 1) * (size.y / 2));
  152. blockArrayMap3D.Set2(x, height, z, turf);
  153.  
  154. //stuff below
  155. while (blockArrayMap3D.Get2(x, whileHeight, z).Id != 5)
  156. {
  157. Block stone = new Block();
  158. stone.Id = 3;
  159. blockArrayMap3D.Set2(x, whileHeight, z, stone);
  160. whileHeight++;
  161. }
  162. Block dirt = new Block();
  163. dirt.Id = 1;
  164. if (whileHeight - 1 > -1)
  165. try { blockArrayMap3D.Set2(x, whileHeight - 1, z, dirt); } catch { }
  166.  
  167. if (whileHeight - 2 > -1)
  168. try { blockArrayMap3D.Set2(x, whileHeight - 2, z, dirt); } catch { }
  169.  
  170. if (whileHeight - 3 > -1)
  171. try { blockArrayMap3D.Set2(x, whileHeight - 3, z, dirt); } catch { }
  172.  
  173. if (whileHeight - 4 > -1)
  174. try { blockArrayMap3D.Set2(x, whileHeight - 4, z, dirt); } catch { }
  175. whileHeight = 0;
  176. }
  177. whileHeight = 0;
  178. }
  179. for (int towers = 0; towers < numericUpDown16.Value; towers++)
  180. {
  181. int sizeOfTower = (int)numericUpDown14.Value;
  182. int randomx = random.Next(size.x - sizeOfTower);
  183. int randomz = random.Next(size.z - sizeOfTower);
  184.  
  185.  
  186. for (int x = randomx; x < randomx + sizeOfTower; x++)
  187. {
  188. for (int z = randomz; z < randomz + sizeOfTower; z++)
  189. {
  190. Block towerBlock = new Block();
  191. towerBlock.Id = (byte)numericUpDown13.Value;
  192.  
  193. double something = osn.Evaluate(x / towerfeature, z / towerfeature);
  194. int height = (int)((something + 1) * (size.y / 1.7));
  195. Debug.WriteLine(height);
  196. for (int e = height; e > 0; e--)
  197. {
  198. try { blockArrayMap3D.Set2(x, e, z, towerBlock); } catch { }
  199. }
  200. //mirror test
  201. //float average = 18;
  202. //Debug.WriteLine(average);
  203. //float howMuchHigherIsIt = height - average;
  204. //Debug.WriteLine(howMuchHigherIsIt);
  205. //try { blockArrayMap3D.Set2(x, (int)(height - howMuchHigherIsIt*2), z, dirt); } catch { Debug.WriteLine(x + " " + (int)(average - howMuchHigherIsIt) + " " + z); }
  206. }
  207. }
  208.  
  209. }
  210. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  211. {
  212. double something = osn.Evaluate(pos.x / feature, pos.y / feature, pos.z / feature);
  213. //Debug.WriteLine(something);
  214. if (something > ((float.Parse(textBox2.Lines[0]) - 50) / 50) && block.Id == 3) { block.Id = 0; }// else { block.Id = 0; }
  215.  
  216.  
  217. });
  218.  
  219.  
  220. return blockArrayMap3D;
  221. }
  222.  
  223. // MapGenerator
  224. public BlockArrayMap3D2 GenerateDerpTerrain(global::Vector3s size, float feature)
  225. {
  226. double tresh = float.Parse(textBox3.Lines[0]);
  227. OpenSimplexNoise osn = new OpenSimplexNoise();
  228. MapGenerator.FixSize(ref size);
  229. BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
  230. BlockArrayMap3D2 imported = new BlockArrayMap3D2(new Vector3s(36, 36, 36));
  231. //make a map out of air
  232. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  233. {
  234. block.Id = 0;
  235. });
  236. //stone
  237. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  238. {
  239. //double something = osn.Evaluate(pos.x, pos.y, pos.z);
  240. //int id = (int)((something + 1) * (size.y / 2));
  241. //Debug.WriteLine(id);
  242. //block.Id = (byte)id;
  243.  
  244. //float noise2 = (float)osn.Evaluate(pos.x / feature / 2, pos.y / feature / 2, pos.z / feature / 2);
  245. //(float.Parse(textBox2.Lines[0]) - 50) / 50;
  246. //double tresh2 = utils.Remap(noise2, -1, 1, -0.5f, 0.5f);
  247. //double avg = (tresh + tresh2) / 2;
  248. //Debug.WriteLine(something);
  249.  
  250. //double tresh = utils.Remap(pos.y, 0, size.y, -0.5f, 0.5f);
  251. //double tresh = utils.Remap(pos.y, 0, size.y, -1f, 1f);
  252.  
  253.  
  254. double noise = osn.Evaluate(pos.x / feature, pos.y / feature, pos.z / feature);
  255. noise *= noise;
  256. //if (pos.y < size.y / 2 + 20 && pos.y > size.y / 2 -5)
  257. //{
  258. if (noise < tresh)
  259. {
  260. //block.Id = 27;
  261. //Console.WriteLine(block.Id);
  262. }
  263. else
  264. {
  265. //block.Id = 0;
  266. }
  267. //}
  268.  
  269.  
  270.  
  271. });
  272. importedmap.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  273. {
  274. imported.Set2(pos.x, pos.y, pos.z, block);
  275. });
  276.  
  277.  
  278. Console.WriteLine(imported.Get2(1, 1, 1).Id);
  279.  
  280. Genheightmap(ref blockArrayMap3D, size);
  281. //AddTrees(ref blockArrayMap3D, size);
  282.  
  283.  
  284.  
  285.  
  286. for (int i = 0; i < 100; i++)
  287. {
  288. int objectx = random.Next(size.x - 37);
  289. int objecty = random.Next(size.y - 37);
  290. int objectz = random.Next(size.z - 37);
  291.  
  292.  
  293. for (int x = 0; x < 35; x++)
  294. {
  295. for (int y = 0; y < 35; y++)
  296. {
  297. for (int z = 0; z < 35; z++)
  298. {
  299. Block a = imported.Get2(x, y, z);
  300. if (a.Id != 0 && a.Id != 46)
  301. {
  302. blockArrayMap3D.Set2(objectx + x, objecty + y, objectz + z, a);
  303. }
  304.  
  305. }
  306. }
  307. }
  308. }
  309.  
  310.  
  311.  
  312.  
  313. return blockArrayMap3D;
  314. }
  315.  
  316. // MapGenerator
  317. public static BlockArrayMap3D RandomizeMap(global::Vector3s size, BlockMap3D blockArrayMap3D)
  318. {
  319. global::MapGenerator.FixSize(ref size);
  320.  
  321. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  322. {
  323. if (block.Id == 7 || block.Id == 53 || block.Id == 9 || block.Id == 17 || block.Id == 58 || block.Id == 1 || block.Id == 46 || block.Id == 5 || block.Id == 61 || block.Id == 4 || block.Id == 10 || block.Id == 14 || block.Id == 27 || block.Id == 2 || block.Id == 21 || block.Id == 60 || block.Id == 3 || block.Id == 11 || block.Id == 8)
  324. {
  325.  
  326. byte next = utils.whitelistgrid();
  327. block.Id = next;
  328. }
  329. else
  330. {
  331. // Debug.WriteLine(block.Id);
  332. }
  333. });
  334. return (BlockArrayMap3D)blockArrayMap3D;
  335. }
  336.  
  337. // MapGenerator
  338. public static BlockArrayMap3D2 GeneratePixelArt(global::Vector3s size, Bitmap bmp)
  339. {
  340. bool cube = false;
  341. bool maze = false;
  342.  
  343.  
  344. Block lol = new Block();
  345. lol.Id = 10;
  346. global::MapGenerator.FixSize(ref size);
  347. //size.x++;
  348. //size.x++;
  349. //size.x++;
  350. BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
  351.  
  352.  
  353. for (int x = 0; x < bmp.Width; x++)
  354. {
  355. for (int y = 0; y < bmp.Height; y++)
  356. {
  357.  
  358. }
  359. }
  360.  
  361. //make a map out of air
  362. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  363. {
  364. block.Id = 0;
  365. block.Color = 1;
  366. });
  367.  
  368.  
  369. for (int x = 0; x < bmp.Width-1; x++)
  370. {
  371. for (int y = 0; y < bmp.Height-1; y++)
  372. {
  373. Color clr = bmp.GetPixel(x, y);
  374. int red = clr.R;
  375. int gre = clr.G;
  376. int blu = clr.B;
  377. //Console.WriteLine("Slow: " + red1 + " " + green + " " + blue);
  378.  
  379.  
  380.  
  381. Block a = new Block();
  382. //string pixel = pixels[x + y * width];
  383. //string[] colors = pixel.Split(",".ToCharArray());
  384. //int red = int.Parse(colors[0]);
  385. //int gre = int.Parse(colors[1]);
  386. //int blu = int.Parse(colors[2]);
  387. //if(red + gre + blu > 384)
  388. //{
  389. // a.Id = 5;
  390. //} else
  391. //{
  392. // a.Id = 4;
  393. //}
  394. //float id = utils.Remap(red + gre + blu, 0, 765, 1, 11);
  395. //int id2 = (int)id;
  396. a.Id = 53;
  397. //ConsoleColor cc = utils.ClosestConsoleColor((byte)red, (byte)gre, (byte)blu);
  398. Color cc = Color.FromArgb((byte)red, (byte)gre, (byte)blu);
  399. var closest = utils.GetClosestColor(ColorArray.ToArray(), cc);
  400. cc = closest;
  401. a.Color = 0;
  402. //Console.WriteLine(cc.ToKnownColor());
  403. //if (2 == 3) { } else if (cc.ToString() == "Black") { a.Color = 0; } else if (cc.ToString() == "DarkBlue") { a.Color = 1; } else if (cc.ToString() == "DarkGreen") { a.Color = 2; } else if (cc.ToString() == "DarkCyan") { a.Color = 3; } else if (cc.ToString() == "DarkRed") { a.Color = 4; } else if (cc.ToString() == "DarkMagenta") { a.Color = 5; } else if (cc.ToString() == "DarkYellow") { a.Color = 6; } else if (cc.ToString() == "Gray") { a.Color = 7; } else if (cc.ToString() == "DarkGray") { a.Color = 8; } else if (cc.ToString() == "Blue") { a.Color = 9; } else if (cc.ToString() == "Green") { a.Color = 10; } else if (cc.ToString() == "Cyan") { a.Color = 11; } else if (cc.ToString() == "Red") { a.Color = 12; } else if (cc.ToString() == "Magenta") { a.Color = 13; } else if (cc.ToString() == "Yellow") { a.Color = 14; } else if (cc.ToString() == "White") { a.Color = 15; }
  404. if (false) { } else if (cc.Name == "Transparent") { a.Color = 0; } else if (cc.Name == "AliceBlue") { a.Color = 1; } else if (cc.Name == "AntiqueWhite") { a.Color = 2; } else if (cc.Name == "Aqua") { a.Color = 3; } else if (cc.Name == "Aquamarine") { a.Color = 4; } else if (cc.Name == "Azure") { a.Color = 5; } else if (cc.Name == "Beige") { a.Color = 6; } else if (cc.Name == "Bisque") { a.Color = 7; } else if (cc.Name == "Black") { a.Color = 8; } else if (cc.Name == "BlanchedAlmond") { a.Color = 9; } else if (cc.Name == "Blue") { a.Color = 10; } else if (cc.Name == "BlueViolet") { a.Color = 11; } else if (cc.Name == "Brown") { a.Color = 12; } else if (cc.Name == "BurlyWood") { a.Color = 13; } else if (cc.Name == "CadetBlue") { a.Color = 14; } else if (cc.Name == "Chartreuse") { a.Color = 15; } else if (cc.Name == "Chocolate") { a.Color = 16; } else if (cc.Name == "Coral") { a.Color = 17; } else if (cc.Name == "CornflowerBlue") { a.Color = 18; } else if (cc.Name == "Cornsilk") { a.Color = 19; } else if (cc.Name == "Crimson") { a.Color = 20; } else if (cc.Name == "Cyan") { a.Color = 21; } else if (cc.Name == "DarkBlue") { a.Color = 22; } else if (cc.Name == "DarkCyan") { a.Color = 23; } else if (cc.Name == "DarkGoldenrod") { a.Color = 24; } else if (cc.Name == "DarkGray") { a.Color = 25; } else if (cc.Name == "DarkGreen") { a.Color = 26; } else if (cc.Name == "DarkKhaki") { a.Color = 27; } else if (cc.Name == "DarkMagenta") { a.Color = 28; } else if (cc.Name == "DarkOliveGreen") { a.Color = 29; } else if (cc.Name == "DarkOrange") { a.Color = 30; } else if (cc.Name == "DarkOrchid") { a.Color = 31; } else if (cc.Name == "DarkRed") { a.Color = 32; } else if (cc.Name == "DarkSalmon") { a.Color = 33; } else if (cc.Name == "DarkSeaGreen") { a.Color = 34; } else if (cc.Name == "DarkSlateBlue") { a.Color = 35; } else if (cc.Name == "DarkSlateGray") { a.Color = 36; } else if (cc.Name == "DarkTurquoise") { a.Color = 37; } else if (cc.Name == "DarkViolet") { a.Color = 38; } else if (cc.Name == "DeepPink") { a.Color = 39; } else if (cc.Name == "DeepSkyBlue") { a.Color = 40; } else if (cc.Name == "DimGray") { a.Color = 41; } else if (cc.Name == "DodgerBlue") { a.Color = 42; } else if (cc.Name == "Firebrick") { a.Color = 43; } else if (cc.Name == "FloralWhite") { a.Color = 44; } else if (cc.Name == "ForestGreen") { a.Color = 45; } else if (cc.Name == "Fuchsia") { a.Color = 46; } else if (cc.Name == "Gainsboro") { a.Color = 47; } else if (cc.Name == "GhostWhite") { a.Color = 48; } else if (cc.Name == "Gold") { a.Color = 49; } else if (cc.Name == "Goldenrod") { a.Color = 50; } else if (cc.Name == "Gray") { a.Color = 51; } else if (cc.Name == "Green") { a.Color = 52; } else if (cc.Name == "GreenYellow") { a.Color = 53; } else if (cc.Name == "Honeydew") { a.Color = 54; } else if (cc.Name == "HotPink") { a.Color = 55; } else if (cc.Name == "IndianRed") { a.Color = 56; } else if (cc.Name == "Indigo") { a.Color = 57; } else if (cc.Name == "Ivory") { a.Color = 58; } else if (cc.Name == "Khaki") { a.Color = 59; } else if (cc.Name == "Lavender") { a.Color = 60; } else if (cc.Name == "LavenderBlush") { a.Color = 61; } else if (cc.Name == "LawnGreen") { a.Color = 62; } else if (cc.Name == "LemonChiffon") { a.Color = 63; } else if (cc.Name == "LightBlue") { a.Color = 64; } else if (cc.Name == "LightCoral") { a.Color = 65; } else if (cc.Name == "LightCyan") { a.Color = 66; } else if (cc.Name == "LightGoldenrodYellow") { a.Color = 67; } else if (cc.Name == "LightGreen") { a.Color = 68; } else if (cc.Name == "LightGray") { a.Color = 69; } else if (cc.Name == "LightPink") { a.Color = 70; } else if (cc.Name == "LightSalmon") { a.Color = 71; } else if (cc.Name == "LightSeaGreen") { a.Color = 72; } else if (cc.Name == "LightSkyBlue") { a.Color = 73; } else if (cc.Name == "LightSlateGray") { a.Color = 74; } else if (cc.Name == "LightSteelBlue") { a.Color = 75; } else if (cc.Name == "LightYellow") { a.Color = 76; } else if (cc.Name == "Lime") { a.Color = 77; } else if (cc.Name == "LimeGreen") { a.Color = 78; } else if (cc.Name == "Linen") { a.Color = 79; } else if (cc.Name == "Magenta") { a.Color = 80; } else if (cc.Name == "Maroon") { a.Color = 81; } else if (cc.Name == "MediumAquamarine") { a.Color = 82; } else if (cc.Name == "MediumBlue") { a.Color = 83; } else if (cc.Name == "MediumOrchid") { a.Color = 84; } else if (cc.Name == "MediumPurple") { a.Color = 85; } else if (cc.Name == "MediumSeaGreen") { a.Color = 86; } else if (cc.Name == "MediumSlateBlue") { a.Color = 87; } else if (cc.Name == "MediumSpringGreen") { a.Color = 88; } else if (cc.Name == "MediumTurquoise") { a.Color = 89; } else if (cc.Name == "MediumVioletRed") { a.Color = 90; } else if (cc.Name == "MidnightBlue") { a.Color = 91; } else if (cc.Name == "MintCream") { a.Color = 92; } else if (cc.Name == "MistyRose") { a.Color = 93; } else if (cc.Name == "Moccasin") { a.Color = 94; } else if (cc.Name == "NavajoWhite") { a.Color = 95; } else if (cc.Name == "Navy") { a.Color = 96; } else if (cc.Name == "OldLace") { a.Color = 97; } else if (cc.Name == "Olive") { a.Color = 98; } else if (cc.Name == "OliveDrab") { a.Color = 99; } else if (cc.Name == "Orange") { a.Color = 100; } else if (cc.Name == "OrangeRed") { a.Color = 101; } else if (cc.Name == "Orchid") { a.Color = 102; } else if (cc.Name == "PaleGoldenrod") { a.Color = 103; } else if (cc.Name == "PaleGreen") { a.Color = 104; } else if (cc.Name == "PaleTurquoise") { a.Color = 105; } else if (cc.Name == "PaleVioletRed") { a.Color = 106; } else if (cc.Name == "PapayaWhip") { a.Color = 107; } else if (cc.Name == "PeachPuff") { a.Color = 108; } else if (cc.Name == "Peru") { a.Color = 109; } else if (cc.Name == "Pink") { a.Color = 110; } else if (cc.Name == "Plum") { a.Color = 111; } else if (cc.Name == "PowderBlue") { a.Color = 112; } else if (cc.Name == "Purple") { a.Color = 113; } else if (cc.Name == "Red") { a.Color = 114; } else if (cc.Name == "RosyBrown") { a.Color = 115; } else if (cc.Name == "RoyalBlue") { a.Color = 116; } else if (cc.Name == "SaddleBrown") { a.Color = 117; } else if (cc.Name == "Salmon") { a.Color = 118; } else if (cc.Name == "SandyBrown") { a.Color = 119; } else if (cc.Name == "SeaGreen") { a.Color = 120; } else if (cc.Name == "SeaShell") { a.Color = 121; } else if (cc.Name == "Sienna") { a.Color = 122; } else if (cc.Name == "Silver") { a.Color = 123; } else if (cc.Name == "SkyBlue") { a.Color = 124; } else if (cc.Name == "SlateBlue") { a.Color = 125; } else if (cc.Name == "SlateGray") { a.Color = 126; } else if (cc.Name == "Snow") { a.Color = 127; } else if (cc.Name == "SpringGreen") { a.Color = 128; } else if (cc.Name == "SteelBlue") { a.Color = 129; } else if (cc.Name == "Tan") { a.Color = 130; } else if (cc.Name == "Teal") { a.Color = 131; } else if (cc.Name == "Thistle") { a.Color = 132; } else if (cc.Name == "Tomato") { a.Color = 133; } else if (cc.Name == "Turquoise") { a.Color = 134; } else if (cc.Name == "Violet") { a.Color = 135; } else if (cc.Name == "Wheat") { a.Color = 136; } else if (cc.Name == "White") { a.Color = 137; } else if (cc.Name == "WhiteSmoke") { a.Color = 138; } else if (cc.Name == "Yellow") { a.Color = 139; } else if (cc.Name == "YellowGreen") { a.Color = 140; }
  405. //Console.WriteLine(cc.Name);
  406. //Console.WriteLine(a.Color);
  407.  
  408. a.Color++;
  409.  
  410. //Console.WriteLine(closest.Name);
  411. int s = 1;
  412. int inv = size.y - 1 - y;
  413. Block metal = new Block();
  414. metal.Id = 10;
  415.  
  416. if (cube)
  417. {
  418. blockArrayMap3D.Set2(y, s, x, metal);
  419. blockArrayMap3D.Set2(y, size.y - s, x, a);
  420.  
  421. blockArrayMap3D.Set2(s, inv, x, a);
  422. blockArrayMap3D.Set2(size.x - s, inv, x, a);
  423.  
  424. blockArrayMap3D.Set2(x, inv, s, a);
  425. blockArrayMap3D.Set2(x, inv, size.z - s, a);
  426. }
  427. else
  428. {
  429. blockArrayMap3D.Set2(y, 7, x, a);
  430. }
  431.  
  432.  
  433.  
  434.  
  435.  
  436. if (cc.ToString() == "Black" && maze)
  437. {
  438. blockArrayMap3D.Set2(y, 8, x, a);
  439. blockArrayMap3D.Set2(y, 9, x, a);
  440. blockArrayMap3D.Set2(y, 10, x, a);
  441. blockArrayMap3D.Set2(y, 11, x, a);
  442. }
  443.  
  444. }
  445. }
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452. //BlockArrayMap3D2 test1 = new BlockArrayMap3D2(size);
  453. //test1.Set2(30, 30, 30, lol);
  454. //BlockArrayMap3D2 test2 = new BlockArrayMap3D2(size);
  455. //test1.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  456. //{
  457. // test2.Set2(pos.x, pos.y, pos.z, block);
  458. //});
  459. //test2 = test1;
  460. //test1.Set2(30, 30, 31, lol);
  461. //test1.Set2(30, 30, 32, lol);
  462.  
  463. //return test2;
  464. return blockArrayMap3D;
  465. }
  466. public static void up(ref BlockArrayMap3D2 blockArrayMap3D, int dir, int leng)
  467. {
  468.  
  469. }
  470.  
  471. // MapGenerator
  472. public static BlockArrayMap3D2 GenerateGrid(global::Vector3s size)
  473. {
  474. global::MapGenerator.FixSize(ref size);
  475. Random rand = new Random();
  476. BlockArrayMap3D2 blockArrayMap3D = new BlockArrayMap3D2(size);
  477. blockArrayMap3D.Change(delegate (ref global::Block block, ref global::Vector3s pos)
  478. {
  479. byte next = utils.whitelistgrid();
  480. //Debug.WriteLine(next.ToString());
  481. if (pos.x % 4 == 0 && pos.y % 4 == 0 && pos.z % 4 == 0)
  482. {
  483. block.Id = next;
  484. }
  485. else
  486. {
  487.  
  488. // Debug.WriteLine("" + pos.x + pos.y + pos.z);
  489. block.Id = 0;
  490. }
  491.  
  492. });
  493. return blockArrayMap3D;
  494. }
  495.  
  496. //Button
  497. private void genmap_click(object sender, EventArgs e)
  498. {
  499. sizex = (int)numericUpDown1.Value;
  500. sizey = (int)numericUpDown2.Value;
  501. sizez = (int)numericUpDown3.Value;
  502.  
  503.  
  504.  
  505. string json2 = MapStoreUtils.Decode(File.ReadAllBytes(@"original_map.bnlbin"));
  506. Json.JsonData json = Json.JsonParser.Parse(json2);
  507.  
  508. json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(sizex);
  509. json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(sizey);
  510. json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(sizez);
  511. json.Object["name"] = Json.Write.String("generated map");
  512. BlockArrayMap3D2 map = GenerateRandom(new Vector3s(sizex, sizey, sizez), (int)numericUpDown4.Value);
  513.  
  514. int unitcount = 0;
  515. int blockcount = map.SizeX * map.SizeY * map.SizeZ;
  516.  
  517. string units = "[";// = json.Object["map"].Object["units"].ToString();
  518. for (int i = 0; i < map.SizeX; i++)
  519. {
  520. for (int j = 0; j < map.SizeY; j++)
  521. {
  522. for (int k = 0; k < map.SizeZ; k++)
  523. {
  524. // Debug.WriteLine("" + map.Get2(i, j, k).Id + map.Get2(i, j, k).Damage + map.Get2(i, j, k).Ldata + map.Get2(i, j, k).Vdata);
  525.  
  526.  
  527. if (random.Next(blockcount / 90) == 50 && map.Get2(i, j, k).Id == 0)
  528. {
  529. unitcount++;
  530.  
  531. //Debug.WriteLine(rand.Next(2));
  532. // Debug.WriteLine(map.Get2(i, j, k).Id);
  533. units = units + ",{\"position\":{\"x\":" + i + ".5,\"y\":" + j + ".5,\"z\":" + k + ".5},\"rotation\":{\"x\":0,\"y\":0,\"z\":0},\"unit_key\":\"" + utils.heal_or_radar_or_ammo() + "\",\"team\":\"" + utils.random_team() + "\"}";
  534.  
  535. }
  536. }
  537. }
  538. }
  539. Debug.WriteLine(unitcount);
  540. textBox1.Lines = unitcount.ToString().Split('a');
  541. json.Object["map"].Object["units"] = Json.Write.String(units + "]");
  542. //Debug.WriteLine(units);
  543. json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(map));
  544. string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
  545. byte[] compressed = MapStoreUtils.Encode(json_fixed);
  546. File.Create(save_to.Lines[0]).Close();
  547. File.WriteAllBytes(save_to.Lines[0], compressed);
  548. File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
  549. //release
  550. File.Create(@"map-generated.bnlbin").Close();
  551. File.WriteAllBytes(@"map-generated.bnlbin", compressed);
  552. }
  553.  
  554.  
  555.  
  556. //Button
  557. private void gengrid_click(object sender, EventArgs e)
  558. {
  559. sizex = (int)numericUpDown9.Value;
  560. sizey = (int)numericUpDown10.Value;
  561. sizez = (int)numericUpDown11.Value;
  562.  
  563.  
  564.  
  565. string json2 = MapStoreUtils.Decode(File.ReadAllBytes(@"original_map.bnlbin"));
  566. Json.JsonData json = Json.JsonParser.Parse(json2);
  567.  
  568. json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(sizex);
  569. json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(sizey);
  570. json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(sizez);
  571. json.Object["name"] = Json.Write.String("generated map");
  572. BlockArrayMap3D2 map = GenerateGrid(new Vector3s(sizex, sizey, sizez));
  573.  
  574. int unitcount = 0;
  575. int blockcount = map.SizeX * map.SizeY * map.SizeZ;
  576.  
  577. string units = "[";// = json.Object["map"].Object["units"].ToString();
  578. for (int i = 0; i < map.SizeX; i++)
  579. {
  580. for (int j = 0; j < map.SizeY; j++)
  581. {
  582. for (int k = 0; k < map.SizeZ; k++)
  583. {
  584. // Debug.WriteLine("" + map.Get2(i, j, k).Id + map.Get2(i, j, k).Damage + map.Get2(i, j, k).Ldata + map.Get2(i, j, k).Vdata);
  585.  
  586.  
  587. if (random.Next(blockcount / 1800) == 50 && map.Get2(i, j, k).Id == 0)
  588. {
  589. if (i % 4 == 0 && k % 4 == 0)
  590. {
  591. unitcount++;
  592.  
  593. //Debug.WriteLine(rand.Next(2));
  594. // Debug.WriteLine(map.Get2(i, j, k).Id);
  595. units = units + ",{\"position\":{\"x\":" + i + ".5,\"y\":" + j + ".5,\"z\":" + k + ".5},\"rotation\":{\"x\":0,\"y\":0,\"z\":0},\"unit_key\":\"" + utils.heal_or_radar_or_ammo() + "\",\"team\":\"" + utils.random_team() + "\"}";
  596. }
  597. }
  598. }
  599. }
  600. }
  601.  
  602. Debug.WriteLine(unitcount);
  603. textBox1.Lines = unitcount.ToString().Split('a');
  604. json.Object["map"].Object["units"] = Json.Write.String(units + "]");
  605. Debug.WriteLine(units);
  606. json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(map));
  607. string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
  608. byte[] compressed = MapStoreUtils.Encode(json_fixed);
  609. File.Create(save_to.Lines[0]).Close();
  610. File.WriteAllBytes(save_to.Lines[0], compressed);
  611. File.Create(@"uncompressed").Close();
  612. File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
  613. //release
  614. File.Create(@"map-generated.bnlbin").Close();
  615. File.WriteAllBytes(@"map-generated.bnlbin", compressed);
  616. }
  617. //Button
  618. private void randomize_existing_map_click(object sender, EventArgs e)
  619. {
  620.  
  621.  
  622. string json_orig = MapStoreUtils.Decode(File.ReadAllBytes(source.Lines[0]));
  623. Json.JsonData json = Json.JsonParser.Parse(json_orig);
  624. Vector3s size = new Vector3s(Json.Read.Int(json.Object["map"].Object["size"].Object["x"]), Json.Read.Int(json.Object["map"].Object["size"].Object["y"]), Json.Read.Int(json.Object["map"].Object["size"].Object["z"]));
  625. MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["map"].Object["blocks_data"]), size);
  626. BlockMap3D orig_blocks = mb.ToMap3D();
  627. BlockMap3D new_blocks = RandomizeMap(size, orig_blocks);
  628.  
  629.  
  630.  
  631.  
  632. //save the map
  633. json.Object["name"] = Json.Write.String("generated map");
  634. json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
  635. string json_fixed = json.ToString();
  636. byte[] compressed = MapStoreUtils.Encode(json_fixed);
  637. File.Create(save_to.Lines[0]).Close();
  638. File.WriteAllBytes(save_to.Lines[0], compressed);
  639. File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
  640. //release
  641. File.Create(@"map-generated.bnlbin").Close();
  642. File.WriteAllBytes(@"map-generated.bnlbin", compressed);
  643. }
  644. //Button
  645. private void genterrain_click(object sender, EventArgs e)
  646. {
  647. string json_orig = MapStoreUtils.Decode(File.ReadAllBytes("original_map.bnlbin"));
  648. Json.JsonData json = Json.JsonParser.Parse(json_orig);
  649. Vector3s size = new Vector3s((int)numericUpDown6.Value, (int)numericUpDown7.Value, (int)numericUpDown8.Value);
  650. json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(size.x);
  651. json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(size.y);
  652. json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(size.z);
  653.  
  654. BlockMap3D new_blocks = GenerateTerrain(size, (float)numericUpDown5.Value);
  655.  
  656.  
  657.  
  658.  
  659. //save the map
  660. json.Object["name"] = Json.Write.String("generated map");
  661. json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
  662. json.Object["map"].Object["units"] = Json.Write.String("[,]");
  663. string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
  664. byte[] compressed = MapStoreUtils.Encode(json_fixed);
  665. File.Create(save_to.Lines[0]).Close();
  666. File.WriteAllBytes(save_to.Lines[0], compressed);
  667. File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
  668. //release
  669. File.Create(@"map-generated.bnlbin").Close();
  670. File.WriteAllBytes(@"map-generated.bnlbin", compressed);
  671. }
  672.  
  673. //Browse
  674. private void button4_Click(object sender, EventArgs e)
  675. {
  676. OpenFileDialog ofd = new OpenFileDialog();
  677. // bmp, gif, jpg, png, tif and dds
  678. ofd.Filter = "map|*.bnlbin";
  679. ofd.CheckFileExists = true;
  680. ofd.Title = "Open map";
  681. if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
  682. {
  683. // Debug.WriteLine(ofd.FileName);
  684. //textBox3.Lines[0] = "2"; //ofd.FileName;
  685. source.Lines = ofd.FileName.Split("?".ToCharArray());
  686. }
  687. }
  688. //Browse
  689. private void button5_Click(object sender, EventArgs e)
  690. {
  691. OpenFileDialog ofd = new OpenFileDialog();
  692. // bmp, gif, jpg, png, tif and dds
  693. ofd.Filter = "map|*.bnlbin";
  694. ofd.CheckFileExists = false;
  695. ofd.Title = "Open map";
  696. if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
  697. {
  698. // Debug.WriteLine(ofd.FileName);
  699. //textBox3.Lines[0] = "2"; //ofd.FileName;
  700. save_to.Lines = ofd.FileName.Split("?".ToCharArray());
  701. }
  702. }
  703.  
  704. private void numericUpDown6_ValueChanged(object sender, EventArgs e)
  705. {
  706. numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
  707. }
  708.  
  709. private void numericUpDown7_ValueChanged(object sender, EventArgs e)
  710. {
  711. numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
  712. }
  713.  
  714. private void numericUpDown8_ValueChanged(object sender, EventArgs e)
  715. {
  716. numericUpDown12.Value = numericUpDown6.Value * numericUpDown7.Value * numericUpDown8.Value;
  717. }
  718.  
  719. private void derp_terrain_click(object sender, EventArgs e)
  720. {
  721. string json_orig = MapStoreUtils.Decode(File.ReadAllBytes("original_map.bnlbin"));
  722. Json.JsonData json = Json.JsonParser.Parse(json_orig);
  723. Vector3s size = new Vector3s((int)numericUpDown6.Value, (int)numericUpDown7.Value, (int)numericUpDown8.Value);
  724. json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(size.x);
  725. json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(size.y);
  726. json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(size.z);
  727.  
  728. BlockMap3D new_blocks = GenerateDerpTerrain(size, (float)numericUpDown5.Value);
  729.  
  730.  
  731.  
  732.  
  733. //save the map
  734. json.Object["name"] = Json.Write.String("generated map");
  735. json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
  736. json.Object["map"].Object["units"] = Json.Write.String("[,]");
  737. string json_fixed = json.ToString().Replace("\\", "").Replace("\"units\":\"[,", "\"units\":[").Replace("\",\"cameras", ",\"cameras");
  738. byte[] compressed = MapStoreUtils.Encode(json_fixed);
  739. File.Create(save_to.Lines[0]).Close();
  740. File.WriteAllBytes(save_to.Lines[0], compressed);
  741. File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
  742. //release
  743. File.Create(@"map-generated.bnlbin").Close();
  744. File.WriteAllBytes(@"map-generated.bnlbin", compressed);
  745. }
  746.  
  747. private void numericUpDown14_ValueChanged(object sender, EventArgs e)
  748. {
  749.  
  750. }
  751.  
  752.  
  753. public BlockArrayMap3D2 AddTrees(ref BlockArrayMap3D2 blockArrayMap3D, Vector3s size)
  754. {
  755. int trunksize = 5;
  756. Block towerBlock = new Block();
  757. towerBlock.Id = (byte)numericUpDown13.Value;
  758. float towerfeature = (float)numericUpDown14.Value;
  759. int sizeOfTower = (int)numericUpDown14.Value;
  760. int sizeOfTower2 = (int)Math.Floor(sizeOfTower * 0.5);
  761. int whileHeight = 0;
  762. for (int towers = 0; towers < numericUpDown16.Value; towers++)
  763. {
  764. whileHeight = size.y - 1;
  765.  
  766.  
  767.  
  768. int randomx = random.Next(size.x - sizeOfTower);
  769. int randomz = random.Next(size.z - sizeOfTower);
  770. int trunkx = randomx + sizeOfTower2;
  771. int trunkz = randomz + sizeOfTower2;
  772. while (blockArrayMap3D.Get2(trunkx, whileHeight, trunkz).Id == 0)
  773. {
  774. whileHeight--;
  775. }
  776. int height = whileHeight + trunksize + sizeOfTower;
  777. if (height > size.y - 1)
  778. {
  779. continue;
  780. }
  781.  
  782.  
  783. for (int x = randomx; x < randomx + sizeOfTower; x++)
  784. {
  785. for (int z = randomz; z < randomz + sizeOfTower; z++)
  786. {
  787.  
  788. //Debug.WriteLine(height);
  789. for (int e = height; e > height - sizeOfTower; e--)
  790. {
  791. try { blockArrayMap3D.Set2(x, e, z, towerBlock); } catch { Console.WriteLine("error at " + e); }
  792. }
  793.  
  794. }
  795. }
  796. for (int x = 0; x < trunksize + 1; x++)
  797. {
  798. try { blockArrayMap3D.Set2(trunkx, whileHeight + x, trunkz, towerBlock); } catch { }
  799.  
  800. }
  801. }
  802. return blockArrayMap3D;
  803.  
  804. }
  805. public BlockArrayMap3D2 Genheightmap(ref BlockArrayMap3D2 blockArrayMap3D, Vector3s size)
  806. {
  807. float towerfeature = (float)numericUpDown14.Value;
  808. float feature = (float)numericUpDown17.Value;
  809. OpenSimplexNoise osn = new OpenSimplexNoise();
  810. MapGenerator.FixSize(ref size);
  811.  
  812. int whileHeight = 0;
  813. for (int x = 0; x < size.x; x++)
  814. {
  815. for (int z = 0; z < size.z; z++)
  816. {
  817. Block turf = new Block();
  818. turf.Id = 5;
  819. double something = osn.Evaluate(x / feature, z / feature);
  820. int height = (int)((something + 1) * (size.y / 3));
  821. blockArrayMap3D.Set2(x, height, z, turf);
  822.  
  823. //stuff below
  824. while (blockArrayMap3D.Get2(x, whileHeight, z).Id != 5)
  825. {
  826. Block stone = new Block();
  827. stone.Id = 3;
  828. blockArrayMap3D.Set2(x, whileHeight, z, stone);
  829. whileHeight++;
  830. }
  831. Block air = new Block();
  832. air.Id = 0;
  833. for (int i = whileHeight + 30; i < size.y; i++)
  834. {
  835. try { blockArrayMap3D.Set2(x, i, z, air); } catch { }
  836. }
  837.  
  838.  
  839. Block dirt = new Block();
  840. dirt.Id = 1;
  841. if (whileHeight - 1 > -1)
  842. try { blockArrayMap3D.Set2(x, whileHeight - 1, z, dirt); } catch { }
  843.  
  844. if (whileHeight - 2 > -1)
  845. try { blockArrayMap3D.Set2(x, whileHeight - 2, z, dirt); } catch { }
  846.  
  847. if (whileHeight - 3 > -1)
  848. try { blockArrayMap3D.Set2(x, whileHeight - 3, z, dirt); } catch { }
  849.  
  850. if (whileHeight - 4 > -1)
  851. try { blockArrayMap3D.Set2(x, whileHeight - 4, z, dirt); } catch { }
  852. whileHeight = 0;
  853. }
  854. whileHeight = 0;
  855. }
  856.  
  857.  
  858.  
  859. return blockArrayMap3D;
  860.  
  861. }
  862.  
  863. private void button7_Click(object sender, EventArgs e)
  864. {
  865. string json_orig = MapStoreUtils.Decode(File.ReadAllBytes(@"C:\bnl\UserData\CustomMaps\object.bnlbin"));
  866. Json.JsonData json = Json.JsonParser.Parse(json_orig);
  867. Console.WriteLine(json);
  868. //Vector3s size = new Vector3s(Json.Read.Int(json.Object["map"].Object["size"].Object["x"]), Json.Read.Int(json.Object["map"].Object["size"].Object["y"]), Json.Read.Int(json.Object["map"].Object["size"].Object["z"]));
  869. //MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["map"].Object["blocks_data"]), size);
  870. Vector3s size = new Vector3s(Json.Read.Int(json.Object["size"].Object["x"]), Json.Read.Int(json.Object["size"].Object["y"]), Json.Read.Int(json.Object["size"].Object["z"]));
  871. MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["blocks_data"]), size);
  872. BlockMap3D orig_blocks = mb.ToMap3D();
  873. importedmap = orig_blocks;
  874. //BlockMap3D new_blocks = RandomizeMap(size, orig_blocks);
  875.  
  876.  
  877. }
  878.  
  879. private void button8_Click(object sender, EventArgs e)
  880. {
  881.  
  882. string pal = "[";
  883. string ifcode = "if(false ){}";
  884.  
  885.  
  886. var colors = utils.GetStaticPropertyBag(typeof(Color));
  887.  
  888. int i = 0;
  889.  
  890. foreach (KeyValuePair<string, object> colorPair in colors)
  891. {
  892. //Console.WriteLine(colorPair.Key);
  893. Color c = (Color)colorPair.Value;
  894. pal += "{\"r\":" + c.R + ",\"g\":" + c.G + ",\"b\":" + c.B + ",\"a\":255},";
  895. ColorArray.Add(c);
  896. ifcode += "else if(cc.Name == \"" + c.Name + "\"){a.Color = " + i + ";}";
  897. i++;
  898. }
  899. //Console.WriteLine(pal);
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908. //foreach (var n in Enum.GetNames(typeof(ConsoleColor)))
  909. //{
  910. // Color c = Color.FromName(n);
  911.  
  912. // pal += "{\"r\":" + c.R + ",\"g\":" + c.G + ",\"b\":" + c.B + ",\"a\":255},";
  913. // ifcode += "else if(cc.ToString() == \"" + n + "\"){a.Color = " + i + ";}";
  914. // i++;
  915. //}
  916. //Console.WriteLine(pal);
  917. //Console.WriteLine(ifcode);
  918.  
  919.  
  920.  
  921. //load img
  922. System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(textBox4.Lines[0]);
  923.  
  924.  
  925. string json_orig = MapStoreUtils.Decode(File.ReadAllBytes("pixelart.bnlbin"));
  926. Json.JsonData json = Json.JsonParser.Parse(json_orig);
  927. //Vector3s size = new Vector3s(Json.Read.Int(json.Object["map"].Object["size"].Object["x"]), Json.Read.Int(json.Object["map"].Object["size"].Object["y"]), Json.Read.Int(json.Object["map"].Object["size"].Object["z"]));
  928. Vector3s size = new Vector3s(bmp.Height, 36, bmp.Width);//height should be 36
  929. //MapBinary mb = new global::MapBinary(Json.Read.Binary(json.Object["map"].Object["blocks_data"]), size);
  930. //BlockMap3D orig_blocks = mb.ToMap3D();
  931. Console.WriteLine(size.x);
  932. BlockMap3D new_blocks = GeneratePixelArt(size, bmp);
  933. byte[] colors2 = global::MapBinary.EncodeColors(new_blocks);
  934.  
  935.  
  936.  
  937.  
  938. //save the map
  939. json.Object["name"] = Json.Write.String("generated map");
  940. json.Object["map"].Object["blocks_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(MapBinary.Pack2(new_blocks));
  941. json.Object["map"].Object["colors_data"] = Json.Write.Optional<byte[]>(new Func<byte[], Json.JsonData>(Json.Write.Binary)).Invoke(colors2);
  942.  
  943. //size
  944. json.Object["map"].Object["size"].Object["x"] = Json.Write.Int(size.x);
  945. json.Object["map"].Object["size"].Object["y"] = Json.Write.Int(size.y);
  946. json.Object["map"].Object["size"].Object["z"] = Json.Write.Int(size.z);
  947.  
  948. //colors shit
  949. json.Object["map"].Object["color_palette"] = Json.Write.String(pal + "]");
  950.  
  951. string json_fixed = json.ToString().Replace("\\", "").Replace("\"color_palette\":\"[", "\"color_palette\":[").Replace(",]\",\"spawn", "],\"spawn");
  952. byte[] compressed = MapStoreUtils.Encode(json_fixed);
  953. File.Create(save_to.Lines[0]).Close();
  954. File.WriteAllBytes(save_to.Lines[0], compressed);
  955. File.WriteAllText(save_to.Lines[0] + "_json.txt", json_fixed);
  956. //release
  957. File.Create(@"map-generated.bnlbin").Close();
  958. File.WriteAllBytes(@"map-generated.bnlbin", compressed);
  959. }
  960.  
  961. private void button9_Click(object sender, EventArgs e)
  962. {
  963. OpenFileDialog ofd = new OpenFileDialog();
  964. // bmp, gif, jpg, png, tif and dds
  965. ofd.Filter = "map|*.*";
  966. ofd.CheckFileExists = true;
  967. ofd.Title = "Open map";
  968. if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
  969. {
  970. // Debug.WriteLine(ofd.FileName);
  971. //textBox3.Lines[0] = "2"; //ofd.FileName;
  972. textBox4.Lines = ofd.FileName.Split("?".ToCharArray());
  973. }
  974. }
  975. }
  976. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement