ainslec / adventuron-issue-tracker

Adventuron Issues Tracker
4 stars 0 forks source link

[FEATURE] Add a "reset_to_default" switch to update_graphic #465

Open nww02 opened 2 years ago

nww02 commented 2 years ago

The way that update_graphic works is superb, however sometimes you want to just "refresh" the graphic on the screen without changing the background image.

The reason for this may be that something has changed in the room that on_render can use. For example, a player has 'picked up' an object, that would cause the overlay for that object to be removed from the scene. In this instance, all you want to do is to remove the overlay. tTo do this you would call "update_graphic" and then in on_refresh you might have some logic like:-

 on_refresh {
    :if (is_beside "treasure") { :overlay "treasure_chest";}
 }

This works LOVELY, {EXCEPT} when you want to have the background image be dynamic. Say, for example, you have a scene which changes between day and night, or, if during the game the scene changes to be different, say because the user has affected the surroundings. In this case, you currently need to set the new graphic as an override in on_describe because the switch isn't permanent, so you need to do it EVERY time you enter the room:-

 on_describe {
   :if (scene_changed) {
              :update_graphic "new_background";
   }

Again, this works PERFECTLY, UNTIL a user picks up or puts something down. You might have this:-

:match "get _" { :update_graphic; }

This would be a nice catch-all that ensures that the screen gets refreshed when you pick something up, BUT when you do that, the DEFAULT graphic is subbed-in and the background changes back to the default graphic. The only two ways to prevent this are to either call a full "redescribe" and force the room to call the on_describe, OR put the update_graphic into a function and then have a huge if_then_else in the match statement to call the appropriate room's update_graphic depending on where you are.

As a suggestion, how about having :update_graphic leave the graphic as it is currently set, only causing a redraw, so that the on_render can put the overlays back on based on its logic? However, to ensure that the current "reset to default" functionality is retained, add a switch to the update_graphic command to reset it back;

  # get just updates the graphic, with on_render removing any overlays
 :match  "get _" {
     :update_graphic;
}
  # this test command resets the image back to its default
:match "reset image" {
     :update_graphic reset_to_default="True";
 }
ainslec commented 2 years ago

The way in which Adventuron works is that when a location graphic is displayed, the on_render{} block is called.

You can interrogate if it is rendering a banner (location) graphic using the following function:

on_render {
   : if (is_rendering_banner()) {
      : if (is_at "barn") {
          : if (is_dark) {
            : overlay "dark_barn";
          }
      }
      : if (is_present "lamp") {
         : overlay "lamp";
      }
   }
}

If you are updating a lot of stateful information on a screen, then update boolean flags, then call : update_graphic, and have all your compositing done in on_render{}.

update_graphic (parameterless) does not update the default graphic to display in a location, it just re-renders the graphic using the default image and also executing the on_render {} logic.

I wonder if this explains the expected use of update_graphic, or if I'm missing something?

ainslec commented 2 years ago

Also, be aware of this command:

(sets a location to a new graphic and redraws).

: set_graphic graphic = "cave" immediate = "true" ;

(sets a location back to its default graphic and redraws)

: set_graphic immediate = "true" ;

nww02 commented 2 years ago

Hi there, Thanks for explaining. Yes, I was aware of the logic you described, and that's how I've worked around it.

The feature request was to prevent that reversion somehow to simplify the logic. I can, of course, overlay a whole new background image on top of the current image except that it prevents me using animated gifs.

Being able to request a "redraw" without the engine reverting the background graphic after it had been changed would be a helpful feature, that's all.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Chris Ainsley @.> Sent: Sunday, August 1, 2021 5:00:17 PM To: ainslec/adventuron-issue-tracker @.> Cc: nww02 @.>; Author @.> Subject: Re: [ainslec/adventuron-issue-tracker] [FEATURE] Add a "reset_to_default" switch to update_graphic (#465)

Also, be aware of this command:

(sets a location to a new graphic and redraws).

: set_graphic graphic = "cave" immediate = "true" ;

(sets a location back to its default graphic and redraws)

: set_graphic immediate = "true" ;

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ainslec/adventuron-issue-tracker/issues/465#issuecomment-890585599, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALFCUOO4PVAJW5JMZJRVDGTT2WYWDANCNFSM5BLFL4GQ.

ainslec commented 2 years ago

It wouldn't revert if you use set_graphic (updates and holds - when using immediate), it would only revert if you used update_graphic (updates in place).

You don't have to use overlays with set_graphic or update_graphic.