From ff8d6f7b9c1e0a05cbef0758e0458b04315a90f6 Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Sun, 21 Apr 2019 16:22:37 -0400
Subject: [PATCH] Allow for saving and loading of layout.

---
 lib/aethyr/core/components/storage.rb |  1 +
 lib/aethyr/core/connection/login.rb   |  3 ++-
 lib/aethyr/core/objects/player.rb     |  5 ++++-
 lib/aethyr/core/render/display.rb     | 21 ++++++++++++++++++---
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/aethyr/core/components/storage.rb b/lib/aethyr/core/components/storage.rb
index d7dc82b..50c2833 100644
--- a/lib/aethyr/core/components/storage.rb
+++ b/lib/aethyr/core/components/storage.rb
@@ -66,6 +66,7 @@ class StorageMachine
     #Yeah, so whatever on this little deal. Probably should do it better later.
     player.use_color = player.io.display.use_color if player.io
     player.color_settings = player.io.display.color_settings if player.io
+    player.layout = player.io.display.layout_type if player.io
 
     #Okay, this is tricky. We can't serialize the IO object stored in the Player
     #objects. To get around this (we don't want to store it anyhow), we temporarily
diff --git a/lib/aethyr/core/connection/login.rb b/lib/aethyr/core/connection/login.rb
index 8db2ca2..8f7059a 100644
--- a/lib/aethyr/core/connection/login.rb
+++ b/lib/aethyr/core/connection/login.rb
@@ -160,7 +160,8 @@ module Login
     end
 
 
-    @display.color_settings = player.color_settings if not player.color_settings.nil?
+    @display.color_settings = player.color_settings unless player.color_settings.nil?
+    @display.layout(layout: player.layout, in_combat: player.info.in_combat) unless player.layout.nil?
 
     @word_wrap = player.word_wrap
     player.instance_variable_set(:@player, self)
diff --git a/lib/aethyr/core/objects/player.rb b/lib/aethyr/core/objects/player.rb
index 3c5aa37..b36f971 100644
--- a/lib/aethyr/core/objects/player.rb
+++ b/lib/aethyr/core/objects/player.rb
@@ -41,7 +41,7 @@ class Player < LivingObject
   }
 
   attr_reader :admin, :color_settings
-  attr_accessor :use_color, :reply_to, :page_height
+  attr_accessor :use_color, :reply_to, :page_height, :layout
 
   #Create a new player object with the given socket connection. You must also pass in a game_object_id and a room, although if you pass in nil for game_object_id it will auto-generate one for you.
   def initialize(connection, game_object_id, room, *args)
@@ -58,6 +58,9 @@ class Player < LivingObject
     @blind = false
     @reply_to = nil
     @prompt_shown = false
+    @layout = :basic
+    @player.display.layout(layout: @layout, in_combat: info.in_combat)
+
     info.stats.satiety = 120
     map_skill = Aethyr::Extensions::Skills::Map.new(self.game_object_id)
     kick_skill = Aethyr::Extensions::Skills::Kick.new(self.game_object_id)
diff --git a/lib/aethyr/core/render/display.rb b/lib/aethyr/core/render/display.rb
index 407a6d8..127cdb6 100644
--- a/lib/aethyr/core/render/display.rb
+++ b/lib/aethyr/core/render/display.rb
@@ -6,6 +6,7 @@ require 'aethyr/core/components/manager'
 require 'aethyr/core/render/window'
 
 class Display
+  attr_reader :layout_type
   attr_accessor :color_settings, :use_color
 
   DEFAULT_HEIGHT = 43
@@ -79,15 +80,30 @@ class Display
     end
   end
 
-  def layout(in_fight: false)
+  def layout(layout: @layout_type, in_combat: false)
+    @layout_type = layout
     if @layout_type == :full && @height > 100 && @width > 165
-      unless in_fight
+      unless in_combat
+        @windows[:fight_enemy].destroy
+        @windows[:fight_team].destroy
+        @windows[:fight_queue].destroy
         @windows[:map].create(height: @height/2)
         @windows[:look].create(height: @height/2 - 3, width: 83, y: @height/2)
         @windows[:main].create(height: @height/2 - 3, x: 83, y: @height/2)
         @windows[:input].create(height: 3, y: @height - 3)
+      else
+        @windows[:map].destroy
+        @windows[:look].destroy
+        @windows[:fight_enemy].create(height: @height/3 - 1, width: @width - 83)
+        @windows[:fight_team].create(height: @height/3 - 1, width: @width - 83, y: @height/3)
+        @windows[:fight_queue].create(height: @height - 3, width: 83, x: @width - 83)
+        @windows[:main].create(height: @height/3 - 1, width: @width - 83, y: @height/2)
+        @windows[:input].create(height: 3, y: @height - 3)
       end
     else
+      @windows[:fight_enemy].destroy
+      @windows[:fight_team].destroy
+      @windows[:fight_queue].destroy
       @windows[:map].destroy
       @windows[:look].destroy
       @windows[:main].create(height: @height - 2)
@@ -106,7 +122,6 @@ class Display
     @width = resolution[0]
     @height = resolution[1]
     Ncurses.resizeterm(@height, @width)
-    @layout_type = :full
     layout
   end
 
-- 
GitLab