Dmarsh12fitch / CircutBoardTowerDefense

0 stars 1 forks source link

Added a Keyboard Controlled Focus Indicator #4

Closed andystopia closed 2 years ago

andystopia commented 2 years ago

Motivation

Keyboard control.

If you don't recognize a class name, that's because I wrote it.

Change Log

Basically my design philosophy is that there is a lot of state in this game. Those states can be divided into two separate concepts. Inclusive States and Exclusive States. Exclusive states are states which are mutually exclusive from all other states. Inclusive states are the states of co-existing states. All of this program is an exclusive state, although it certainly does not need to be that way.

So for most objects, there will be several components. There will be a selection component (BlahBlahBlahSelectionInteractor) inside the object, and there will be a selection manager, outside the object. Right now all the managers are exclusive, although that could certainly change in the future.

There is also focus components, and these are a little more complicated. These tie a bunch of things together. You'll have the same FocusInteractor (on the object), and FocusManager outside the object, except FocusManager is itself managed by ActiveRegionFocus, which ensures only one focus manager can be focused at any given time (exclusive state).

This is because something could be focused (like when it's hovered), but not selected( like when it's clicked)

Each focus interactor will also have several dependencies as components:

I also wrote an observer pattern for events, but it seems to me as though this is a bad plan, and it looks like most people use a ScriptableObject Observer pattern instead, which, admittedly, is a much better idea, but still probably a little hard to use. So I don't actually use the observer's I wrote, but I just didn't feel like deleting them.

Please use this system or propose an alternative; state desync is really hard to deal with.

Bugs

Due to the desync of TileSelectionInteractor and TileFocusInteractor, sometimes mouse events cause the FocusIndicator to be black, this is a bug that needs to be fixed, but not one that I cared fix before publishing.

The renderer bounds of objects cannot be known until they render, so you can't set a focused object on the first frame accurately, because it will just give you an all zero bounds. Not really sure how to fix this one, maybe we can defer for a frame? We could open an issue to discuss this one.

Due to the fact that tiles with turrets on them can't be clicked when a turret sits on top of them, I removed that collider on turret, so turrets can no longer be disabled by mobs thanks to the fact that it uses a Physics collider to calculate.

Details

You may notice the TurretShopSelectionManager isn't used, that's because I use the OldTurretShopManager, since they implement the same interface, which allows the bottom left turrets to highlight when I select using my custom menu.

Keyboard Controls are as follows:

andystopia commented 2 years ago

I closed my other one, and it can be deleted, because when I merged it with my own main branch, it had a flaw with the range indicator not disappearing, so I merged into my main branch, tested, and am now submitting it.