Skip to content

Commit

Permalink
Use Item Example
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Aug 15, 2024
1 parent 333896a commit f5be382
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"itemNameKey": "exampleitems.milk.name",
"itemDescriptionKey": "exampleitems.milk.desc",
"sprite": "exampleitems.milk",
"itemColor": {
"r": 58,
"g": 40,
"b": 32,
"a": 255
},
"value": 50,
"dimensions": [
"X"
],
"damageMode": "DESTROY",
"sellOverrideValue": 10,
"hasSpecialDiscardAction": true,
"discardPromptOverride": "prompt.use"
}

2 changes: 2 additions & 0 deletions Winch.Examples/ExampleItems/Assets/Localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"exampleitems.durable.desc": "???",
"exampleitems.ice.name": "Ice Block",
"exampleitems.ice.desc": "A block of ice.",
"exampleitems.milk.name": "Milk Bucket",
"exampleitems.milk.desc": "An iron bucket full of milk.",
"exampleitems.nonspatial.name": "Non Spatial",
"exampleitems.nonspatial.desc": "???",
"exampleitems.message.name": "Message Name",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion Winch.Examples/ExampleItems/Loader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Winch.Core;
Expand All @@ -7,10 +8,19 @@

namespace ExampleItems
{
public class Loader
public static class Loader
{
public static ItemData MilkBucket => ItemUtil.GetModdedItemData("exampleitems.milk");
public static VibrationData MilkBucketVibrationData;

public static void Initialize()
{
MilkBucketVibrationData = ScriptableObject.CreateInstance<VibrationData>().DontDestroyOnLoad().Rename("MilkBucket");
MilkBucketVibrationData.vibrationParamsList = new List<VibrationParams>
{
new VibrationParams(0.03f,0,0.1f,0.3f,0.75f)
};

#region Dialogue
try
{
Expand Down Expand Up @@ -57,6 +67,7 @@ public static void Initialize()
#endregion

GameManager.Instance.OnGameStarted += OnGameStarted;
GameManager.Instance.OnGameEnded += OnGameEnded;
}

private static GameObject CreateCube()
Expand All @@ -72,6 +83,8 @@ private static GameObject CreateCube()

private static void OnGameStarted()
{
GameEvents.Instance.OnSpecialItemHandlerRequested += OnSpecialItemHandlerRequested;

try
{
var cubeLand = CreateCube();
Expand All @@ -93,5 +106,24 @@ private static void OnGameStarted()
WinchCore.Log.Error(e);
}
}

private static void OnGameEnded()
{
GameEvents.Instance.OnSpecialItemHandlerRequested -= OnSpecialItemHandlerRequested;
}

private static void OnSpecialItemHandlerRequested(SpatialItemData itemData)
{
if (itemData.id == MilkBucket.id)
{
GameManager.Instance.ItemManager.UseRepairKit();
GameManager.Instance.ItemManager.RepairAllItemDurability();
GameManager.Instance.UI.OccasionalGridPanel.TryRepairCurrentCrabPot();
GameManager.Instance.UI.ShowNotification(NotificationType.ANY_REPAIR_KIT_USED, "notification.durability-repaired");
GameManager.Instance.Player.Sanity.ChangeSanity(1f);
GameManager.Instance.UI.ShowNotification(NotificationType.ANY_REPAIR_KIT_USED, "notification.panic-repaired");
GameManager.Instance.VibrationManager.Vibrate(MilkBucketVibrationData, VibrationRegion.WholeBody, overrideExistingVibrations: true);
}
}
}
}

0 comments on commit f5be382

Please sign in to comment.