test2.nim 2.6 KB

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