WIP DailyRandom - Generates random value every day [DISCONTINUED]

Discussion in 'Modding Tools' started by pepoluan, Jul 4, 2019.

  1. pepoluan

    pepoluan Star Wrangler

    ATTENTION: This mod has been discontinued; use CP's {{Random}} token instead! Post is kept only for posterity reasons.

    Currently, ContentPatcher does not have a feature to generate random value, meaning that if (for example) you have several variants of Emily Portrait/Character with different summer clothing, she will be wearing the same clothing everyday.

    (ContentPatcher does have a {{season}} token, though, that is why I emphasized "summer" above. Come the 28th, when the calendar rolls over to next season, ContentPatcher will update the {{season}} token and hence pick up a new asset.)

    So, I whup up a mod that provides just that: A way to generate a random number that changes only when the day changes (you don't want Emily to flicker around between her summer variants every tick...)

    Attached is a very early version of this mod, that is why this is a WIP not a Release.

    How To Use:

    [1] Create a CP ContentPack as usual, with the asset variants labeled accordingly.

    For example:
    • Characters/Emily_summer_a.png
    • Characters/Emily_summer_b.png
    • Characters/Emily_summer_c.png
    • Characters/Haley_summer_00.png
    • Characters/Haley_summer_01.png
    • Portraits/Emily_summer_a.png
    • Portraits/Emily_summer_b.png
    • Portraits/Emily_summer_c.png
    • Portraits/Haley_summer_00.png
    • Portraits/Haley_summer_01.png
    [2] In your mod's manifest.json, add a Dependency to this mod, for example:

    "Dependencies": [
    {
    "UniqueID": "pepoluan.DailyRandom",
    "IsRequired": true
    }
    ]

    [3] Create a "dailyrandom.yaml" file in the same directory as manifest.json, for example:
    Code:
    vars:
    - name: em
      mustchange: true  # true means the mod will reroll until the next day's choice is different
      choices:
      - a
      - b
      - c
    - name: hal
      mustchange: false
      choices:
      - "00"  # You'll need to quote numbers
      - "01"
    
    [4] Modify the "FromFile" of your content.json like so:

    Code:
    "FromFile": "assets/Characters/Emily_{{season}}_{{pepoluan.DailyRandom/###:em}}.png"
    ...
    "FromFile": "assets/Characters/Haley_{{season}}_{{pepoluan.DailyRandom/###:hal}}.png"
    ...
    "FromFile": "assets/Portraits/Emily_{{season}}_{{pepoluan.DailyRandom/###:em}}.png"
    ...
    "FromFile": "assets/Portraits/Haley_{{season}}_{{pepoluan.DailyRandom/###:hal}}.png"
    
    Change the "###" to the last part of your mod's UniqueID (e.g., if your mod's UniqueID is "greatModder.EmilyRemake", the "###" should be replaced with "EmilyRemake")

    Notice also the variable names "em" and "hal", they must match exactly the variables declared in the file "dailyrandom.yaml".

    Source code available here: https://bitbucket.org/pepoluan/sdvmod-daily-random/src/default/
     

      Attached Files:

      Last edited: Dec 10, 2019
    • pepoluan

      pepoluan Star Wrangler

      Okay, a clearer guide:

      Step 1: Prepare your assets

      Assume this folder structure (NO config.json or manifest.json at first):

      Code:
      [CP] ModName
      + assets
        + Characters
        | + Emily_spring_01.png
        | + Emily_spring_02.png
        | + Emily_spring_03.png
        | + Emily_summer_11.png
        | + Emily_fall_21.png
        | + Emily_fall_22.png
        | + Emily_winter_31.png
        | + Haley_spring_a.png
        | + Haley_spring_b.png
        | + Haley_summer_a.png
        | + Haley_summer_b.png
        | + Haley_fall_a.png
        | + Haley_fall_b.png
        | + Haley_winter_a.png
        | + Haley_winter_b.png
        + Portraits
          + Emily_spring_01.png
          + Emily_spring_02.png
          + Emily_spring_03.png
          + Emily_summer_11.png
          + Emily_fall_21.png
          + Emily_fall_22.png
          + Emily_winter_31.png
          + Haley_spring_a.png
          + Haley_spring_b.png
          + Haley_summer_a.png
          + Haley_summer_b.png
          + Haley_fall_a.png
          + Haley_fall_b.png
          + Haley_winter_a.png
          + Haley_winter_b.png
      Just make sure that the per-season variant tag/label/selector is the same between Characters & Portraits.

      Step 2: Create manifest.json

      Create it like below, adjusting the fields as necessary:
      Code:
      {
          "Name": "Your Project Name",
          "Author": "your name",
          "Version": "1.0.0",
          "Description": "One or two sentences about the mod.",
          "UniqueID": "YourName.YourProjectName",
          "MinimumApiVersion": "2.11.0",
          "UpdateKeys": [],
          "ContentPackFor": {
              "UniqueID": "Pathoschild.ContentPatcher",
              "MinimumVersion": "1.9.0"
          },
          "Dependencies": [
              {
                  "UniqueID": "pepoluan.DailyRandom",
                  "IsRequired": true
              }
          ]
      }
      Some requirements:
      • You MUST specify "MinimumVersion": "1.9.0" for ContentPatcher
      • You MUST list "pepoluan.DailyRandom" as a required dependency ("IsRequired" MUST be set true)
      • You MUST ensure that the "YourProjectName" part of "UniqueID" does not collide/clash with other mods

      Step 3: Create content.json

      Although you can use the {{pepoluan.DailyRandom/...}} token directly in "FromFile", I suggest using a DynamicToken instead, like so:

      Code:
      {
        "Format": "1.9",
        "DynamicTokens": [
          {
            "Name": "emily_variant",
            "Value": "{{pepoluan.DailyRandom/YourProjectName:em{{season}}}}"
          },
          {
            "Name": "haley_variant",
            "Value": "{{pepoluan.DailyRandom/YourProjectName:haley}}"
          }
        ],
        "Changes": [
          {
            "Action": "EditImage",
            "Target": "Characters/Emily",
            "FromFile": "assets/Characters/Emily_{{season}}_{{emily_variant}}.png"
          },
          {
            "Action": "EditImage",
            "Target": "Portraits/Emily",
            "FromFile": "assets/Portraits/Emily_{{season}}_{{emily_variant}}.png"
          },
          {
            "Action": "EditImage",
            "Target": "Characters/Haley",
            "FromFile": "assets/Characters/Haley_{{season}}_{{haley_variant}}.png"
          },
          {
            "Action": "EditImage",
            "Target": "Portraits/Haley",
            "FromFile": "assets/Portraits/Haley_{{season}}_{{haley_variant}}.png"
          }
        ]
      }
      Don't forget to replace YourProjectName with the actual last part of YOUR mod's UniqueID, as defined in manifest.json !!


      Step 4: Create dailyrandom.yaml

      Now let's define the DailyRandom variables, like so:

      Code:
      vars:
      - name: emspring
        mustchange: true
        choices: ["01", "02", "03"]
      - name: emsummer
        choices: ["11"]  # Example of list containing just one item
      - name: emfall
        mustchange: true
        choices:
        - "21"
        - "22"
      - name: emwinter
        mustchange: false
        choices:
        - "31"
      - name: haley
        mustchange: false
        choices:
        - a  # No need to quote if choice starts with a letter
        - b
      Explanation:
      • This is a YAML Format with some additional restrictions imposed by this mod
      • Tab characters are forbidden
      • First letter of the parameters "name", "mustchange", and "choices" MUST be justified
      • For the purposes of this mod, numbers should be quoted
      • You can specify the choices in one line (using the brackets notation) or as a dashed vertical list
        • Even if you have only 1 choice (at the moment; probably you're planning additional assets), you MUST make the choice a list
      Field definitions:
      name : (REQUIRED) Name of the daily random variable; this is what content.json will refer to after the colon
      mustchange : (Optional) whether the new day's value must be different from yesterday's; defaults to "false". If "choices" (see next) contains only 1 item, it will be forced to "false"
      choices : (REQUIRED) One or more values the mod will choose from at the start of day​


      Step 5: Done!

      You don't have to configure the DailyRandom mod itself! DailyRandom will find your mod and inject the needed "advanced custom tokens".

      Just pay attention to the SMAPI Console for errors from ContentPatcher (NOT from DailyRandom).
       
        Last edited: Jul 5, 2019
      • Wolffang719

        Wolffang719 Void-Bound Voyager

        I like the idea but I have no idea how to properly fill out most of the fields, this is more an issue with myself less so your explanation.
         
        • pepoluan

          pepoluan Star Wrangler

          The development of this mod has been discontinued, since Pathoschild had coded the {{Random}} token.
           

          Share This Page