tiles.rs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* This file is to show and setup a decent population of tiles (possibly to be used in-game)
  2. This shows:
  3. + How to check there are tiles, and if they don't exist, pre-populate some in
  4. + Iterate all the tiles and display the juicy inners of each tile
  5. */
  6. use std::path::PathBuf;
  7. use anyhow::bail;
  8. use rmmo::{TileIndex, Tile};
  9. fn main() -> Result<(), anyhow::Error> {
  10. match TileIndex::load(PathBuf::from("data/tiles.json")) {
  11. Ok(ti) => {
  12. println!("Loaded {} tiles:", ti.len());
  13. let mut idx = 0;
  14. for t in ti {
  15. if let Some(desc) = t.description {
  16. println!("{:3}] name=\"{:25}\" \"{:1}\" color=\"{:25}\" description=\"{}\"", idx, t.name, t.symbol, t.color, desc);
  17. } else {
  18. println!("{:3}] name=\"{:25}\" \"{:1}\" color=\"{:25}\" description=None", idx, t.name, t.symbol, t.color);
  19. }
  20. idx += 1;
  21. }
  22. },
  23. Err(err) => {
  24. // Covers Windows and Linux "Not Found" error message (If it isn't either of these bail)
  25. if err.to_string() != "The system cannot find the file specified. (os error 2)" && err.to_string() != "No such file or directory (os error 2)" {
  26. bail!(err);
  27. }
  28. // Ok must be "Not Found", so let's make a new one
  29. let mut ti = TileIndex::new();
  30. //ti.define(Tile::new("", "", ""));
  31. //ti.define(Tile::with_description("", "", "", ""));
  32. ti.define(Tile::with_description("void", "", "", "You can fly over this, or fall into it"));
  33. ti.define(Tile::with_description("player", "@", "bright green", "You"));
  34. ti.define(Tile::with_description("player-neutral", "@", "bright white", "Another player"));
  35. ti.define(Tile::with_description("player-ally", "@", "green", "Another player, an ally"));
  36. ti.define(Tile::with_description("player-enemy", "@", "bright red", "Another player, an enemy"));
  37. ti.define(Tile::with_description("path-grass", ".", "green", "A grassy path"));
  38. ti.define(Tile::with_description("path-stone", ".", "white", "A stoney path"));
  39. ti.define(Tile::with_description("water-shallow", "~", "bright cyan", "Shallow Water (Movement 60%, Can swim"));
  40. ti.define(Tile::with_description("water-deep", "~", "bright blue", "Deep Water (Can not swim)"));
  41. ti.define(Tile::with_description("tree-small", "t", "green", "A small Tree, flammable, produces wood"));
  42. ti.define(Tile::with_description("tree-large", "T", "green", "A large Tree, flammable, produces wood"));
  43. ti.define(Tile::with_description("crystal-small", "*", "magenta", "A small crystal, probably from killing a monster"));
  44. ti.define(Tile::with_description("crystal-large", "*", "bright magenta", "A large crystal, probably from killing a monster"));
  45. ti.define(Tile::with_description("gold", "$", "bright yellow", "Some gold coins, useful to buy something"));
  46. ti.define(Tile::with_description("gem-red", "*", "red", "A ruby gemstone"));
  47. ti.define(Tile::with_description("gem-green", "*", "green", "A emerald gemstone"));
  48. ti.define(Tile::with_description("wall-v", "|", "white", "A stone wall"));
  49. ti.define(Tile::with_description("wall-h", "-", "white", "A stone wall"));
  50. ti.define(Tile::with_description("door-c", "+", "brown", "A wooden door, closed (maybe you should Open it?)"));
  51. ti.define(Tile::with_description("door-o", "-", "brown", "A wooden door, opened (you could Close it, or walk thru it)"));
  52. ti.define(Tile::with_description("stairs-up", ">", "white", "A staircase leading upward"));
  53. ti.define(Tile::with_description("stairs-down", "<", "white", "A staircase leading downward"));
  54. ti.define(Tile::with_description("checkpoint", ";", "bright cyan", "A checkpoint (useful for going to the surface, and returning to this level)"));
  55. ti.define(Tile::with_description("trap-disabled", "^", "white", "A trap, appears to be disabled or broken"));
  56. ti.define(Tile::with_description("trap-arrow", "^", "bright white", "A arrow trap"));
  57. ti.define(Tile::with_description("trap-bear", "^", "brown", "A bear trap, can cripple you for some time"));
  58. ti.define(Tile::with_description("trap-teleport", "^", "bright cyan", "A teleport trap, teleports you randomly between the upper level, this level or the next deeper level"));
  59. ti.define(Tile::with_description("trap-fire", "^", "red", "A fire trap, can ignite you dealing damage over time"));
  60. ti.define(Tile::with_description("trap-time", "^", "bright yellow", "A time stop trap, you will be caught in a magical time stop for quite some time"));
  61. ti.define(Tile::with_description("trap-sound", "^", "green", "A sound trap, will emit a loud sound (which will attract monsters near by)"));
  62. ti.define(Tile::with_description("food-ration", "%", "brown", "A food ration"));
  63. ti.define(Tile::with_description("food-apple", "%", "red", "A apple"));
  64. ti.define(Tile::with_description("food-egg", "%", "bright white", "A egg"));
  65. ti.define(Tile::with_description("food-c-chicken", "%", "bright yellow", "A can of chicken"));
  66. ti.define(Tile::with_description("food-c-tuna", "%", "bright cyan", "A can of tuna fish"));
  67. ti.define(Tile::with_description("key", "F", "bright white", "A key (used to unlock further dungeon levels)"));
  68. ti.define(Tile::with_description("potion-heal", "b", "red", "A potion of healing"));
  69. ti.define(Tile::with_description("potion-magic", "b", "cyan", "A potion of mana"));
  70. ti.define(Tile::with_description("potion-surface", "b", "bright cyan", "A potion of returning (Drink this to return to the surface)"));
  71. ti.define(Tile::with_description("potion-poison", "b", "green", "A potion of poison (Deals some damage over time)"));
  72. ti.define(Tile::with_description("potion-suicide", "b", "bright red", "A potion of suicide (Drink this to end it all)"));
  73. ti.define(Tile::with_description("monster-rat", "r", "brown", "A rat"));
  74. ti.define(Tile::with_description("monster-coyote", "c", "brown", "A coyote"));
  75. ti.define(Tile::with_description("monster-minotaur", "M", "brown", "The Minotaur (Level 5 Boss)"));
  76. ti.define(Tile::with_description("monster-wolf", "w", "white", "A wolf (Slightly bigger than a coyote, and twice as vicious)"));
  77. ti.define(Tile::with_description("monster-slime", "n", "green", "A green slimy ooze"));
  78. ti.define(Tile::with_description("monster-goblin", "G", "green", "A goblin"));
  79. ti.define(Tile::with_description("monster-troll", "T", "white", "A troll"));
  80. ti.define(Tile::with_description("monster-dragon-red", "D", "red", "The Red Dragon (Level 10 Boss)"));
  81. ti.define(Tile::with_description("monster-skeleton", "A", "bright white", "A skeleton"));
  82. ti.define(Tile::with_description("monster-s-troll", "T", "bright white", "A giant skeleton (Once was a troll)"));
  83. ti.define(Tile::with_description("monster-dragon-green", "D", "green", "The Green Dragon (Level 15 Boss)"));
  84. ti.define(Tile::with_description("monster-titan", "T", "bright magenta", "A giant Titan"));
  85. ti.define(Tile::with_description("monster-mimic-crystal", "*", "cyan", "A Mimic (appearing as some crystal)"));
  86. ti.save(PathBuf::from("data/tiles.json"))?;
  87. println!("Created {} tiles", ti.len());
  88. }
  89. }
  90. Ok(())
  91. }