test2.nim 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # --- Test 2. Work with default nodes. --- #
  2. import
  3. nodesnim,
  4. unittest
  5. suite "Work with default nodes.":
  6. test "Setup window":
  7. Window("default nodes test")
  8. test "Setup scene":
  9. build:
  10. - Scene main
  11. addMainScene(main)
  12. test "Canvas test":
  13. build:
  14. - Canvas canvas:
  15. call:
  16. resize(256, 256)
  17. fill(Color("#ffaacc"))
  18. point(5, 5, Color("#64ffff"))
  19. line(8, 16, 128, 64, Color("#ffff64ff"))
  20. circle(0, 240, 32, Color("#aaff6456"))
  21. line(200, -150, 0, 256, Color("#0e1317ff"))
  22. bezier(0, 0, 256, 0, 256, 256, Color("#227"))
  23. cubic_bezier(0, 0, 256, 0, 0, 256, 256, 256, Color("#272"))
  24. move(74.4, 89.4)
  25. text("hello!,\nworld!", 64, 64, Vector2(1, 1))
  26. saveAs("assets/canvas.png") # save result in file.
  27. getSceneByName("main").addChild(canvas)
  28. test "AudioStreamPlayer test":
  29. build:
  30. - AudioStreamPlayer audio1:
  31. stream: loadAudio("assets/vug_ost_Weh.ogg")
  32. call setVolume(64) # 64/100
  33. call play()
  34. getSceneByName("main").addChild(audio1)
  35. test "Duplicate nodes":
  36. build:
  37. - Node node(name: "MyOwnNode")
  38. var node1 = node.duplicate()
  39. assert node.name == node1.name
  40. test "AnimationPlayer node":
  41. build:
  42. - ColorRect rect:
  43. color: Color(0, 0, 0)
  44. call resize(100, 100)
  45. - ColorRect rect1:
  46. color: Color(0, 0, 0)
  47. call resize(100, 100)
  48. call move(0, 150)
  49. - ColorRect rect2:
  50. color: Color(0.5, 0.8, 0.5)
  51. call resize(100, 100)
  52. call move(0, 300)
  53. - AnimationPlayer animation:
  54. mode: ANIMATION_NORMAL # Default animation mode.
  55. call:
  56. addState(rect.color.r.addr, @[(tick: 0, value: 0.0), (tick: 200, value: 1.0)])
  57. addState(rect.position.x.addr, @[(tick: 0, value: 0.0), (tick: 100, value: 250.0)])
  58. setDuration(200)
  59. play()
  60. - AnimationPlayer animation1:
  61. mode: ANIMATION_EASE
  62. call:
  63. addState(rect1.position.x.addr, @[(tick: 0, value: 0.0), (tick: 100, value: 250.0)])
  64. setDuration(200)
  65. play()
  66. - AnimationPlayer animation2:
  67. mode: ANIMATION_BEZIER
  68. bezier: (0.8, 0.9)
  69. call:
  70. addState(rect2.position.x.addr, @[(tick: 0, value: 0.0), (tick: 100, value: 250.0)])
  71. setDuration(200)
  72. play()
  73. getSceneByName("main").addChildren(rect, rect1, rect2, animation, animation1, animation2)
  74. test "Launch window":
  75. windowLaunch()