Merge branch 'Pryaxis:general-devel' into tshock-installer
This commit is contained in:
commit
c600966a75
6 changed files with 143 additions and 80 deletions
|
|
@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
|
@ -35,6 +35,8 @@ namespace TShockAPI.Localization
|
||||||
|
|
||||||
private static readonly Dictionary<int, string> Prefixs = new Dictionary<int, string>();
|
private static readonly Dictionary<int, string> Prefixs = new Dictionary<int, string>();
|
||||||
|
|
||||||
|
private static readonly Dictionary<int, string> Buffs = new Dictionary<int, string>();
|
||||||
|
|
||||||
internal static void Initialize()
|
internal static void Initialize()
|
||||||
{
|
{
|
||||||
var culture = Language.ActiveCulture;
|
var culture = Language.ActiveCulture;
|
||||||
|
|
@ -58,10 +60,16 @@ namespace TShockAPI.Localization
|
||||||
NpcNames.Add(i, Lang.GetNPCNameValue(i));
|
NpcNames.Add(i, Lang.GetNPCNameValue(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < Terraria.ID.BuffID.Count; i++)
|
||||||
|
{
|
||||||
|
Buffs.Add(i, Lang.GetBuffName(i));
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var field in typeof(Main).Assembly.GetType("Terraria.ID.PrefixID")
|
foreach (var field in typeof(Main).Assembly.GetType("Terraria.ID.PrefixID")
|
||||||
.GetFields().Where(f => !f.Name.Equals("Count", StringComparison.Ordinal)))
|
.GetFields().Where(f => !f.Name.Equals("Count", StringComparison.Ordinal)))
|
||||||
{
|
{
|
||||||
Prefixs.Add((int) field.GetValue(null), field.Name);
|
var i = (int)field.GetValue(null);
|
||||||
|
Prefixs.Add(i, Lang.prefix[i].Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
@ -114,5 +122,19 @@ namespace TShockAPI.Localization
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get buff name in English
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Buff Id</param>
|
||||||
|
/// <returns>Buff name in English</returns>
|
||||||
|
public static string GetBuffNameById(int id)
|
||||||
|
{
|
||||||
|
string buff;
|
||||||
|
if (Buffs.TryGetValue(id, out buff))
|
||||||
|
return buff;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ namespace TShockAPI
|
||||||
/// <summary>VersionNum - The version number the TerrariaAPI will return back to the API. We just use the Assembly info.</summary>
|
/// <summary>VersionNum - The version number the TerrariaAPI will return back to the API. We just use the Assembly info.</summary>
|
||||||
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
|
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
/// <summary>VersionCodename - The version codename is displayed when the server starts. Inspired by software codenames conventions.</summary>
|
/// <summary>VersionCodename - The version codename is displayed when the server starts. Inspired by software codenames conventions.</summary>
|
||||||
public static readonly string VersionCodename = "ζ Ori";
|
public static readonly string VersionCodename = "Thank you, everyone, for your support of TShock all these years! <3";
|
||||||
|
|
||||||
/// <summary>SavePath - This is the path TShock saves its data in. This path is relative to the TerrariaServer.exe (not in ServerPlugins).</summary>
|
/// <summary>SavePath - This is the path TShock saves its data in. This path is relative to the TerrariaServer.exe (not in ServerPlugins).</summary>
|
||||||
public static string SavePath = "tshock";
|
public static string SavePath = "tshock";
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
Also, be sure to release on github with the exact assembly version tag as below
|
Also, be sure to release on github with the exact assembly version tag as below
|
||||||
so that the update manager works correctly (via the Github releases api and mimic)
|
so that the update manager works correctly (via the Github releases api and mimic)
|
||||||
-->
|
-->
|
||||||
<Version>5.1.2</Version>
|
<Version>5.1.3</Version>
|
||||||
<AssemblyTitle>TShock for Terraria</AssemblyTitle>
|
<AssemblyTitle>TShock for Terraria</AssemblyTitle>
|
||||||
<Company>Pryaxis & TShock Contributors</Company>
|
<Company>Pryaxis & TShock Contributors</Company>
|
||||||
<Product>TShockAPI</Product>
|
<Product>TShockAPI</Product>
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ namespace TShockAPI
|
||||||
private static readonly Utils instance = new Utils();
|
private static readonly Utils instance = new Utils();
|
||||||
|
|
||||||
/// <summary>Utils - Creates a utilities object.</summary>
|
/// <summary>Utils - Creates a utilities object.</summary>
|
||||||
private Utils() {}
|
private Utils() { }
|
||||||
|
|
||||||
/// <summary>Instance - An instance of the utils class.</summary>
|
/// <summary>Instance - An instance of the utils class.</summary>
|
||||||
/// <value>value - the Utils instance</value>
|
/// <value>value - the Utils instance</value>
|
||||||
|
|
@ -210,8 +210,8 @@ namespace TShockAPI
|
||||||
tileY = startTileY;
|
tileY = startTileY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tileX = startTileX + r.Next(tileXRange*-1, tileXRange);
|
tileX = startTileX + r.Next(tileXRange * -1, tileXRange);
|
||||||
tileY = startTileY + r.Next(tileYRange*-1, tileYRange);
|
tileY = startTileY + r.Next(tileYRange * -1, tileYRange);
|
||||||
j++;
|
j++;
|
||||||
} while (TilePlacementValid(tileX, tileY) && TileSolid(tileX, tileY));
|
} while (TilePlacementValid(tileX, tileY) && TileSolid(tileX, tileY));
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +253,7 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
if (type >= Terraria.ID.ItemID.Count)
|
if (type >= Terraria.ID.ItemID.Count)
|
||||||
return new List<Item>();
|
return new List<Item>();
|
||||||
return new List<Item> {GetItemById(type)};
|
return new List<Item> { GetItemById(type) };
|
||||||
}
|
}
|
||||||
Item item = GetItemFromTag(text);
|
Item item = GetItemFromTag(text);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
|
|
@ -280,37 +280,35 @@ namespace TShockAPI
|
||||||
/// <returns>List of Items</returns>
|
/// <returns>List of Items</returns>
|
||||||
public List<Item> GetItemByName(string name)
|
public List<Item> GetItemByName(string name)
|
||||||
{
|
{
|
||||||
var found = new List<Item>();
|
var startswith = new List<int>();
|
||||||
Item item = new Item();
|
var contains = new List<int>();
|
||||||
string nameLower = name.ToLowerInvariant();
|
for (int i = 1; i < ItemID.Count; i++)
|
||||||
var checkEnglish = Language.ActiveCulture != GameCulture.FromCultureName(GameCulture.CultureName.English);
|
|
||||||
|
|
||||||
for (int i = 1; i < Terraria.ID.ItemID.Count; i++)
|
|
||||||
{
|
{
|
||||||
item.netDefaults(i);
|
var currentName = Lang.GetItemNameValue(i);
|
||||||
if (!String.IsNullOrWhiteSpace(item.Name))
|
if (!string.IsNullOrEmpty(currentName))
|
||||||
{
|
{
|
||||||
if (item.Name.ToLowerInvariant() == nameLower)
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new List<Item> { item };
|
return new List<Item> { GetItemById(i) };
|
||||||
if (item.Name.ToLowerInvariant().StartsWith(nameLower))
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
found.Add(item.Clone());
|
startswith.Add(i);
|
||||||
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
contains.Add(i);
|
||||||
}
|
}
|
||||||
|
currentName = EnglishLanguage.GetItemNameById(i);
|
||||||
if (!checkEnglish)
|
if (!string.IsNullOrEmpty(currentName))
|
||||||
{
|
{
|
||||||
continue;
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
}
|
return new List<Item> { GetItemById(i) };
|
||||||
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
string englishName = EnglishLanguage.GetItemNameById(i).ToLowerInvariant();
|
startswith.Add(i);
|
||||||
if (!String.IsNullOrEmpty(englishName))
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
contains.Add(i);
|
||||||
if (englishName == nameLower)
|
|
||||||
return new List<Item> { item };
|
|
||||||
if (englishName.StartsWith(nameLower))
|
|
||||||
found.Add(item.Clone());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
|
||||||
|
if (startswith.Count != 1)
|
||||||
|
startswith.AddRange(contains);
|
||||||
|
return startswith.Select(GetItemById).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -369,22 +367,35 @@ namespace TShockAPI
|
||||||
/// <returns>List of matching NPCs</returns>
|
/// <returns>List of matching NPCs</returns>
|
||||||
public List<NPC> GetNPCByName(string name)
|
public List<NPC> GetNPCByName(string name)
|
||||||
{
|
{
|
||||||
var found = new List<NPC>();
|
var startswith = new List<int>();
|
||||||
NPC npc = new NPC();
|
var contains = new List<int>();
|
||||||
string nameLower = name.ToLowerInvariant();
|
for (int i = -17; i < NPCID.Count; i++)
|
||||||
for (int i = -17; i < Terraria.ID.NPCID.Count; i++)
|
|
||||||
{
|
{
|
||||||
string englishName = EnglishLanguage.GetNpcNameById(i).ToLowerInvariant();
|
var currentName = Lang.GetNPCNameValue(i);
|
||||||
|
if (!string.IsNullOrEmpty(currentName))
|
||||||
npc.SetDefaults(i);
|
{
|
||||||
if (npc.FullName.ToLowerInvariant() == nameLower || npc.TypeName.ToLowerInvariant() == nameLower
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|| nameLower == englishName)
|
return new List<NPC> { GetNPCById(i) };
|
||||||
return new List<NPC> { npc };
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
if (npc.FullName.ToLowerInvariant().StartsWith(nameLower) || npc.TypeName.ToLowerInvariant().StartsWith(nameLower)
|
startswith.Add(i);
|
||||||
|| englishName?.StartsWith(nameLower) == true)
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
found.Add((NPC)npc.Clone());
|
contains.Add(i);
|
||||||
|
}
|
||||||
|
currentName = EnglishLanguage.GetNpcNameById(i);
|
||||||
|
if (!string.IsNullOrEmpty(currentName))
|
||||||
|
{
|
||||||
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return new List<NPC> { GetNPCById(i) };
|
||||||
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
startswith.Add(i);
|
||||||
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
contains.Add(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return found;
|
|
||||||
|
if (startswith.Count != 1)
|
||||||
|
startswith.AddRange(contains);
|
||||||
|
return startswith.Select(GetNPCById).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -414,22 +425,35 @@ namespace TShockAPI
|
||||||
/// <returns>Matching list of buff ids</returns>
|
/// <returns>Matching list of buff ids</returns>
|
||||||
public List<int> GetBuffByName(string name)
|
public List<int> GetBuffByName(string name)
|
||||||
{
|
{
|
||||||
string nameLower = name.ToLower();
|
var startswith = new List<int>();
|
||||||
string buffname;
|
var contains = new List<int>();
|
||||||
for (int i = 1; i < Terraria.ID.BuffID.Count; i++)
|
for (int i = 1; i < BuffID.Count; i++)
|
||||||
{
|
{
|
||||||
buffname = Lang.GetBuffName(i);
|
var currentName = Lang.GetBuffName(i);
|
||||||
if (!String.IsNullOrWhiteSpace(buffname) && buffname.ToLower() == nameLower)
|
if (!string.IsNullOrWhiteSpace(currentName))
|
||||||
return new List<int> {i};
|
{
|
||||||
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return new List<int> { i };
|
||||||
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
startswith.Add(i);
|
||||||
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
contains.Add(i);
|
||||||
|
}
|
||||||
|
currentName = EnglishLanguage.GetBuffNameById(i);
|
||||||
|
if (!string.IsNullOrWhiteSpace(currentName))
|
||||||
|
{
|
||||||
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return new List<int> { i };
|
||||||
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
startswith.Add(i);
|
||||||
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
contains.Add(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var found = new List<int>();
|
|
||||||
for (int i = 1; i < Terraria.ID.BuffID.Count; i++)
|
if (startswith.Count != 1)
|
||||||
{
|
startswith.AddRange(contains);
|
||||||
buffname = Lang.GetBuffName(i);
|
return startswith;
|
||||||
if (!String.IsNullOrWhiteSpace(buffname) && buffname.ToLower().StartsWith(nameLower))
|
|
||||||
found.Add(i);
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -449,24 +473,38 @@ namespace TShockAPI
|
||||||
/// <returns>List of prefix IDs</returns>
|
/// <returns>List of prefix IDs</returns>
|
||||||
public List<int> GetPrefixByName(string name)
|
public List<int> GetPrefixByName(string name)
|
||||||
{
|
{
|
||||||
Item item = new Item();
|
var startswith = new List<int>();
|
||||||
item.SetDefaults(0);
|
var contains = new List<int>();
|
||||||
string lowerName = name.ToLowerInvariant();
|
|
||||||
var found = new List<int>();
|
|
||||||
for (int i = FirstItemPrefix; i <= LastItemPrefix; i++)
|
for (int i = FirstItemPrefix; i <= LastItemPrefix; i++)
|
||||||
{
|
{
|
||||||
item.prefix = (byte)i;
|
var currentName = Lang.prefix[i].ToString();
|
||||||
string prefixName = item.AffixName().Trim().ToLowerInvariant();
|
if (!string.IsNullOrWhiteSpace(currentName))
|
||||||
string englishName = EnglishLanguage.GetPrefixById(i).ToLowerInvariant();
|
{
|
||||||
if (prefixName == lowerName || englishName == lowerName)
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new List<int>() { i };
|
return new List<int> { i };
|
||||||
else if (prefixName.StartsWith(lowerName) || englishName?.StartsWith(lowerName) == true) // Partial match
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
found.Add(i);
|
startswith.Add(i);
|
||||||
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
contains.Add(i);
|
||||||
|
}
|
||||||
|
currentName = EnglishLanguage.GetPrefixById(i);
|
||||||
|
if (!string.IsNullOrWhiteSpace(currentName))
|
||||||
|
{
|
||||||
|
if (currentName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return new List<int> { i };
|
||||||
|
if (currentName.StartsWith(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
startswith.Add(i);
|
||||||
|
else if (currentName.Contains(name, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
contains.Add(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return found;
|
|
||||||
|
if (startswith.Count != 1)
|
||||||
|
startswith.AddRange(contains);
|
||||||
|
return startswith;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a prefix by ID or name
|
/// Gets a prefix by ID or name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idOrName">ID or name</param>
|
/// <param name="idOrName">ID or name</param>
|
||||||
|
|
@ -476,7 +514,7 @@ namespace TShockAPI
|
||||||
int type = -1;
|
int type = -1;
|
||||||
if (int.TryParse(idOrName, out type) && type >= FirstItemPrefix && type <= LastItemPrefix)
|
if (int.TryParse(idOrName, out type) && type >= FirstItemPrefix && type <= LastItemPrefix)
|
||||||
{
|
{
|
||||||
return new List<int> {type};
|
return new List<int> { type };
|
||||||
}
|
}
|
||||||
return GetPrefixByName(idOrName);
|
return GetPrefixByName(idOrName);
|
||||||
}
|
}
|
||||||
|
|
@ -961,7 +999,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
internal void PrepareLangForDump()
|
internal void PrepareLangForDump()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < Main.recipe.Length; i++)
|
for (int i = 0; i < Main.recipe.Length; i++)
|
||||||
Main.recipe[i] = new Recipe();
|
Main.recipe[i] = new Recipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -993,12 +1031,12 @@ namespace TShockAPI
|
||||||
foreach (var field in typeof(Permissions).GetFields().OrderBy(f => f.Name))
|
foreach (var field in typeof(Permissions).GetFields().OrderBy(f => f.Name))
|
||||||
{
|
{
|
||||||
output.Append("|[[");
|
output.Append("|[[");
|
||||||
output.Append((string) field.GetValue(null));
|
output.Append((string)field.GetValue(null));
|
||||||
output.Append("]]|");
|
output.Append("]]|");
|
||||||
|
|
||||||
foreach (Group g in TShock.Groups.groups)
|
foreach (Group g in TShock.Groups.groups)
|
||||||
{
|
{
|
||||||
if (g.HasPermission((string) field.GetValue(null)))
|
if (g.HasPermission((string)field.GetValue(null)))
|
||||||
{
|
{
|
||||||
output.Append("✔|");
|
output.Append("✔|");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3aa54cead523e0edfd25b6895bc0d53a44f1eab1
|
Subproject commit e0e2df24dbc618683cc75595c59bf7f88acada08
|
||||||
|
|
@ -78,7 +78,10 @@ Use past tense when adding new entries; sign your name off when you add or chang
|
||||||
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. -->
|
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. -->
|
||||||
|
|
||||||
## Upcoming changes
|
## Upcoming changes
|
||||||
* Your changes could be here!
|
* Updated the Utils.FindByIdOrName to follow same logic. Now fuzzy match fallback to `StartsWith` and then `Contains`. (@sgkoishi)
|
||||||
|
|
||||||
|
## TShock 5.1.3
|
||||||
|
* Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef)
|
||||||
|
|
||||||
## TShock 5.1.2
|
## TShock 5.1.2
|
||||||
* Added support for Terraria 1.4.4.8.1 via OTAPI 3.1.19. (@SignatureBeef)
|
* Added support for Terraria 1.4.4.8.1 via OTAPI 3.1.19. (@SignatureBeef)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue