Changes

m
Replace deprecated <source> tags with <syntaxhighlight> tags
Line 10: Line 10:  
| {{#expr:({{{broken|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% are broken and not open-source.¹
 
| {{#expr:({{{broken|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% are broken and not open-source.¹
 
|}
 
|}
<small>¹ Many of these broke in Stardew Valley 1.1 or 1.2. Some may be updated by their authors.</small><noinclude>
+
<small>¹ Many of these broke due to a Stardew Valley update. Some may be updated by their authors later.</small><noinclude>
    
==Usage==
 
==Usage==
Line 25: Line 25:     
==Script==
 
==Script==
This tiny script generates the template call when run from the parent page.
+
This script generates the template call when run from the parent page.
<source lang="javascript">
+
<syntaxhighlight lang="javascript">
var entries = $("#mod-list tr[data-status]");
+
(function() {
var ok = entries.filter("[data-status='ok'], [data-status='optional']").length;
+
  // group mods by status
var workaround = entries.filter("[data-status='workaround'], [data-status='obsolete']").length;
+
  let counts = { ok: 0, workaround: 0, soon: 0, broken: 0, total: 0 };
var soon = entries.filter("[data-status='broken'][data-has-source], [data-status='soon-official']").length;
+
  let invalidMods = [];
var broken = entries.filter("[data-status='broken']:not([data-has-source])").length;
+
  $("#mod-list .mod").each(function(i, entry) {
var total = ok + workaround + soon + broken;
+
    entry = $(entry);
 +
    let status = entry.attr("data-beta-status") || entry.attr("data-status");
 +
    let hasSource = entry.is("[data-github], [data-custom-source]");
 +
   
 +
    switch(status) {
 +
      // ignore obsolete mods
 +
      case "abandoned":
 +
      case "obsolete":
 +
        break;
   −
if (total != entries.length) {
+
      // compatible
  var unknown = entries.filter(":not([data-status='ok'], [data-status='optional'], [data-status='workaround'], [data-status='obsolete'], [data-status='broken'], [data-status='soon-official'])");
+
      case "ok":
  console.log("found entries with unknown status:", unknown);
+
      case "optional":
  throw 'script failed';
+
        counts.ok++;
}
+
        counts.total++;
 +
        break;
   −
`
+
      // workaround
{{/barchart
+
      case "workaround":
  |ok        = ${ok}
+
      case "unofficial":
  |workaround = ${workaround}
+
        counts.workaround++;
  |soon      = ${soon}
+
        counts.total++;
  |broken    = ${broken}
+
        break;
  |total      = ${total}
+
 
}}
+
      // soon/broken
`</source>
+
      case "broken":
 +
        if (hasSource)
 +
          counts.soon++;
 +
        else
 +
          counts.broken++;
 +
        counts.total++;
 +
        break;
 +
 
 +
      default:
 +
        invalidMods.push(mods);
 +
        break;
 +
    }
 +
  });
 +
 
 +
  // show results
 +
  if (invalidMods.length) {
 +
    console.log("found entries with unknown status:", invalidMods);
 +
    throw 'script failed';
 +
  }
 +
 
 +
  console.log(`
 +
    {{/barchart
 +
      |ok        = ${counts.ok}
 +
      |workaround = ${counts.workaround}
 +
      |soon      = ${counts.soon}
 +
      |broken    = ${counts.broken}
 +
      |total      = ${counts.total}
 +
    }}
 +
  `.replace(/^    /mg, ''));
 +
})();
 +
</syntaxhighlight>
   −
[[Category:Modding]]</noinclude>
+
[[Category:Modding]]
 +
[[de:Modding:SMAPI Kompatibilität/barchart]]
 +
</noinclude>
114

edits