Windows in scene map: duplicate code

Mainly for ace but doesn't make a difference since the question is generic enough.

Ok so basically there are a couple things that people want in Ace like displaying an item window (with the item usage functionality like in Scene_Item), or showing the actor's equips (for a single-actor party).

Right on the map in real-time. You know kind of like how things work in diablo or stuff.

But I didn't feel like converting them from VX because I am basically duplicating logic that is written in Scene_Item and Scene_Equip that handles all of the item usage and equip switching.

The status window isn't too bad since there isn't much logic there, but what if I wanted to port an arbitrary window over to the map scene?

It's really silly. I'd like to just use the logic that's already written in Scene_Item and Scene_ItemBase and Scene_Equip, except draw my windows in Scene_Map.

I don't know how to solve this problem without writing duplicate code.
When you say logic already written in Scene_Item and Scene_ItemBase, are you talking about creating the instances wich were created in those scenes or the commands processing?
The command processing.

I don't want to copy the "use_item" method over, or all of the methods that perform checks and stuff to determine whether I can use it, what to use it on, etc

The windows I would need to instantiate because I might need to customize the dimensions and positions.
Ever tried to include those classes inside your class? Try searching for multiple inheritance in Ruby and you'll find plenty ways to do what you need.
I know you can include multiple modules but never heard of including classes.

I think I'm stuck with Scene_Map though, since a lot of code probably assumes Scene_Map is the actual map scene, and not some custom map scene.
You could rewrite everything you need into a new super class and then write a new Scene_Map child from that class...
Its fairly easy to replicate all the logic from these scenes without any serious repercussion.

As far as I'm concerned, you should have as minimum logic in your 'graphic' classes.

Anyway, sometimes you have to write duplicate code, the answer will not come to you immediately, and the more time you spend

trying to find a shortcut is the more time you'll probably end up losing.

What I'm saying is:

Just write the code, and then fix it later instead of trying to perfect it at once.

pretty much what Gleen said.

I can give you a tip on custom scenes that need a Game_Map



Code:
module MyMapThing
  module Kernel
    def _map
      your_map # // Game_Map 
    end

    def _player
      your_player # // Some Game_Character
    end
  end
end

class Game_Interpreter
  def _map
    $game_map
  end
  def _player
    $game_player
  end
  # // Overwrite all methods that have calls to $game_map and $game_player
  # // with _map and _player respectively
end
# // Do the same for all the other built in classes

# // 
class Game_Interpreter_MMP < Game_Interpreter
  include MyMapThing::Kernel
  # // No rewriting required because now you have access to your custom map
  # // by writing the parent class modular 
end

# // Be sure to include your custom kernel in all your needed classes.

class Game_Event_MMP < Game_Event
  include MyMapThing::Kernel
end
This is a technique I created for writing custom map scenes.

Its a bit time consuming at first, but well worth the trouble 😀

After you've cleared the overwriting side of things, its all about your

custom scene and how you plan to deal with it.

Original thread: https://forums.rpgmakerweb.com/threads/windows-in-scene-map-duplicate-code.3164/