note description: "[ A table of TUPLEs where each TUPLE holds an EV_WORLD object (e.g. EV_TEXT_WIDGET, ATTACK_UNIT_WIDGET, etc.) along with an EV_COORDINATE of where that widget should be placed, indexed by a string name. ]" author: "Jimmy J. Johnson" date: "11/11/23" copyright: "Copyright (c) 2023, Jimmy J. Johnson" license: "Eiffel Forum v2 (http://www.eiffel.com/licensing/forum.txt)" class WIDGET_POSITION_TABLE [G -> EV_MODEL, K -> HASHABLE] --inherit -- HASH_TABLE [TUPLE [mod: G; loc: EV_COORDINATE], K] -- rename -- extend as table_extend -- export -- {NONE} -- put, -- force, -- table_extend, -- replace, -- replace_key, -- merge -- end create make feature {NONE} -- Initialization make -- Create an instance do create table.make (100) end feature -- Access widget (a_key: K): EV_MODEL -- The widget associated with `a_key' require has_key: has (a_key) do Result := table.definite_item (a_key).mod end location (a_key: K): EV_COORDINATE -- The location associated with `a_key' require has_key: has (a_key) do Result := table.definite_item (a_key).loc end widget_for_iteration: EV_MODEL -- The `widget' item at the current iteration position require not_off: not is_off do Result := table.item_for_iteration.mod end location_for_iteration: EV_COORDINATE -- The `location' item at the current iteration position require not_off: not is_off do Result := table.item_for_iteration.loc end key_for_iteration: K -- The key at thge currenbt iteration position require not_off: not is_off do Result := table.key_for_iteration end feature -- Query has (a_key: K): BOOLEAN -- Does Current contain an item with `a_key' do Result := table.has (a_key) end feature -- Element change extend (a_widget: EV_MODEL; a_x, a_y: INTEGER; a_key: K) -- Add `a_widget' to the table, located at (a_x, a_y) and -- indexed by `a_key'. Replace any previous item that -- was indexed by `a_key'. -- An EV_COORDINATE is created from `a_x' and `a_y'. local loc: EV_COORDINATE do create loc.make (a_x, a_y) table.force ([a_widget, loc], a_key) end reposition (a_key: K; a_x, a_y: INTEGER) -- Change the `location' for the item indexed by `a_key' require has_key: has (a_key) do location (a_key).set_x (a_x) location (a_key).set_y (a_y) end feature -- Cursor movement start -- Bring cursor to first position do table.start end forth -- Advance cursor to next position or `is_off' require not_off: not is_off do table.forth end is_off: BOOLEAN -- Is the cursor after the last item? do Result := table.off end feature {NONE} -- Implementation table: HASH_TABLE [TUPLE [mod: EV_MODEL; loc: EV_COORDINATE], K] -- Implementation of Current end