• R/O
  • SSH

dwaddle: Commit

Main Dwaddle repository


Commit MetaInfo

Revision3f9a1813536f24d550742eaf168547575d1c8fa9 (tree)
Time2021-05-22 07:14:20
AuthorRemilia Scarlet <remilia@post...>
CommiterRemilia Scarlet

Log Message

Add #indicesNamed, #lastIndexOf, and #insert to WadFile class.

Change Summary

Incremental Difference

diff -r 0f2519756157 -r 3f9a1813536f src/wadfile.cr
--- a/src/wadfile.cr Fri May 21 16:13:50 2021 -0600
+++ b/src/wadfile.cr Fri May 21 16:14:20 2021 -0600
@@ -309,6 +309,23 @@
309309 end
310310 end
311311
312+ # Inserts `lmp` at the specified index, shifting successing lumps. If `idx`
313+ # is greater than the `#size` of this wad, `lmp` is simply added at the end.
314+ def insert(idx : UInt32, lmp : Lump)
315+ if idx >= self.size
316+ self << lmp
317+ else
318+ @entries.insert(idx, lmp)
319+ lmp.parent = self
320+
321+ if @entriesTable.has_key?(lmp.name)
322+ @entriesTable[lmp.name] << lmp
323+ else
324+ @entriesTable[lmp.name] = [lmp]
325+ end
326+ end
327+ end
328+
312329 # Removes the given lump from this wad. If this wad does not contain the
313330 # lump, a `WadError` is raised.
314331 def remove(lmp : Lump)
@@ -409,6 +426,13 @@
409426 -1
410427 end
411428
429+ # Returns the index of the last lump that matches the given name, or -1 if
430+ # no such lump exists.
431+ def lastIndexOf(name : String) : Int
432+ @entries.reverse.each_index { |idx| return idx if @entries[idx].name == name.upcase }
433+ -1
434+ end
435+
412436 # Returns an array of lumps that match the given name.
413437 def lumpsNamed(name : String) : Array(Lump)
414438 if @entriesTable.has_key?(name.upcase)
@@ -418,6 +442,17 @@
418442 end
419443 end
420444
445+ # Returns an array of lump indices that match the given name.
446+ def indicesNamed(name : String) : Array(Int32)
447+ ret = [] of Int32
448+ self.each_with_index do |lmp, idx|
449+ if lmp.name == name.upcase
450+ ret << idx
451+ end
452+ end
453+ ret
454+ end
455+
421456 # Returns the first lump with the given name. `startIdx` is the index at
422457 # which to start searching within the wad.
423458 def firstLumpNamed(name, startIdx = 0)
Show on old repository browser