simplify with newer pattern features
This commit is contained in:
parent
b6c8cfc28b
commit
0539bb8f37
|
@ -64,7 +64,7 @@ namespace StardewModdingAPI.ModBuildConfig.Analyzer
|
||||||
}
|
}
|
||||||
|
|
||||||
// conditional access
|
// conditional access
|
||||||
if (node is ConditionalAccessExpressionSyntax conditionalAccess && conditionalAccess.WhenNotNull is MemberBindingExpressionSyntax conditionalBinding)
|
if (node is ConditionalAccessExpressionSyntax { WhenNotNull: MemberBindingExpressionSyntax conditionalBinding } conditionalAccess)
|
||||||
{
|
{
|
||||||
declaringType = semanticModel.GetTypeInfo(conditionalAccess.Expression).Type;
|
declaringType = semanticModel.GetTypeInfo(conditionalAccess.Expression).Type;
|
||||||
memberType = semanticModel.GetTypeInfo(node);
|
memberType = semanticModel.GetTypeInfo(node);
|
||||||
|
|
|
@ -94,9 +94,8 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World
|
||||||
this.RemoveObjects(location, obj =>
|
this.RemoveObjects(location, obj =>
|
||||||
obj is not Chest
|
obj is not Chest
|
||||||
&& (
|
&& (
|
||||||
obj.Name == "Weeds"
|
obj.Name is "Weeds" or "Stone"
|
||||||
|| obj.Name == "Stone"
|
|| obj.ParentSheetIndex is 294 or 295
|
||||||
|| (obj.ParentSheetIndex == 294 || obj.ParentSheetIndex == 295)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
+ this.RemoveResourceClumps(location, clump => this.DebrisClumps.Contains(clump.parentSheetIndex.Value));
|
+ this.RemoveResourceClumps(location, clump => this.DebrisClumps.Contains(clump.parentSheetIndex.Value));
|
||||||
|
|
|
@ -106,7 +106,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework
|
||||||
{
|
{
|
||||||
foreach (int id in this.TryLoad<int, string>("Data\\weapons").Keys)
|
foreach (int id in this.TryLoad<int, string>("Data\\weapons").Keys)
|
||||||
{
|
{
|
||||||
yield return this.TryCreate(ItemType.Weapon, id, p => (p.ID >= 32 && p.ID <= 34)
|
yield return this.TryCreate(ItemType.Weapon, id, p => p.ID is >= 32 and <= 34
|
||||||
? (Item)new Slingshot(p.ID)
|
? (Item)new Slingshot(p.ID)
|
||||||
: new MeleeWeapon(p.ID)
|
: new MeleeWeapon(p.ID)
|
||||||
);
|
);
|
||||||
|
|
|
@ -137,7 +137,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
|
||||||
return new ModFolder(root, searchFolder, ModType.Xnb, null, ModParseError.XnbMod, "it's not a SMAPI mod (see https://smapi.io/xnb for info).");
|
return new ModFolder(root, searchFolder, ModType.Xnb, null, ModParseError.XnbMod, "it's not a SMAPI mod (see https://smapi.io/xnb for info).");
|
||||||
|
|
||||||
// SMAPI installer
|
// SMAPI installer
|
||||||
if (relevantFiles.Any(p => p.Name == "install on Linux.sh" || p.Name == "install on macOS.command" || p.Name == "install on Windows.bat"))
|
if (relevantFiles.Any(p => p.Name is "install on Linux.sh" or "install on macOS.command" or "install on Windows.bat"))
|
||||||
return new ModFolder(root, searchFolder, ModType.Invalid, null, ModParseError.ManifestMissing, "the SMAPI installer isn't a mod (you can delete this folder after running the installer file).");
|
return new ModFolder(root, searchFolder, ModType.Invalid, null, ModParseError.ManifestMissing, "the SMAPI installer isn't a mod (you can delete this folder after running the installer file).");
|
||||||
|
|
||||||
// not a mod?
|
// not a mod?
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace StardewModdingAPI.Toolkit.Serialization
|
||||||
{
|
{
|
||||||
json = File.ReadAllText(fullPath);
|
json = File.ReadAllText(fullPath);
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (ex is DirectoryNotFoundException || ex is FileNotFoundException)
|
catch (Exception ex) when (ex is DirectoryNotFoundException or FileNotFoundException)
|
||||||
{
|
{
|
||||||
result = default(TModel);
|
result = default(TModel);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.Chucklefish
|
||||||
.GetAsync(string.Format(this.ModPageUrlFormat, parsedId))
|
.GetAsync(string.Format(this.ModPageUrlFormat, parsedId))
|
||||||
.AsString();
|
.AsString();
|
||||||
}
|
}
|
||||||
catch (ApiException ex) when (ex.Status == HttpStatusCode.NotFound || ex.Status == HttpStatusCode.Forbidden)
|
catch (ApiException ex) when (ex.Status is HttpStatusCode.NotFound or HttpStatusCode.Forbidden)
|
||||||
{
|
{
|
||||||
return page.SetError(RemoteModStatus.DoesNotExist, "Found no Chucklefish mod with this ID.");
|
return page.SetError(RemoteModStatus.DoesNotExist, "Found no Chucklefish mod with this ID.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.Nexus
|
||||||
mod = await this.GetModFromApiAsync(parsedId);
|
mod = await this.GetModFromApiAsync(parsedId);
|
||||||
|
|
||||||
// page doesn't exist
|
// page doesn't exist
|
||||||
if (mod == null || mod.Status == NexusModStatus.Hidden || mod.Status == NexusModStatus.NotPublished)
|
if (mod == null || mod.Status is NexusModStatus.Hidden or NexusModStatus.NotPublished)
|
||||||
return page.SetError(RemoteModStatus.DoesNotExist, "Found no Nexus mod with this ID.");
|
return page.SetError(RemoteModStatus.DoesNotExist, "Found no Nexus mod with this ID.");
|
||||||
|
|
||||||
// return info
|
// return info
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace StardewModdingAPI
|
||||||
internal static bool IsSaveLoaded => Game1.hasLoadedGame && Game1.activeClickableMenu is not TitleMenu;
|
internal static bool IsSaveLoaded => Game1.hasLoadedGame && Game1.activeClickableMenu is not TitleMenu;
|
||||||
|
|
||||||
/// <summary>Whether the game is currently writing to the save file.</summary>
|
/// <summary>Whether the game is currently writing to the save file.</summary>
|
||||||
internal static bool IsSaving => Game1.activeClickableMenu is SaveGameMenu || Game1.activeClickableMenu is ShippingMenu; // saving is performed by SaveGameMenu, but it's wrapped by ShippingMenu on days when the player shipping something
|
internal static bool IsSaving => Game1.activeClickableMenu is SaveGameMenu or ShippingMenu; // saving is performed by SaveGameMenu, but it's wrapped by ShippingMenu on days when the player shipping something
|
||||||
|
|
||||||
/// <summary>The active split-screen instance IDs.</summary>
|
/// <summary>The active split-screen instance IDs.</summary>
|
||||||
internal static readonly ISet<int> ActiveScreenIds = new HashSet<int>();
|
internal static readonly ISet<int> ActiveScreenIds = new HashSet<int>();
|
||||||
|
@ -39,7 +39,7 @@ namespace StardewModdingAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Whether the in-game world is completely unloaded and not in the process of being loaded. The world may still exist in memory at this point, but should be ignored.</summary>
|
/// <summary>Whether the in-game world is completely unloaded and not in the process of being loaded. The world may still exist in memory at this point, but should be ignored.</summary>
|
||||||
internal static bool IsWorldFullyUnloaded => Context.LoadStage == LoadStage.ReturningToTitle || Context.LoadStage == LoadStage.None;
|
internal static bool IsWorldFullyUnloaded => Context.LoadStage is LoadStage.ReturningToTitle or LoadStage.None;
|
||||||
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
|
|
|
@ -47,9 +47,9 @@ namespace StardewModdingAPI.Framework.Content
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public TData GetData<TData>()
|
public TData GetData<TData>()
|
||||||
{
|
{
|
||||||
if (this.Data is not TData)
|
if (this.Data is not TData data)
|
||||||
throw new InvalidCastException($"The content data of type {this.Data.GetType().FullName} can't be converted to the requested {typeof(TData).FullName}.");
|
throw new InvalidCastException($"The content data of type {this.Data.GetType().FullName} can't be converted to the requested {typeof(TData).FullName}.");
|
||||||
return (TData)this.Data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,7 @@ namespace StardewModdingAPI.Framework.Input
|
||||||
isDown: pressed.Contains(button)
|
isDown: pressed.Contains(button)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (button == SButton.MouseLeft || button == SButton.MouseMiddle || button == SButton.MouseRight || button == SButton.MouseX1 || button == SButton.MouseX2)
|
if (button is SButton.MouseLeft or SButton.MouseMiddle or SButton.MouseRight or SButton.MouseX1 or SButton.MouseX2)
|
||||||
mouseOverrides[button] = newState;
|
mouseOverrides[button] = newState;
|
||||||
else if (button.TryGetKeyboard(out Keys _))
|
else if (button.TryGetKeyboard(out Keys _))
|
||||||
keyboardOverrides[button] = newState;
|
keyboardOverrides[button] = newState;
|
||||||
|
|
|
@ -32,11 +32,8 @@ namespace StardewModdingAPI.Framework.ModLoading
|
||||||
ModDataRecordVersionedFields dataRecord = modDatabase.Get(manifest?.UniqueID)?.GetVersionedFields(manifest);
|
ModDataRecordVersionedFields dataRecord = modDatabase.Get(manifest?.UniqueID)?.GetVersionedFields(manifest);
|
||||||
|
|
||||||
// apply defaults
|
// apply defaults
|
||||||
if (manifest != null && dataRecord != null)
|
if (manifest != null && dataRecord?.UpdateKey is not null)
|
||||||
{
|
manifest.UpdateKeys = new[] { dataRecord.UpdateKey };
|
||||||
if (dataRecord.UpdateKey != null)
|
|
||||||
manifest.UpdateKeys = new[] { dataRecord.UpdateKey };
|
|
||||||
}
|
|
||||||
|
|
||||||
// build metadata
|
// build metadata
|
||||||
bool shouldIgnore = folder.Type == ModType.Ignored;
|
bool shouldIgnore = folder.Type == ModType.Ignored;
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
|
||||||
|
|
||||||
// skip if not broken
|
// skip if not broken
|
||||||
FieldDefinition fieldDefinition = fieldRef.Resolve();
|
FieldDefinition fieldDefinition = fieldRef.Resolve();
|
||||||
if (fieldDefinition != null && !fieldDefinition.HasConstant)
|
if (fieldDefinition?.HasConstant == false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// rewrite if possible
|
// rewrite if possible
|
||||||
|
|
|
@ -674,7 +674,7 @@ namespace StardewModdingAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// mouse
|
// mouse
|
||||||
if (input == SButton.MouseLeft || input == SButton.MouseRight)
|
if (input is SButton.MouseLeft or SButton.MouseRight)
|
||||||
{
|
{
|
||||||
button = new InputButton(mouseLeft: input == SButton.MouseLeft);
|
button = new InputButton(mouseLeft: input == SButton.MouseLeft);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace StardewModdingAPI
|
||||||
/// <param name="state">The button state.</param>
|
/// <param name="state">The button state.</param>
|
||||||
public static bool IsDown(this SButtonState state)
|
public static bool IsDown(this SButtonState state)
|
||||||
{
|
{
|
||||||
return state == SButtonState.Held || state == SButtonState.Pressed;
|
return state is SButtonState.Held or SButtonState.Pressed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,11 +118,11 @@ namespace StardewModdingAPI.Utilities
|
||||||
return SButtonState.None;
|
return SButtonState.None;
|
||||||
|
|
||||||
// mix of held + pressed => pressed
|
// mix of held + pressed => pressed
|
||||||
if (states.All(p => p == SButtonState.Pressed || p == SButtonState.Held))
|
if (states.All(p => p is SButtonState.Pressed or SButtonState.Held))
|
||||||
return SButtonState.Pressed;
|
return SButtonState.Pressed;
|
||||||
|
|
||||||
// mix of held + released => released
|
// mix of held + released => released
|
||||||
if (states.All(p => p == SButtonState.Held || p == SButtonState.Released))
|
if (states.All(p => p is SButtonState.Held or SButtonState.Released))
|
||||||
return SButtonState.Released;
|
return SButtonState.Released;
|
||||||
|
|
||||||
// not down last tick or now
|
// not down last tick or now
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace StardewModdingAPI.Utilities
|
||||||
public bool IsDown()
|
public bool IsDown()
|
||||||
{
|
{
|
||||||
SButtonState state = this.GetState();
|
SButtonState state = this.GetState();
|
||||||
return state == SButtonState.Pressed || state == SButtonState.Held;
|
return state is SButtonState.Pressed or SButtonState.Held;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Get whether the input binding was just pressed this tick.</summary>
|
/// <summary>Get whether the input binding was just pressed this tick.</summary>
|
||||||
|
|
Loading…
Reference in New Issue