Finished testing and docs for now. Time for new features!
This commit is contained in:
+22
-2
@@ -1,22 +1,42 @@
|
||||
# Nathan Hinton 1 Oct 2025
|
||||
# Create a custom hash class for the universe.
|
||||
|
||||
require 'logger'
|
||||
|
||||
require './position'
|
||||
|
||||
# This will contain the universe hash inside it. It will allow for array type
|
||||
# indexing as well as point type indexing
|
||||
class UniverseArray < Array
|
||||
def initialize
|
||||
end
|
||||
|
||||
@@logger = Logger.new('logs/universe.log')
|
||||
|
||||
# Custom accessor. This allows us to access either with a position object
|
||||
# (preferred as it does validation) or direct access.
|
||||
#
|
||||
# @param index [Integer, Position] If it is an integer nothing special. If a
|
||||
# Position it will be intepreted for us into the regular indexint.
|
||||
# @param rest [Object] Actually, I have no idea why this is here. (copy paste)
|
||||
# @return Whatever is at that position. Can be anything.
|
||||
def [](index, *rest)
|
||||
#require 'byebug';debugger
|
||||
if index.is_a?(Position)
|
||||
if self[index.y_pos].nil?
|
||||
@@logger.debug "attempted access outside of known universe!"
|
||||
return nil
|
||||
end
|
||||
return self[index.y_pos][index.x_pos]
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# Custom writer. This allows us to access either with a position object
|
||||
# (preferred as it does validation) or direct access.
|
||||
#
|
||||
# @param index [Integer, Position] If it is an integer nothing special. If a
|
||||
# Position it will be intepreted for us into the regular indexint.
|
||||
# @param rest [Object] This (if intercepted) has the value we should assign
|
||||
def []=(index, *rest)
|
||||
if index.is_a?(Position)
|
||||
return self[index.y_pos][index.x_pos] = rest[0]
|
||||
|
||||
Reference in New Issue
Block a user