2018-03-04 23:53:55 +08:00
|
|
|
|
using CustomNPCFramework.Framework.Enums;
|
|
|
|
|
using CustomNPCFramework.Framework.Graphics;
|
2018-02-24 17:36:41 +08:00
|
|
|
|
using CustomNPCFramework.Framework.ModularNPCS;
|
|
|
|
|
using CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
using CustomNPCFramework.Framework.NPCS;
|
2018-03-04 19:36:19 +08:00
|
|
|
|
using CustomNPCFramework.Framework.Utilities;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using StardewModdingAPI;
|
|
|
|
|
using StardewValley;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CustomNPCFramework
|
|
|
|
|
{
|
2018-03-04 20:36:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// TODO:
|
|
|
|
|
/// List all asset managers in use.
|
|
|
|
|
/// Have all asset managers list what assets they are using.
|
2018-03-05 05:23:40 +08:00
|
|
|
|
///
|
2018-03-05 07:21:39 +08:00
|
|
|
|
/// Have asset info have a var called age.
|
|
|
|
|
/// ...where
|
|
|
|
|
/// 0=adult
|
|
|
|
|
/// 1=child
|
|
|
|
|
///
|
|
|
|
|
/// /// Have asset info have a var called bodyType.
|
|
|
|
|
/// ...where
|
|
|
|
|
/// 0=thin
|
|
|
|
|
/// 1=normal
|
|
|
|
|
/// 2=muscular
|
|
|
|
|
/// 3=big
|
|
|
|
|
///
|
2018-03-05 05:23:40 +08:00
|
|
|
|
/// Load in the assets and go go go.
|
2018-03-05 06:44:52 +08:00
|
|
|
|
/// -Collect a bunch of assets together to test this thing.
|
2018-03-04 20:36:46 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
|
2018-02-24 11:10:56 +08:00
|
|
|
|
public class Class1 : Mod
|
|
|
|
|
{
|
|
|
|
|
public static IModHelper ModHelper;
|
|
|
|
|
public static IMonitor ModMonitor;
|
2018-03-04 20:36:46 +08:00
|
|
|
|
|
2018-03-04 19:36:19 +08:00
|
|
|
|
public static NPCTracker npcTracker;
|
2018-03-04 20:36:46 +08:00
|
|
|
|
public static AssetPool assetPool;
|
2018-02-24 11:10:56 +08:00
|
|
|
|
public override void Entry(IModHelper helper)
|
|
|
|
|
{
|
|
|
|
|
ModHelper = this.Helper;
|
|
|
|
|
ModMonitor = this.Monitor;
|
2018-03-04 20:36:46 +08:00
|
|
|
|
|
2018-02-24 11:10:56 +08:00
|
|
|
|
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_LoadChar;
|
2018-03-04 19:36:19 +08:00
|
|
|
|
|
|
|
|
|
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
|
|
|
|
|
StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
|
|
|
|
|
|
2018-02-24 11:10:56 +08:00
|
|
|
|
StardewModdingAPI.Events.LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged;
|
|
|
|
|
StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
|
2018-03-04 19:36:19 +08:00
|
|
|
|
npcTracker = new NPCTracker();
|
2018-03-04 20:36:46 +08:00
|
|
|
|
assetPool = new AssetPool();
|
|
|
|
|
var assetManager = new AssetManager();
|
|
|
|
|
assetPool.addAssetManager(new KeyValuePair<string, AssetManager>("testNPC", assetManager));
|
|
|
|
|
initializeExamples();
|
|
|
|
|
initializeAssetPool();
|
|
|
|
|
assetPool.loadAllAssets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initializeAssetPool()
|
|
|
|
|
{
|
|
|
|
|
string path = Path.Combine(ModHelper.DirectoryPath, "Content", "Graphics", "NPCS", "Characters", "RainMan");
|
|
|
|
|
assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair<string, string>("characters", path));
|
2018-03-04 19:36:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveEvents_AfterSave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
npcTracker.afterSave();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveEvents_BeforeSave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
npcTracker.cleanUpBeforeSave();
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GameEvents_UpdateTick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Game1.player.currentLocation == null) return;
|
|
|
|
|
foreach (var v in Game1.player.currentLocation.characters)
|
|
|
|
|
{
|
|
|
|
|
v.speed = 5;
|
2018-02-24 17:36:41 +08:00
|
|
|
|
//v.MovePosition(Game1.currentGameTime, Game1.viewport, Game1.player.currentLocation);
|
2018-03-04 20:36:46 +08:00
|
|
|
|
//ModMonitor.Log(v.sprite.spriteHeight.ToString());
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsCurrentLocationChanged e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-04 19:36:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to spawn a custom npc just as an example. Don't keep this code.
|
2018-03-17 19:04:04 +08:00
|
|
|
|
/// GENERATE NPC AND CALL THE CODE
|
2018-03-04 19:36:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2018-02-24 11:10:56 +08:00
|
|
|
|
private void SaveEvents_LoadChar(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-03-17 19:04:04 +08:00
|
|
|
|
ExtendedNPC myNpc3 = assetPool.generateNPC(Genders.female, 0, 1);
|
2018-03-17 19:39:46 +08:00
|
|
|
|
MerchantNPC merch = new MerchantNPC(new List<Item>()
|
|
|
|
|
{
|
|
|
|
|
new StardewValley.Object(475,999)
|
|
|
|
|
}, myNpc3);
|
|
|
|
|
npcTracker.addNewNPCToLocation(Game1.getLocationFromName("BusStop", false), merch);
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initializeExamples()
|
|
|
|
|
{
|
2018-03-04 23:53:55 +08:00
|
|
|
|
|
2018-02-24 11:10:56 +08:00
|
|
|
|
string dirPath = Path.Combine(ModHelper.DirectoryPath, "Content", "Templates");
|
2018-03-04 20:36:46 +08:00
|
|
|
|
var aManager=assetPool.getAssetManager("testNPC");
|
|
|
|
|
aManager.addPathCreateDirectory(new KeyValuePair<string, string>("templates", dirPath));
|
2018-02-24 11:10:56 +08:00
|
|
|
|
string filePath =Path.Combine(dirPath, "Example.json");
|
2018-03-04 23:53:55 +08:00
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
string getRelativePath = getShortenedDirectory(filePath);
|
|
|
|
|
ModMonitor.Log("THIS IS THE PATH::: " + getRelativePath);
|
2018-03-05 05:23:40 +08:00
|
|
|
|
AssetInfo info = new AssetInfo("MyExample",new NamePairings("StandingExampleL", "StandingExampleR", "StandingExampleU", "StandingExampleD"), new NamePairings("MovingExampleL", "MovingExampleR", "MovingExampleU", "MovingExampleD"), new NamePairings("SwimmingExampleL", "SwimmingExampleR", "SwimmingExampleU", "SwimmingExampleD"), new NamePairings("SittingExampleL", "SittingExampleR", "SittingExampleU", "SittingExampleD"), new Vector2(16, 16), false);
|
2018-03-04 23:53:55 +08:00
|
|
|
|
info.writeToJson(filePath);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
string filePath2 = Path.Combine(dirPath, "AdvancedExample.json");
|
|
|
|
|
if (!File.Exists(filePath2))
|
|
|
|
|
{
|
|
|
|
|
|
2018-03-05 06:32:59 +08:00
|
|
|
|
ExtendedAssetInfo info2 = new ExtendedAssetInfo("AdvancedExample", new NamePairings("AdvancedStandingExampleL", "AdvancedStandingExampleR", "AdvancedStandingExampleU", "AdvancedStandingExampleD"), new NamePairings("AdvancedMovingExampleL", "AdvancedMovingExampleR", "AdvancedMovingExampleU", "AdvancedMovingExampleD"), new NamePairings("AdvancedSwimmingExampleL", "AdvancedSwimmingExampleR", "AdvancedSwimmingExampleU", "AdvancedSwimmingExampleD"), new NamePairings("AdvancedSittingExampleL", "AdvancedSittingExampleR", "AdvancedSittingExampleU", "AdvancedSittingExampleD"), new Vector2(16, 16), false, Genders.female, new List<Seasons>()
|
2018-03-04 23:53:55 +08:00
|
|
|
|
{
|
|
|
|
|
Seasons.spring,
|
|
|
|
|
Seasons.summer
|
|
|
|
|
}, PartType.hair
|
|
|
|
|
);
|
|
|
|
|
info2.writeToJson(filePath2);
|
|
|
|
|
}
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string getShortenedDirectory(string path)
|
|
|
|
|
{
|
2018-02-24 17:36:41 +08:00
|
|
|
|
string lol = (string)path.Clone();
|
|
|
|
|
string[] spliter = lol.Split(new string[] { ModHelper.DirectoryPath },StringSplitOptions.None);
|
2018-03-17 19:04:04 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return spliter[1];
|
|
|
|
|
}
|
|
|
|
|
catch(Exception err)
|
|
|
|
|
{
|
|
|
|
|
return spliter[0];
|
|
|
|
|
}
|
2018-02-24 11:10:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string getRelativeDirectory(string path)
|
|
|
|
|
{
|
|
|
|
|
string s = getShortenedDirectory(path);
|
|
|
|
|
return s.Remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|