-
Notifications
You must be signed in to change notification settings - Fork 438
Zip #745
base: indev
Are you sure you want to change the base?
Zip #745
Conversation
GameServerLib/Content/CharData.cs
Outdated
@@ -110,10 +115,11 @@ public void Load(string name) | |||
HpRegenPerLevel = file.GetFloat("Data", "HPRegenPerLevel", HpRegenPerLevel); | |||
MpRegenPerLevel = file.GetFloat("Data", "MPRegenPerLevel", MpRegenPerLevel); | |||
AttackSpeedPerLevel = file.GetFloat("Data", "AttackSpeedPerLevel", AttackSpeedPerLevel); | |||
IsMelee = file.GetString("Data", "IsMelee", IsMelee ? "Yes" : "No").Equals("yes"); | |||
IsMelee = file.GetString("Data", "IsMelee", IsMelee ? "Yes" : "No").ToLower().Equals("yes"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self note: make this ToLowerInvariant()
just in case.
Codecov Report
@@ Coverage Diff @@
## indev #745 +/- ##
========================================
+ Coverage 1.88% 9.15% +7.27%
========================================
Files 131 131
Lines 7798 7742 -56
Branches 614 616 +2
========================================
+ Hits 147 709 +562
+ Misses 7651 7028 -623
- Partials 0 5 +5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some indexes instead of arrays, don't sure if it's from your PR or was already, but should be changed.
GameServerLib/Items/ItemData.cs
Outdated
public int RecipeItem1 { get; private set; } | ||
public int RecipeItem2 { get; private set; } | ||
public int RecipeItem3 { get; private set; } | ||
public int RecipeItem4 { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need only 4? maybe use array? and do RecipeItem[i] = content.GetInt("Data", "RecipeItem{i}", -1),
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, there doesn't seem to be a good reason to limit this to just 4 items. My vote also goes out to arrays (for potential custom content in the future).
GameServerLib/Items/ItemRecipe.cs
Outdated
itemManager.SafeGetItemType(_owner.RecipeItem1), | ||
itemManager.SafeGetItemType(_owner.RecipeItem2), | ||
itemManager.SafeGetItemType(_owner.RecipeItem3), | ||
itemManager.SafeGetItemType(_owner.RecipeItem4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also use array and loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now requesting changes because of the recipe and argument name. Do also check if LINQ can make your code cleaner though.
Other than that, what is the memory usage of loading all game data upon startup? I understand that it makes the rest easier, but isn't ZIP a random access format (meaning you should be able to just store offsets/lengths in your dictionary and read from file on demand)? I won't make you change all the stuff, but keep it in mind.
{ | ||
contents.Add(directory.Replace('\\', '/').Split('/').Last()); | ||
return path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no faster LINQ way to do this? possibilities.First
or something?
throw new ContentNotFoundException($"Spell data for {spellName} was not found."); | ||
if (Content.ContainsKey(path)) | ||
{ | ||
return path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
GameServerLib/Items/ItemData.cs
Outdated
public int RecipeItem1 { get; private set; } | ||
public int RecipeItem2 { get; private set; } | ||
public int RecipeItem3 { get; private set; } | ||
public int RecipeItem4 { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, there doesn't seem to be a good reason to limit this to just 4 items. My vote also goes out to arrays (for potential custom content in the future).
if (item != null) | ||
{ | ||
_totalPrice += item.TotalPrice; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This most likely can also be a LINQ sum
GameServerLib/Items/Shop.cs
Outdated
_game.PacketNotifier.NotifyRemoveItem(_owner, slotId, stackSize); | ||
_owner.RemoveSpell((byte)(slotId + ITEM_ACTIVE_OFFSET)); | ||
inventory.RemoveItem(item); | ||
} | ||
|
||
private bool AddItem(ItemType itemType) | ||
private bool AddItem(ItemData ıtemData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the proper normal english i
here 😋
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While i went through your changes i noticed that you also changed some enums and while i'm pretty sure that those changes have nothing to do with .zip support it can be overlooked.
That being said i can't help but notice that the way you implemented this is by loading all file contents in memory as bytes while checking if .zip file is present.
I don't think this is acceptable solution even for a short term.
Aside from performance issues this will cause, it is not really clear how this interacts with multiple packages providing the same file and doesn't provide any mechanism for possible further exstensions.
It would be shame to just drop this PR because of other changes that you made to organize content loading.
|
||
private byte[] _data; | ||
|
||
public FileEntry(string name, string fullPath, Stream stream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still storing full content of the file into memory.
However this time you did define a class that describes an interface for a FileEntry
.
You should extract this interface so that you can have multiple implementations for FileEntry
(example .zip or file system).
And yes this would mean that your ContentManager
would have to implement IDisposable
to get rid of open .zip handles which should be trivial to implement(store them in list).
So what you should implement is FilesystemFileEntry
which should be wraper for IFilerEntry
around this class:
https://docs.microsoft.com/en-us/dotnet/api/system.io.fileinfo?view=netframework-4.7.2
For ZipFileEntry
you can wrap this class(ZipArchiveEntry
):
https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-compress-and-extract-files
Both of those provide you a way to:
- File name
- File name relative to root path of package
Open
orOpenRead
which returns a stream
.zip
file support for content. (Unzipped files may overwrite what is in.zip
)No other mentionable change, except compatibility.
Requires LeagueSandbox/LeagueSandbox-Default#84 to work, because the content has been regenerated.