Difference between revisions of "Modding:Mod compatibility/barchart"

From Stardew Valley Wiki
Jump to navigation Jump to search
(tweak format, update script)
m
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
| <div style="display: inline-block; width: {{#expr:({{{ok|0}}} + {{{workaround|0}}}) * 2}}px; background: #9F9;">&nbsp;</div>
+
| <div style="display: inline-block; width: {{#expr:(({{{ok|0}}} + {{{workaround|0}}}) / {{{total|<noinclude>1</noinclude>0}}}) * 200}}px; background: #9F9;">&nbsp;</div>
| {{#expr:{{{ok|0}}} + {{{workaround|0}}}}}% are compatible or have a working alternative.
+
| {{#expr:(({{{ok|0}}} + {{{workaround|0}}}) / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% are compatible or have a working alternative.
 
|-
 
|-
| <div style="display: inline-block; width: {{#expr:{{{soon|0}}} * 2}}px; background: #FF9;">&nbsp;</div>
+
| <div style="display: inline-block; width: {{#expr:({{{soon|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 200}}px; background: #FF9;">&nbsp;</div>
| {{{soon|0}}}% have an update coming soon.
+
| {{#expr:({{{soon|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 100 round 0}}% have an update coming soon.
 
|-
 
|-
| <div style="display: inline-block; width: {{#expr:{{{broken|0}}} * 2}}px; background: #F99;">&nbsp;</div>
+
| <div style="display: inline-block; width: {{#expr:({{{broken|0}}} / {{{total|<noinclude>1</noinclude>0}}}) * 200}}px; background: #F99;">&nbsp;</div>
| {{{broken|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==
List the percentage values for each group:
+
List the counts for each group:
 
<pre>
 
<pre>
 
{{/barchart
 
{{/barchart
   |ok        = 52
+
   |ok        = 135
   |workaround = 23
+
   |workaround = 33
   |soon      = 10
+
   |soon      = 56
   |broken    = 15
+
   |broken    = 33
 +
  |total      = 257
 
}}
 
}}
 
</pre>
 
</pre>
  
 
==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 ok = $("#mod-list tr[data-status='ok']").length;
+
(function() {
var workaround = $("#mod-list tr[data-status='workaround']").length;
+
  // group mods by status
var soon = $("#mod-list tr[data-status='soon']").length;
+
  let counts = { ok: 0, workaround: 0, soon: 0, broken: 0, total: 0 };
var broken = $("#mod-list tr[data-status='broken']").length;
+
  let invalidMods = [];
 +
  $("#mod-list .mod").each(function(i, entry) {
 +
    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;
  
var total = ok + workaround + soon + broken;
+
      // compatible
var okPercent = Math.round(ok / total * 100);
+
      case "ok":
var workaroundPercent = Math.round(workaround / total * 100);
+
      case "optional":
var soonPercent = Math.round(soon / total * 100);
+
        counts.ok++;
var brokenPercent = Math.round(broken / total * 100);
+
        counts.total++;
 +
        break;
  
`
+
      // workaround
{{/barchart
+
      case "workaround":
  |ok        = ${okPercent}
+
      case "unofficial":
  |workaround = ${workaroundPercent}
+
        counts.workaround++;
  |soon      = ${soonPercent}
+
        counts.total++;
  |broken    = ${brokenPercent}
+
        break;
}}
+
 
`
+
      // 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]]
 +
[[tr:Modlama:Mod Uyumluluğu/barchart]]
 +
</noinclude>

Latest revision as of 12:29, 12 July 2024

 
0% are compatible or have a working alternative.
 
0% have an update coming soon.
 
0% are broken and not open-source.¹

¹ Many of these broke due to a Stardew Valley update. Some may be updated by their authors later.

Usage

List the counts for each group:

{{/barchart
  |ok         = 135
  |workaround = 33
  |soon       = 56
  |broken     = 33
  |total      = 257
}}

Script

This script generates the template call when run from the parent page.

(function() {
  // group mods by status
  let counts = { ok: 0, workaround: 0, soon: 0, broken: 0, total: 0 };
  let invalidMods = [];
  $("#mod-list .mod").each(function(i, entry) {
    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;

      // compatible
      case "ok":
      case "optional":
        counts.ok++;
        counts.total++;
        break;

      // workaround
      case "workaround":
      case "unofficial":
        counts.workaround++;
        counts.total++;
        break;

      // soon/broken
      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, ''));
})();