Skip to content

Commit

Permalink
Merge pull request #12 from Sirspam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Sirspam authored Dec 29, 2022
2 parents 4b16192 + 0e2a746 commit 8b8c38f
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 71 deletions.
Binary file added LocalFilesExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 18 additions & 18 deletions Nya/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class PluginConfig
public virtual Color BackgroundColor { get; set; } = new Color(0.745f, 0.745f, 0.745f);
public virtual bool RainbowBackgroundColor { get; set; } = false;
public virtual bool PersistantAutoNya { get; set; } = false;
public virtual int AutoNyaWait { get; set; } = 4;
public virtual int AutoNyaWait { get; set; } = 5;
public virtual int ImageScaleValue { get; set; } = 512; // 0 means scaling disabled
public virtual bool EasterEggs { get; set; } = true;
public virtual string SelectedAPI { get; set; } = ImageSources.Sources.Keys.First();
Expand Down Expand Up @@ -68,30 +68,30 @@ public virtual void Changed()
/// </remark>
private void FixConfigIssues()
{
if (AutoNyaWait < 4)
using var _ = ChangeTransaction;

if (AutoNyaWait < 3)
{
AutoNyaWait = 4;
AutoNyaWait = 3;
}

if (SelectedEndpoints.Count != ImageSources.Sources.Count)
{
using var _ = ChangeTransaction;
SelectedEndpoints.Clear();
foreach (var key in ImageSources.Sources.Keys)
{
SelectedEndpoints.Add(key, new EndpointData
{
SelectedSfwEndpoint = ImageSources.Sources[key].SfwEndpoints.FirstOrDefault() ?? "Empty",
SelectedNsfwEndpoint = ImageSources.Sources[key].NsfwEndpoints.FirstOrDefault() ?? "Empty"
});
}
}


if (!ImageSources.Sources.ContainsKey(SelectedAPI))
{
SelectedEndpoints.Remove(SelectedAPI);
SelectedAPI = ImageSources.Sources.First().Key;
}

var selectedSfwEndpoint = SelectedEndpoints[SelectedAPI].SelectedSfwEndpoint;
if (!ImageSources.GlobalEndpoints.Contains(selectedSfwEndpoint) && !ImageSources.Sources[SelectedAPI].SfwEndpoints.Contains(selectedSfwEndpoint))
{
SelectedEndpoints[SelectedAPI].SelectedSfwEndpoint = ImageSources.Sources[SelectedAPI].SfwEndpoints.FirstOrDefault() ?? "Empty";
}

var selectedNsfwEndpoint = SelectedEndpoints[SelectedAPI].SelectedNsfwEndpoint;
if (!ImageSources.GlobalEndpoints.Contains(selectedNsfwEndpoint) && !ImageSources.Sources[SelectedAPI].SfwEndpoints.Contains(selectedSfwEndpoint))
{
SelectedEndpoints[SelectedAPI].SelectedNsfwEndpoint = ImageSources.Sources[SelectedAPI].NsfwEndpoints.FirstOrDefault() ?? "Empty";
}
}
}
}
10 changes: 5 additions & 5 deletions Nya/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class Plugin
[Init]
public Plugin(Config config, Logger logger, Zenjector zenjector)
{
var folderPath = Path.Combine(UnityGame.UserDataPath, "Nya");
Directory.CreateDirectory(Path.Combine(folderPath, "sfw"));
Directory.CreateDirectory(Path.Combine(folderPath, "nsfw"));

zenjector.UseLogger(logger);
zenjector.UseHttpService();
zenjector.UseMetadataBinder<Plugin>();
Expand All @@ -27,14 +31,10 @@ public Plugin(Config config, Logger logger, Zenjector zenjector)
{
pluginConfig.NsfwImages = false;
}

zenjector.Install<NyaAppInstaller>(Location.App, pluginConfig);
zenjector.Install<NyaMenuInstaller>(Location.Menu);
zenjector.Install<NyaGameInstaller>(Location.Singleplayer);

var folderPath = Path.Combine(UnityGame.UserDataPath, "Nya");
Directory.CreateDirectory(Path.Combine(folderPath, "sfw"));
Directory.CreateDirectory(Path.Combine(folderPath, "nsfw"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public ModalContent(string topText, string midText, string midImagePath, string
private readonly ModalContent[] _modalContents =
{
new ModalContent("Woah There!", "Are you sure you want to enable NSFW features? You have to be 18+ to do this!", "Nya.Resources.Chocola_Surprised.png", "No", "Yes, I'm 18+", true, false),
new ModalContent("Are you sure?", "Are you reallllyyyy certain that your age is 18 or above?", "Nya.Resources.Chocola_Question_Mark.png", "No, I'm not", "Yes, I'm certain", true, true),
new ModalContent("Are you very very sure?", "If you're lying I will find out and tell your parents. \r\n(They will be very disappointed with you)", "Nya.Resources.Chocola_Angry.png", "Sorry, I lied", "Yes, I'm not lying", true, true),
new ModalContent("Are you sure?", "Mhm... you super sure you're 18 or older??", "Nya.Resources.Chocola_Question_Mark.png", "No, I'm not", "Yes, I'm certain", true, true),
new ModalContent("Are you very sure?", "If you're lying I will find out and tell your parents. \r\n(They will be very disappointed in you)", "Nya.Resources.Chocola_Angry.png", "Sorry, I lied", "Yes, I'm not lying", true, true),
new ModalContent("Just double checking", "Okay so you're absolutely positive that you're 18+ and want to enable NSFW features?", "Nya.Resources.Chocola_Howdidyoudothat.png", "No", "Yes", true, true),
new ModalContent("Surprise math question!", "To confirm that you're really 18, let's do a maths question! \r\nWhat is 6 + 9 * (4 - 2) + 0?", "Nya.Resources.Chocola_Laugh.png", "No", "Yes", true, true, true, true),
new ModalContent("Correct!", "If you got that right then you must be a smart and sensible adult!", "Nya.Resources.Chocola_Happy.png", "but I'm not...", "I am! 😃", true, true),
new ModalContent("Wait!", "The NSFW features could be dangerous! \r\nWhy else would they be called Not Safe For Work??", "Nya.Resources.Chocola_Spooked.png", "That sounds risky!", "I am prepared", true, true),
new ModalContent("Last time I'll ask", "So you definitely want to enable NSFW and suffer the consequences which may entail from it?", "Nya.Resources.Chocola_Bashful.png", "No", "Yes", true, true)
new ModalContent("Wait!", "The NSFW features could be dangerous! \r\nWhy else would they be called \"Not Safe For Work??\"", "Nya.Resources.Chocola_Spooked.png", "That sounds risky!", "I am prepared", true, true),
new ModalContent("Last time I'll ask", "So you definitely want to enable the NSFW features and suffer the consequences which may entail from it?", "Nya.Resources.Chocola_Bashful.png", "No", "Yes", true, true)
};

private bool _parsed;
Expand Down Expand Up @@ -264,8 +264,8 @@ async void FinishedCallback()
if (modalContent.ButtonIntractabilityCooldown)
{
#if !DEBUG
IntractabilityCooldown(_mathSlider);
IntractabilityCooldown(_submitButton);
IntractabilityCooldown(_mathSlider);
IntractabilityCooldown(_submitButton);
#endif
}
}
Expand All @@ -280,8 +280,8 @@ async void FinishedCallback()
if (modalContent.ButtonIntractabilityCooldown)
{
#if !DEBUG
IntractabilityCooldown(_noButton);
IntractabilityCooldown(_yesButton);
IntractabilityCooldown(_noButton);
IntractabilityCooldown(_yesButton);
#endif
}
}
Expand All @@ -291,14 +291,14 @@ async void FinishedCallback()
private static async void IntractabilityCooldown(SliderSetting gameObject)
{
gameObject.interactable = false;
await AwaitSleep(2500);
await AwaitSleep(2000);
gameObject.interactable = true;
}

private static async void IntractabilityCooldown(Selectable gameObject)
{
gameObject.interactable = false;
await AwaitSleep(2500);
await AwaitSleep(2000);
gameObject.interactable = true;
}

Expand Down
54 changes: 42 additions & 12 deletions Nya/UI/ViewControllers/ModalControllers/SettingsModalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ protected SettingsModalController(UIUtils uiUtils, ImageUtils imageUtils, MainCa
[UIComponent("modal")]
public readonly ModalView ModalView = null!;

[UIComponent("modal")]
protected readonly RectTransform ModalTransform = null!;

[UIComponent("settings-modal-tab-selector")]
protected readonly TabSelector TabSelector = null!;

Expand Down Expand Up @@ -94,7 +91,7 @@ protected SettingsModalController(UIUtils uiUtils, ImageUtils imageUtils, MainCa

[UIComponent("api-dropdown")]
protected readonly Transform ApiDropDownTransform = null!;

[UIComponent("sfw-dropdown")]
protected readonly Transform SfwDropDownTransform = null!;

Expand Down Expand Up @@ -138,15 +135,29 @@ private void BaseParse(Component parentTransform, object host)
{
BSMLParser.instance.Parse(Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "Nya.UI.Views.SettingsModalView.bsml"), parentTransform.gameObject, host);
ModalView.name = "NyaSettingsModal";
ModalView.SetField("_animateParentCanvas", true);
ApiDropDownTransform.Find("DropdownTableView").GetComponent<ModalView>().SetField("_animateParentCanvas", false);
SfwDropDownTransform.Find("DropdownTableView").GetComponent<ModalView>().SetField("_animateParentCanvas", false);
NsfwDropDownTransform.Find("DropdownTableView").GetComponent<ModalView>().SetField("_animateParentCanvas", false);
ModalView.gameObject.AddComponent<CanvasGroup>();
Button[] buttons = { ApiDropDownTransform.Find("DropDownButton").GetComponent<Button>(), SfwDropDownTransform.Find("DropDownButton").GetComponent<Button>(), NsfwDropDownTransform.Find("DropDownButton").GetComponent<Button>() };
foreach (var button in buttons)
{
button.onClick.RemoveAllListeners();
button.onClick.AddListener(() => DropDownButtonClicked(button.transform.parent.Find("DropdownTableView").GetComponent<ModalView>(), button));
}

_parsed = true;
}
}

private void DropDownButtonClicked(ModalView modalView, Button button)
{
modalView.SetupView(RootTransform);
modalView.SetField("_parentCanvasGroup", ModalView.gameObject.GetComponent<CanvasGroup>());
modalView.Show(true);

button.onClick.RemoveAllListeners();
button.onClick.AddListener(() => modalView.Show(true));
button.GetComponent<SignalOnUIButtonClick>().Start();
}

protected void ShowModal(Transform parentTransform, object host)
{
BaseParse(parentTransform, host);
Expand Down Expand Up @@ -284,7 +295,10 @@ protected void NsfwChange(string value)
[UIAction("format-source")]
protected string FormatSource(string value)
{
return value.Split('/').Last().Replace("_", " ");
value = value.Split('/').Last().Replace("_", " ");
var charArray = value.ToCharArray();
charArray[0] = char.ToUpper(charArray[0]);
return new string(charArray);
}

#endregion
Expand Down Expand Up @@ -393,9 +407,13 @@ private void UpdateLists()
{
SfwDropDownListSetting.values.Clear();
SfwDropDownListSetting.values = ImageSources.Sources[APIValue].SfwEndpoints.Cast<object>().ToList();
SfwDropDownListSetting.UpdateChoices();
if (SfwDropDownListSetting.values.Count > 1)
{
SfwDropDownListSetting.values.Add("Random");
}
SfwDropDownListSetting.Value = SfwValue;

SfwDropDownListSetting.UpdateChoices();

if (CheckNsfwListHasEndpoints())
{
if (NsfwDropDownListSetting.interactable == false)
Expand All @@ -406,6 +424,10 @@ private void UpdateLists()

NsfwDropDownListSetting.values.Clear();
NsfwDropDownListSetting.values = ImageSources.Sources[APIValue].NsfwEndpoints.Cast<object>().ToList();
if (NsfwDropDownListSetting.values.Count > 1)
{
NsfwDropDownListSetting.values.Add("Random");
}
NsfwDropDownListSetting.Value = NsfwValue;
NsfwDropDownListSetting.UpdateChoices();
}
Expand All @@ -415,7 +437,15 @@ public void Initialize()
{
APIList = ImageSources.Sources.Keys.Cast<object>().ToList();
SfwList = ImageSources.Sources[APIValue].SfwEndpoints.Cast<object>().ToList();
NsfwList = NsfwList = ImageSources.Sources[APIValue].NsfwEndpoints.Cast<object>().ToList();
if (SfwList.Count > 1)
{
SfwList.Add("Random");
}
NsfwList = ImageSources.Sources[APIValue].NsfwEndpoints.Cast<object>().ToList();
if (NsfwList.Count > 1)
{
NsfwList.Add("Random");
}
}
}
}
2 changes: 1 addition & 1 deletion Nya/UI/Views/NyaSettingsMainView.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<tab tab-name="Behaviour" tags="settings-tab" horizontal-fit="PreferredSize" vertical-fit="PreferredSize">
<vertical child-expand-width="true" horizontal-fit="PreferredSize" vertical-fit="PreferredSize" anchor-pos-y="10">
<slider-setting id="auto-wait-slider" text="Auto Nya wait time" hover-hint="How many seconds Auto Nya will wait for before getting a new image" increment="1" min="4" max="30" integer-only="true" value="auto-wait-value" bind-value="true" apply-on-change="true"/>
<slider-setting id="auto-wait-slider" text="Auto Nya wait time" hover-hint="How many seconds Auto Nya will wait for before getting a new image" increment="1" min="3" max="30" integer-only="true" value="auto-wait-value" bind-value="true" apply-on-change="true"/>
<checkbox-setting text="Persistant Auto Nya" hover-hint="Auto Nya will re-enable whenever Nya is active" value="persistant-auto-nya" bind-value="true" apply-on-change="true"/>
<dropdown-list-setting id="scale-dropdown" text="Downscale images" hover-hint="Image downscaling helps reduce the stutter whenever loading a new image. It's recommended to keep this enabled" value="scaling-value" choices="scaling-choices" bind-value="true" apply-on-change="true"/>
<checkbox-setting id="easter-eggs-checkbox" text="Easter Eggs" hover-hint="They're funny please I swear" value="easter-eggs" bind-value="true" apply-on-change="true"/>
Expand Down
2 changes: 1 addition & 1 deletion Nya/UI/Views/SettingsModalView.bsml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<bg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="root" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd">
<bg id="root" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd">
<modal id="modal" show-event="open-modal" hide-event="close-modal" clickerino-offerino-closerino="true" size-delta-x="71" size-delta-y="50" move-to-center="true">
<vertical anchor-pos-y="10.3">

Expand Down
40 changes: 29 additions & 11 deletions Nya/Utils/ImageSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Nya.Utils
{
public class ImageSources
internal sealed class ImageSources
{
internal static Dictionary<string, SourceData> Sources { get; } = new Dictionary<string, SourceData>
{
Expand All @@ -13,13 +13,14 @@ public class ImageSources
{
BaseEndpoint = "https://api.waifu.pics/",
Mode = DataMode.Json,
// Removed 'kill' endpoint because it makes me sad :(
SfwEndpoints = new List<string>
{
"sfw/neko", "sfw/waifu", "sfw/awoo", "sfw/shinobu", "sfw/megumin", "sfw/cuddle", "sfw/cry",
"sfw/hug", "sfw/kiss", "sfw/lick", "sfw/pat", "sfw/smug", "sfw/bonk", "sfw/yeet", "sfw/blush",
"sfw/smile", "sfw/wave", "sfw/highfive", "sfw/nom", "sfw/bite", "sfw/glomp", "sfw/slap",
"sfw/kick", "sfw/happy", "sfw/wink", "sfw/poke", "sfw/dance"
}, // No 'kill' endpoint because it makes me sad :(
},
NsfwEndpoints = new List<string> { "nsfw/neko", "nsfw/waifu", "nsfw/trap", "nsfw/blowjob" }
}
},
Expand All @@ -41,7 +42,8 @@ public class ImageSources
{
BaseEndpoint = "https://anime-api.hisoka17.repl.co/img/",
Mode = DataMode.Json,
SfwEndpoints = new List<string> { "hug", "kiss", "slap", "wink", "pat", "kill", "cuddle", "punch", "waifu" },
// Removed 'kill' endpoint because, once again, it makes me a bit sad :(
SfwEndpoints = new List<string> { "hug", "kiss", "slap", "wink", "pat", "cuddle", "punch", "waifu" },
NsfwEndpoints = new List<string> { "nsfw/hentai", "nsfw/boobs", "nsfw/lesbian" }
}
},
Expand All @@ -62,25 +64,41 @@ public class ImageSources
{
BaseEndpoint = Path.Combine(UnityGame.UserDataPath, "Nya"),
Mode = DataMode.Local,
SfwEndpoints = new List<string> { "/sfw" },
NsfwEndpoints = new List<string> { "/nsfw" }
SfwEndpoints = PopulateLocalEndpoints(false),
NsfwEndpoints = PopulateLocalEndpoints(true)
}
}
};

private static List<string> PopulateLocalEndpoints(bool nsfw)
{
var baseFolder = nsfw ? "nsfw" : "sfw";
var endpoints = new List<string> {baseFolder};

foreach (var folder in Directory.GetDirectories(Path.Combine(UnityGame.UserDataPath, "Nya", baseFolder)))
{
endpoints.Add(Path.GetFileName(folder));
}

return endpoints;
}

internal struct SourceData
{
internal string BaseEndpoint;
internal DataMode Mode;
internal List<string> SfwEndpoints;
internal List<string> NsfwEndpoints;
}
}

internal enum DataMode
{
Unsupported,
Json,
Local
// Empty shouldn't really be here but that's an issue I'll fix later :clueless:
internal static readonly string[] GlobalEndpoints = {"Empty", "Random"};

internal enum DataMode
{
Unsupported,
Json,
Local
}
}
}
Loading

0 comments on commit 8b8c38f

Please sign in to comment.