laneya2

cave exploration game
git clone https://git.ce9e.org/laneya2.git

commit
5362c5ca5388f3bf9786e57d8d118537a9f715ab
parent
9f57e1ad60fc62cad49d86ee1a4ec092c6d928fb
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-09-26 06:48
refactor commitSpan

Diffstat

M static/main.js 23 +++++++++++------------

1 files changed, 11 insertions, 12 deletions


diff --git a/static/main.js b/static/main.js

@@ -158,35 +158,34 @@ var render = function() {
  158   158 
  159   159     $pre.style.fontSize = fontSize;
  160   160     $pre.innerHTML = '';
  161    -1     var spanColor = -1;
  162    -1     var span = '';
  163   161 
  164    -1     var commitSpan = () => {
  165    -1         if (spanColor === -1) {
  166    -1             $pre.append(span);
   -1   162     var commitSpan = (text, color) => {
   -1   163         if (color === -1) {
   -1   164             $pre.append(text);
  167   165         } else {
  168   166             var $span = document.createElement('span');
  169    -1             $span.innerText = span;
  170    -1             $span.className = `color-${spanColor}`;
   -1   167             $span.innerText = text;
   -1   168             $span.className = `color-${color}`;
  171   169             $pre.append($span);
  172   170         }
  173    -1         span = '';
  174    -1         spanColor = -1;
  175   171     };
  176   172 
  177    -1     for (let y = 0; y < rows; y++) {
   -1   173     for (let y = 1; y < rows; y++) {
   -1   174         var span = '';
   -1   175         var spanColor = -1;
   -1   176 
  178   177         for (let x = 0; x < cols; x++) {
  179   178             const [c, color] = game.getChar(xOffset + x, yOffset + y);
  180   179             if (color === spanColor) {
  181   180                 span += c;
  182   181             } else {
  183    -1                 commitSpan();
   -1   182                 commitSpan(span, spanColor);
  184   183                 span = c;
  185   184                 spanColor = color;
  186   185             }
  187   186         }
  188   187 
  189    -1         commitSpan();
   -1   188         commitSpan(span, spanColor);
  190   189         $pre.append('\n');
  191   190     }
  192   191 };