<commit_before>--MapView.lua
local class = require 'lib/30log'
local statemachine = require('lib/statemachine')

local Interfaceable = require 'src/component/Interfaceable'
local Renderable = require 'src/component/Renderable'
local Transform = require 'src/component/Transform'
local TouchDelegate = require 'src/datatype/TouchDelegate'
local GameObject = require 'src/GameObject'
local Polygon = require 'src/datatype/Polygon'
local MainMenuView = require 'src/ui/MainMenuView'
local QuickCommandPanelView = require 'src/ui/QuickCommandPanelView'
local ConfirmationDialogBoxView = require 'src/ui/ConfirmationDialogBoxView'
local TurnStartView = require 'src/ui/TurnStartView'
local CityInspectorView = require 'src/ui/CityInspectorView'
local ArmyInspectorView = require 'src/ui/ArmyInspectorView'

local MapView = class("MapView", {

})

function MapView:init( registry, scenegraph, tiles, cities, units )

  self.registry = registry
  self.scenegraph = scenegraph

  local Map_Layer = registry:add(GameObject:new('Map Layer', {
    Transform:new()
    }))
  local Tile_Layer = registry:add(GameObject:new('Tile_Layer',{}))
  local City_Layer = registry:add(GameObject:new('City_Layer',{}))
  local Unit_Layer = registry:add(GameObject:new('Unit_Layer',{}))
  local UI_Layer = registry:add(GameObject:new('UI_Layer',{}))
  local Turn_Start_View = TurnStartView:new(registry, scenegraph)
  local Main_Menu_View = MainMenuView:new(registry, scenegraph)
  local Quick_Command_Panel_View = QuickCommandPanelView:new(registry, scenegraph)
  local Confirmation_Dialog_Box_View = ConfirmationDialogBoxView:new(registry, scenegraph)
  local City_Inspector_View = CityInspectorView:new(registry, scenegraph)
  local Army_Inspector_View = ArmyInspectorView:new(registry, scenegraph)

  local Inspector = registry:add(GameObject:new('Inspector',{
    Transform:new(0,675),
    Renderable:new(
      Polygon:new({w=1200, h=125}),
      nil,
      {50,100,100,125},
      "Inspector Panel (has some commands, cursor information, minimap, etc). Press Escape to bring up the Main Menu")
    }))

  local Map_View_Touch_Delegate = TouchDelegate:new()
  Map_View_Touch_Delegate:setHandler('onDrag', function(this, x,y,dx,dy)
    if not Main_Menu_View.is_attached and registry:get(Map_Layer):hasComponent('Transform') then
      local t = registry:get(Map_Layer):getComponent('Transform')
      t:translate(dx,dy)
    end
  end)
  Map_View_Touch_Delegate:setHandler('onKeypress', function(this, btn)
    print('key pressed on map view: ' .. btn .. ' while showing_main_menu == ' .. tostring(Main_Menu_View.is_attached))
    if btn == 'escape' then
      if Main_Menu_View.is_attached then
        Main_Menu_View:hide()
      else
        Main_Menu_View:show(UI_Layer)
      end
    end
  end)
  local Map_View = registry:add(GameObject:new('Map_View',{
    Transform:new(0,0),
    Interfaceable:new(
      Polygon:new({w=1200, h=800}),
      Map_View_Touch_Delegate)
    }))

  scenegraph:attach(Map_View)
  scenegraph:attachAll({Map_Layer,UI_Layer}, Map_View)
  scenegraph:attachAll({Tile_Layer,City_Layer,Unit_Layer,UI_Layer}, Map_Layer)
  scenegraph:attachAll(tiles, Tile_Layer)
  scenegraph:attachAll(cities, City_Layer)
  scenegraph:attachAll(units, Unit_Layer)
  scenegraph:attachAll({Inspector},UI_Layer)
  scenegraph:attachAll({Quick_Command_Panel_View.root},Inspector)
  for i, tile in ipairs(tiles) do
    scenegraph:attach(tile.root, Tile_Layer)
  end
  for i, city in ipairs(cities) do
    scenegraph:attach(city.root, City_Layer)
  end
  for i, unit in ipairs(units) do
    scenegraph:attach(unit.root, Unit_Layer)
  end

  scenegraph:setRoot(Map_View)

  registry:subscribe("selectCity", function(this, msg)
    if msg.icon_type == 'city' then
      print('Show city inspector for ' .. inspect(msg.address.address))<commit_msg>fix parenting<commit_after>--MapView.lua
local class = require 'lib/30log'
local statemachine = require('lib/statemachine')

local Interfaceable = require 'src/component/Interfaceable'
local Renderable = require 'src/component/Renderable'
local Transform = require 'src/component/Transform'
local TouchDelegate = require 'src/datatype/TouchDelegate'
local GameObject = require 'src/GameObject'
local Polygon = require 'src/datatype/Polygon'
local MainMenuView = require 'src/ui/MainMenuView'
local QuickCommandPanelView = require 'src/ui/QuickCommandPanelView'
local ConfirmationDialogBoxView = require 'src/ui/ConfirmationDialogBoxView'
local TurnStartView = require 'src/ui/TurnStartView'
local CityInspectorView = require 'src/ui/CityInspectorView'
local ArmyInspectorView = require 'src/ui/ArmyInspectorView'

local MapView = class("MapView", {

})

function MapView:init( registry, scenegraph, tiles, cities, units )

  self.registry = registry
  self.scenegraph = scenegraph

  local Map_Layer = registry:add(GameObject:new('Map Layer', {
    Transform:new()
    }))
  local Tile_Layer = registry:add(GameObject:new('Tile_Layer',{}))
  local City_Layer = registry:add(GameObject:new('City_Layer',{}))
  local Unit_Layer = registry:add(GameObject:new('Unit_Layer',{}))
  local UI_Layer = registry:add(GameObject:new('UI_Layer',{}))
  local Turn_Start_View = TurnStartView:new(registry, scenegraph)
  local Main_Menu_View = MainMenuView:new(registry, scenegraph)
  local Quick_Command_Panel_View = QuickCommandPanelView:new(registry, scenegraph)
  local Confirmation_Dialog_Box_View = ConfirmationDialogBoxView:new(registry, scenegraph)
  local City_Inspector_View = CityInspectorView:new(registry, scenegraph)
  local Army_Inspector_View = ArmyInspectorView:new(registry, scenegraph)

  local Inspector = registry:add(GameObject:new('Inspector',{
    Transform:new(0,675),
    Renderable:new(
      Polygon:new({w=1200, h=125}),
      nil,
      {50,100,100,125},
      "Inspector Panel (has some commands, cursor information, minimap, etc). Press Escape to bring up the Main Menu")
    }))

  local Map_View_Touch_Delegate = TouchDelegate:new()
  Map_View_Touch_Delegate:setHandler('onDrag', function(this, x,y,dx,dy)
    if not Main_Menu_View.is_attached and registry:get(Map_Layer):hasComponent('Transform') then
      local t = registry:get(Map_Layer):getComponent('Transform')
      t:translate(dx,dy)
    end
  end)
  Map_View_Touch_Delegate:setHandler('onKeypress', function(this, btn)
    print('key pressed on map view: ' .. btn .. ' while showing_main_menu == ' .. tostring(Main_Menu_View.is_attached))
    if btn == 'escape' then
      if Main_Menu_View.is_attached then
        Main_Menu_View:hide()
      else
        Main_Menu_View:show(UI_Layer)
      end
    end
  end)
  local Map_View = registry:add(GameObject:new('Map_View',{
    Transform:new(0,0),
    Interfaceable:new(
      Polygon:new({w=1200, h=800}),
      Map_View_Touch_Delegate)
    }))

  scenegraph:attach(Map_View)
  scenegraph:attachAll({Map_Layer,UI_Layer}, Map_View)
  scenegraph:attachAll({Tile_Layer,City_Layer,Unit_Layer}, Map_Layer)
  scenegraph:attachAll({Inspector},UI_Layer)
  scenegraph:attachAll({Quick_Command_Panel_View.root},Inspector)

  for i, tile in ipairs(tiles) do
    scenegraph:attach(tile.root, Tile_Layer)
  end
  for i, city in ipairs(cities) do
    scenegraph:attach(city.root, City_Layer)
  end
  for i, unit in ipairs(units) do
    scenegraph:attach(unit.root, Unit_Layer)
  end

  scenegraph:setRoot(Map_View)

  registry:subscribe("selectCity", function(this, msg)
    if msg.icon_type == 'city' then
      print('Show city inspector for ' .. inspect(msg.address.address))
{'fraction_non_alphanumeric': 0.11264795850512037, 'fraction_numerical': 0.008777763000398989, 'mean_word_length': 5.556233653007847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7615799', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2450, 'n_words': 476}