Changes

Jump to navigation Jump to search
→‎Refactoring: update & rework item key proposal, link to detailed proposal document
Line 17: Line 17:     
===Refactoring===
 
===Refactoring===
<ul>
+
* Add unique item keys and allow custom spritesheets per item. This would eliminate the current complexities with adding custom items to Stardew Valley, make code much more readable, simplify troubleshooting mod errors, and make it possible to support any item type in cases like sending mail. See the [https://gist.github.com/Pathoschild/92d1fcb7c2ffeb7e1461c242cdb025e2 detailed proposal doc].
<li>Replace <tt>Item.ParentSheetIndex</tt> with three properties:
+
* ☐ Change all <code>const</code> fields to <code>static readonly</code>. They're accessed the same way and the performance difference is negligible, but that'll make the decompiled code much easier to understand, and avoid issues where const values get 'baked in' to mod assemblies.
 
  −
{| class="wikitable"
  −
|-
  −
! field
  −
! type
  −
! notes
  −
|-
  −
| <tt>ID</tt>
  −
| <tt>string</tt>
  −
| An ID unique across all item types (like <tt>parsnip</tt> or <tt>radish_salad</tt>). That would allow unambiguous and human-readable item references throughout the code (e.g. gift tastes, machine behaviour, etc), fix bugs like the wallpaper glitch, and make it easy to avoid ID collisions in mods (e.g. <tt>spacechase0.JsonAssets/watermelon</tt>).
  −
|-
  −
| <tt>Sheet</tt>
  −
| <tt>Texture2D</tt>
  −
| The spritesheet to draw (e.g. <tt>Game1.objectSpriteSheet</tt>). This lets modders easily add custom items with their own spritesheet, and simplifies draw logic.
  −
|-
  −
| <tt>SheetIndex</tt>
  −
| <tt>int</tt>
  −
| Equivalent to the old <tt>ParentSheetIndex</tt>, but for the <tt>Sheet</tt> texture. No longer used as an ID.
  −
|}
  −
Files like <tt>Data/ObjectInformation</tt> would be updated to use the new IDs:
  −
<syntaxhighlight lang="yaml">
  −
# old format
  −
634: "Apricot/50/15/Basic -79/Apricot/A tender little fruit with a rock-hard pit."
  −
629: "Apricot Sapling/500/-300/Basic -74/Apricot Sapling/Takes 28 days to produce a mature Apricot tree. Bears fruit in the spring. Only grows if the 8 surrounding \"tiles\" are empty."
  −
 
  −
# new format
  −
apricot: "634/Apricot/50/15/Basic -79/A tender little fruit with a rock-hard pit."
  −
apricot_sapling: "629/Apricot Sapling/500/-300/Basic -74/Takes 28 days to produce a mature Apricot tree. Bears fruit in the spring. Only grows if the 8 surrounding \"tiles\" are empty."
  −
</syntaxhighlight>
  −
With equivalent changes in files like <tt>Data/NPCGiftTastes</tt>:
  −
<syntaxhighlight lang="yaml">
  −
# old format
  −
Universal_Like: "-2 -7 -26 -75 -80 72 395 613 634 635 636 637 638 724 459"
  −
 
  −
# new format
  −
Universal_Like: "-2 -7 -26 -75 -80 apple apricot cherry coffee maple_syrup mead orange peach pomegranate shrimp"
  −
</syntaxhighlight>
  −
 
  −
Creating a vanilla item would use a key lookup like before:
  −
<syntaxhighlight lang="C#">
  −
Object item = new Object("apricot"); // equivalent to new Object("apricot", "Maps/springobjects", 634, ...);
  −
</syntaxhighlight>
  −
 
  −
This also avoids needing to check item types in most code (e.g. no need to exclude bigcraftables in gift tastes, since there's no possible ID overlap with the IDs listed in <tt>Data/NPCGiftTastes</tt>).
  −
</li>
  −
<li>☐ Change all <code>const</code> fields to <code>static readonly</code>. They're accessed the same way and the performance difference is negligible, but that'll make the decompiled code much easier to understand, and avoid issues where const values get 'baked in' to mod assemblies.</li>
  −
</ul>
      
==Completed items==
 
==Completed items==
translators
8,439

edits

Navigation menu