folds.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. FOLDS
  3. Folds are two adjacent Faces joined together, as if one
  4. long 6 x 3 strip has been folding down the center and
  5. three such shapes together wrap the six sides of the Cube.
  6. Currently this is important for text wrapping. And in the
  7. future? Who knows. Characters in a String are mapped thus:
  8. LEFT FACE
  9. RIGHT FACE
  10. -------- -------- --------
  11. | | | |-------- -------- --------
  12. | 0 | 1 | 2 | | | |
  13. | | | | 3 | 4 | 5 |
  14. -------- -------- -------- | | |
  15. | | | |-------- -------- --------
  16. | 6 | 7 | 8 | | | |
  17. | | | | 9 | 10 | 11 |
  18. -------- -------- -------- | | |
  19. | | | |-------- -------- --------
  20. | 12 | 13 | 14 | | | |
  21. | | | | 15 | 16 | 17 |
  22. -------- -------- -------- | | |
  23. -------- -------- --------
  24. ^
  25. |
  26. FOLD LINE
  27. Currently Folds are only intended to be created and
  28. heroized after the first Cube mapping. After the Cube
  29. twists things would get rather weird...
  30. */
  31. export function Fold( left, right ){
  32. this.map = [
  33. left.northWest[ left.face ].text,
  34. left.north[ left.face ].text,
  35. left.northEast[ left.face ].text,
  36. right.northWest[ right.face ].text,
  37. right.north[ right.face ].text,
  38. right.northEast[ right.face ].text,
  39. left.west[ left.face ].text,
  40. left.origin[ left.face ].text,
  41. left.east[ left.face ].text,
  42. right.west[ right.face ].text,
  43. right.origin[ right.face ].text,
  44. right.east[ right.face ].text,
  45. left.southWest[ left.face ].text,
  46. left.south[ left.face ].text,
  47. left.southEast[ left.face ].text,
  48. right.southWest[ right.face ].text,
  49. right.south[ right.face ].text,
  50. right.southEast[ right.face ].text
  51. ]
  52. }
  53. Fold.prototype.getText = function(){
  54. var text = ''
  55. this.map.forEach( function( element ){
  56. text += element.innerHTML
  57. })
  58. return text
  59. }
  60. Fold.prototype.setText = function( text ){
  61. var i
  62. text = text.justifyLeft( 18 )
  63. for( i = 0; i < 18; i ++ ){
  64. this.map[ i ].innerHTML = text.substr( i, 1 )
  65. }
  66. }