io.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. function redraw()
  2. {
  3. drawfigure("player_avatar", player);
  4. if (rival.name !== "") drawfigure("rival_avatar", rival);
  5. else {
  6. var canvas = document.getElementById("rival_avatar");
  7. var ctx = canvas.getContext("2d");
  8. ctx.beginPath();
  9. ctx.clearRect(0, 0, canvas.width, canvas.height);
  10. ctx.beginPath();
  11. var w = canvas.width;
  12. canvas.width = 1;
  13. canvas.width = w;
  14. }
  15. drawStats();
  16. }
  17. var defaultWindow = ShowCamp;
  18. var windows = [];
  19. function NextWindow(){
  20. if(windows.length>0){
  21. var nxt =windows.pop();
  22. nxt();
  23. }else{//next round?
  24. defaultWindow();
  25. }
  26. }
  27. function newWindow(windowFunc){
  28. windows.unshift(windowFunc);
  29. }
  30. function drawStats()
  31. {
  32. function calcStatWidth(stat) { return stat >= 50 ? (stat - 50) * 2 : (50 - stat) * 1.9; }
  33. function appendStat(elem, type, avatar){
  34. var avatarObj = eval(avatar);
  35. var appendTo;
  36. if (avatarObj == player) {
  37. appendTo = ".stat-bar--masc";
  38. $(elem).children(appendTo).first().append("<div class='avatar-stat avatar-stat--maxmin'></div>");
  39. $(elem).children(appendTo).first().children(".avatar-stat--maxmin").first().css("width", calcStatWidth(avatarObj.minimums[type])+"%");
  40. appendTo = ".stat-bar--fem";
  41. $(elem).children(appendTo).first().append("<div class='avatar-stat avatar-stat--maxmin'></div>");
  42. $(elem).children(appendTo).first().children(".avatar-stat--maxmin").first().css("width", calcStatWidth(avatarObj.maximums[type])+"%");
  43. }
  44. appendTo = avatarObj[type] >= 50 ? ".stat-bar--fem" : ".stat-bar--masc";
  45. $(elem).children(appendTo).first().append("<div class='avatar-stat avatar-stat--"+avatar+"'></div>");
  46. $(elem).children(appendTo).first().children(".avatar-stat--"+avatar).first().css("width", calcStatWidth(avatarObj[type])+"%");
  47. }
  48. $(".stat-bar-container").each(function(){
  49. $(this).empty();
  50. $(this).append("<span class='stat-bar stat-bar--fem'></span><span class='stat-bar stat-bar--masc'></span>");
  51. var type = $(this).attr("id");
  52. appendStat(this, type, "player");
  53. appendStat(this, type, "rival");
  54. });
  55. $("#player_changra").html(player.changra);
  56. if (getPerceptionRate() >= getRandomInt(0, 100)) $("#rival_changra").html(rival.changra);
  57. else $("#rival_changra").html("?");
  58. $("#player_women").html(player.women.length);
  59. $("#rival_women").html(rival.women.length);
  60. $("#player_perception").html(player.perception());
  61. $("#player_experience").html(player.experience);
  62. }
  63. function ChoiceMessage(message,title,options){
  64. var wnd= function(){
  65. var buttons = "";
  66. for(var o in options){
  67. buttons+=`<button id="${o}" class="btn push--right" title=${options[o].text}>${options[o].text}</button>`;
  68. }
  69. var msg = `<h1>${title}</h1>${message}`;
  70. $(".stats").hide();
  71. $("#output").html("<div id='message'></div>\
  72. <div id='end_buttons' class='push--top'></div>");
  73. $("#message").html(msg);
  74. $("#end_buttons").html(buttons);
  75. for(var o in options){
  76. $("#"+o).click(options[o].action);
  77. }
  78. redraw();
  79. }
  80. newWindow(wnd);
  81. }
  82. function EndRound(){
  83. Camp();
  84. }
  85. function Message(action, message, noclick,character){
  86. var wnd = function(){
  87. $(".stats").hide();
  88. $("#output").html("<div id='message' class='clickable'>"+message+"</div>");
  89. if(character){
  90. rival=character;
  91. redraw();
  92. }
  93. if (noclick !== true) {
  94. $("#message").append("<p align='center'><font size='-4'>click to continue</font></p>");
  95. $("#message").click(
  96. function() {
  97. $(".stats").show();
  98. if(typeof action=="string"){
  99. eval(action);
  100. }else if(typeof action=="function"){
  101. action();
  102. }
  103. }
  104. );
  105. }
  106. }
  107. newWindow(wnd);
  108. }