Changes

Jump to navigation Jump to search
1,920 bytes added ,  17:59, 15 September 2019
Removed 'Send a letter' from Other section and made it an expanded section on Mail. Still in progress
Line 323: Line 323:  
// TODO: Examples with choices
 
// TODO: Examples with choices
   −
==Harmony==
  −
{{quote|Here be dragons. Thou art forewarned.}}
     −
[https://github.com/pardeike/Harmony Harmony] lets you patch Stardew Valley methods directly. This is very powerful, but comes with major caveats:
+
==Mail==
 +
If you are new to SMAPI or to modding Stardew Valley in general, sending a simple letter to the player's mailbox is a great place to start your learning journey. You will be treated to some simple to understand code and concepts, as well as receive some instant gratification in the form of a tangible, in-game letter that you can see in action.  If the examples in this section fall short, there are many folks available to assist you on the Discord channel (//TODO: Provide link).
   −
* It's very easy to cause crashes, errors, or subtle bugs, including difficult-to-diagnose memory corruption errors.
+
===Mail content===
* SMAPI can't detect incompatible Harmony code.
  −
* Crossplatform compatibility is not guaranteed, and should be tested on all three platforms.
  −
* May conflict with other Harmony mods (e.g. if two mods patch the same method, or two mods try to load different versions of Harmony).
  −
* Harmony patches may have unpredictable effects on other mods that aren't using Harmony.
  −
* Harmony patches may prevent you from attaching a debugger when testing.
     −
Using Harmony should be a last resort, and is deliberately not documented.
+
Before you can actually send any of your own custom mail to the player, you must decided how your letter will be composed.  By that I mean, is your letter static - always the same text - or is it dynamic - text changes based on a variable piece of information?  Obviously a static letter will be easier to implement, so if you are just starting off, go that route for now.  However, both static and dynamic methods are explained below.
   −
==Other==
+
To send mail, whether static or dynamic, you first have to let Stardew Valley know about your content, also referred to as an asset.  In the case of mail, you have to inject your additions into the mail data. You accomplish this via the IAssetEditor interface. You can implement IAssetEditor from your ModEntry class, or create a separate class that implements IAssetEditor to inject new mail content into "Data\Mail.xnb". The examples cited below use the latter approach for clarity, easy of reuse, and encapsulation:
===Add a small animation===
  −
<source lang="c#">
  −
location.temporarySprites.Add(new TemporaryAnimatedSprite(...))
  −
</source>
  −
See ''TemporaryAnimatedSprite'' for more details
     −
===Play a sound===
+
===Inject static content===
<source lang="c#">
  −
location.playSound("SOUND");
  −
</source>
  −
(e.g. "junimoMeep1")
     −
===Send a letter===
+
Most times a static, predefined letter will suffice, whether you are including an attachment (i.e. object, money, etc.) or not.  You can softly reference the player's name, using "@", but not much else.  Replace codes that work in dialog texts, like %pet or %farm, do not work in static mail content at this time.
   −
Before you can send any of your own custom mail you must use a class that implements (derives from) IAssetEditor to inject new mail content into "Data\Mail.xnb".  It doesn't have to be a separate class as ModEntry can also implement IAssetEditor. An example using a separate class is shown below:
+
The example below adds 3 letters into the mail data collection.  Note, that the code below does not send any letters to the player, but simply makes them available to Stardew Valley game so they can be sent.  "XML comments" for each method have bee removed to reduce clutter.
    
<source lang="c#">
 
<source lang="c#">
Line 386: Line 371:  
}
 
}
 
</source>
 
</source>
 +
 +
===Inject dynamic content===
 +
 +
//TODO: This will be expanded soon...  please check back!
 +
 +
 +
===Send a letter===
    
To make uses of this class in your own project, thereby making the mail data available, hook into the OnGameLaunch event, for example
 
To make uses of this class in your own project, thereby making the mail data available, hook into the OnGameLaunch event, for example
Line 400: Line 392:  
</source>
 
</source>
   −
To actually put one of your custom letters into the player's in-game mailbox, you can use a couple different methods, depending on your need.  Two examples are shown below.  The distinction between the two methods will be explained below:
+
Now that you have your letter loaded, it's time to send it to the player.  There are a couple different methods available to accomplish this as well, depending on your need.  Two examples are shown below.  The distinction between the two methods will be explained below:
    
<source lang="c#">
 
<source lang="c#">
Line 420: Line 412:     
That is all there is to sending a simple letter.  Attaching items, although mentioned in the source code comments above, will need some additional explanation at a future time.  Creating mail content dynamically, in respond to game conditions, is a little more complicated and will be covered in the future as well.
 
That is all there is to sending a simple letter.  Attaching items, although mentioned in the source code comments above, will need some additional explanation at a future time.  Creating mail content dynamically, in respond to game conditions, is a little more complicated and will be covered in the future as well.
 +
 +
==Harmony==
 +
{{quote|Here be dragons. Thou art forewarned.}}
 +
 +
[https://github.com/pardeike/Harmony Harmony] lets you patch Stardew Valley methods directly. This is very powerful, but comes with major caveats:
 +
 +
* It's very easy to cause crashes, errors, or subtle bugs, including difficult-to-diagnose memory corruption errors.
 +
* SMAPI can't detect incompatible Harmony code.
 +
* Crossplatform compatibility is not guaranteed, and should be tested on all three platforms.
 +
* May conflict with other Harmony mods (e.g. if two mods patch the same method, or two mods try to load different versions of Harmony).
 +
* Harmony patches may have unpredictable effects on other mods that aren't using Harmony.
 +
* Harmony patches may prevent you from attaching a debugger when testing.
 +
 +
Using Harmony should be a last resort, and is deliberately not documented.
 +
 +
==Other==
 +
===Add a small animation===
 +
<source lang="c#">
 +
location.temporarySprites.Add(new TemporaryAnimatedSprite(...))
 +
</source>
 +
See ''TemporaryAnimatedSprite'' for more details
 +
 +
===Play a sound===
 +
<source lang="c#">
 +
location.playSound("SOUND");
 +
</source>
 +
(e.g. "junimoMeep1")
    
==Open source==
 
==Open source==
49

edits

Navigation menu