not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.7 KiB

  1. function StandardAbacusColumn(x,starty,endy,blockstop,blocksbottom,blocksheight,colcols,blockcols,abacus,value,isupper,aging,schety){
  2. if (aging === undefined) aging=true;
  3. if (schety === undefined) schety=false;
  4. this.elements = [];
  5. this.colWidthScale = 8/33;
  6. this.blockcols = blockcols;
  7. this.value = value;
  8. this.drawColumn = function(){
  9. //grey: A0A0A0, stroke 6B6B6B
  10. var width = this.colWidthScale*abacus.blockWidth;
  11. var height = endy-starty;
  12. //console.log(width);
  13. //console.log(height);
  14. //console.log(x);
  15. //console.log(starty);
  16. var rect = new createjs.Shape();
  17. rect.graphics.beginFill(this.blockcols[0]).drawRect(-1*(width/2),0,width,height);
  18. rect.graphics.beginStroke(this.blockcols[1]);
  19. rect.graphics.setStrokeStyle(width/8);
  20. rect.graphics.moveTo(-1*(width/2),0);
  21. rect.graphics.lineTo(-1*(width/2),height);
  22. rect.graphics.moveTo((width/2),0);
  23. rect.graphics.lineTo((width/2),height);
  24. rect.x = x;
  25. rect.y = starty;
  26. abacus.stage.addChild(rect);
  27. }
  28. this.updateY = function(){
  29. var bmargin = (abacus.verticalMargin*abacus.blockHeight);
  30. var start = starty+(bmargin/2);
  31. var incr = abacus.blockHeight+bmargin;
  32. for (var i = 0; i<blocksheight; i++){
  33. if (this.elements[i]!=null){
  34. this.elements[i].updateIndex(i);
  35. this.elements[i].updateY(start);
  36. if (isupper==true&&this.elements.lastIndexOf(null)<i){
  37. this.elements[i].updateValue(true);
  38. } else if (isupper==false&&this.elements.indexOf(null)>i){
  39. this.elements[i].updateValue(true);
  40. } else {
  41. this.elements[i].updateValue(false);
  42. }
  43. }
  44. start+=incr;
  45. }
  46. //console.log(this.howManyInUse());
  47. abacus.updateTextItems();
  48. }
  49. this.initElements = function(){
  50. this.elements = [];
  51. var middlea;
  52. var middleb;
  53. if (schety==true){
  54. middlea=(blocksheight-blocksbottom)+blocksbottom/2-1;
  55. middleb=(blocksheight-blocksbottom)+(blocksbottom/2);
  56. }
  57. for (var i = 0; i<blocksheight; i++){
  58. if ((i<blockstop)||(i>=blocksheight-blocksbottom)){
  59. if (schety==true&&(i==middlea||i==middleb)){
  60. var b = new AbacusBead(x,starty,"#000",abacus,this,i,value);
  61. } else {
  62. var b = new AbacusBead(x,starty,colcols,abacus,this,i,value);
  63. }
  64. b.init();
  65. //console.log(b);
  66. this.elements.push(b);
  67. } else {
  68. this.elements.push(null);
  69. }
  70. }
  71. }
  72. this.shuntLeft = function(index){
  73. if (this.elements.lastIndexOf(null)<index){
  74. var placeindex = this.elements.indexOf(null);
  75. var startindex = this.elements.lastIndexOf(null)+1;
  76. var length = index-startindex+1;
  77. var movearray = this.elements.splice(startindex,length);
  78. //for (var i = 0; i<movearray.length; i++){
  79. // movearray[i].resetAge();
  80. //}
  81. var args = [placeindex, 0].concat(movearray);
  82. Array.prototype.splice.apply(this.elements, args);
  83. this.updateY();
  84. }
  85. }
  86. this.shuntRight = function(index){
  87. if (this.elements.indexOf(null)>index){
  88. console.log("start");
  89. console.log(this.elements);
  90. var placeindex = this.elements.lastIndexOf(null)+1;
  91. var endindex = this.elements.indexOf(null)-1;
  92. var length = endindex-index+1;
  93. var movearray = this.elements.splice(index,length);
  94. console.log(movearray);
  95. //for (var i = 0; i<movearray.length; i++){
  96. // movearray[i].resetAge();
  97. //}
  98. console.log(this.elements);
  99. var args = [placeindex-length, 0].concat(movearray);
  100. Array.prototype.splice.apply(this.elements, args);
  101. this.updateY();
  102. //console.log(this.elements);
  103. }
  104. }
  105. this.howManyInUse = function(){
  106. if (isupper==true){
  107. var index = this.elements.lastIndexOf(null);
  108. if (index!=this.elements.length-1){
  109. return this.elements.slice(index+1,this.elements.length);
  110. } else {
  111. return [];
  112. }
  113. } else {
  114. var index = this.elements.indexOf(null);
  115. if (index!=0){
  116. return this.elements.slice(0,index);
  117. } else {
  118. return [];
  119. }
  120. }
  121. }
  122. this.updateAges = function(){
  123. for (var i = 0; i<this.elements.length; i++){
  124. if (this.elements[i]!=null&&aging==true){
  125. this.elements[i].updateAge();
  126. }
  127. }
  128. }
  129. this.restore = function(arr){
  130. var newelements = [];
  131. for (var i = 0; i<this.elements.length; i++){
  132. if (this.elements[i]!=null){
  133. newelements.push(this.elements[i]);
  134. }
  135. }
  136. this.elements = newelements;
  137. for (var i = 0; i<arr.length; i++){
  138. if (arr[i] == null){
  139. this.elements.splice(i, 0, null);
  140. }
  141. }
  142. //console.log(this.elements);
  143. this.updateY();
  144. }
  145. this.restoreAge = function(arr){
  146. for (var i = 0; i<this.elements.length; i++){
  147. if (this.elements[i]!=null){
  148. this.elements[i].forceAge(arr[i]);
  149. }
  150. }
  151. }
  152. this.save = function(){
  153. var arr = [];
  154. for (var i = 0; i<this.elements.length; i++){
  155. if (this.elements[i]==null){
  156. arr.push(null);
  157. } else {
  158. arr.push(this.elements[i].age);
  159. }
  160. }
  161. return arr;
  162. }
  163. this.init = function(){
  164. this.drawColumn();
  165. this.initElements();
  166. this.updateY();
  167. }
  168. }