Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.19 KB | None | 0 0
  1. module IMP_ReadWrite_Excel
  2.  
  3.   Perform = true
  4.  
  5. end
  6.  
  7. class Scene_Title
  8.  
  9.   alias impexcel_start start unless $@
  10.   def start
  11.     if $TEST && IMP_ReadWrite_Excel::Perform
  12.       $scene = Scene_ReadWrite_Excel.new
  13.     else
  14.       impexcel_start
  15.     end
  16.   end
  17.  
  18.   alias impexcel_terminate terminate unless $@
  19.   def terminate
  20.     impexcel_teminate if !($TEST && IMP_ReadWrite_Excel::Perform)
  21.   end
  22.  
  23. end
  24.  
  25. class Scene_ReadWrite_Excel < Scene_Base
  26.  
  27.   def start
  28.     @window = Window_Base.new(0, 0, Graphics.width/2, Graphics.Height)
  29.     text = "Do you want to read data or write data?"
  30.     width = @window.contents.width
  31.     @window.contents.draw_text(0, 0, width, Window_Base::WLH, text, 1)
  32.     @choice = Window_Command.new(128, ["Read","Write"])
  33.     @choice.x = Graphics.width / 2
  34.     @choice.y = Window_Base::WLH + 32
  35.     @choice.active = true
  36.     text = "If you're writing data, don't forget the .rb file needs to be on your desktop."
  37.     y = Graphics.height - Window_Base::WLH
  38.     @window.contents.draw_text(0, y, width, Window_Base::WLH, text, 1)
  39.   end
  40.  
  41.   def update
  42.     @choice.update if @choice.active
  43.     update_input
  44.   end
  45.  
  46.   def update_input
  47.     if Input.trigger?(Input::B)
  48.       Sound.play_buzzer
  49.     end
  50.     if Input.trigger?(Input::C)
  51.       case @choice.index
  52.       when 0; read_processing
  53.       when 1; write_processing
  54.       end
  55.       @choice.active = false
  56.       @choice.visible = false
  57.     end
  58.   end
  59.  
  60.   def write_processing
  61.     file = File.new("C:\\Users\\Public\\Desktop\\" + RPG::System.game_title, "w+")
  62.     Marshal.dump($data_items, file)
  63.     file.close
  64.     @window.contents.clear
  65.     text = "Done."
  66.     width = @window.contents.width
  67.     @window.contents.draw_text(0, 0, width, Window_Base::WLH, text, 1)
  68.   end
  69.  
  70.   def read_processing
  71.     file = File.open("C:\\Users\\Public\\Desktop\\" + RPG::System.game_title, "w+")
  72.     data_items = Marshal.load(file)
  73.     save_data(data_items, "Data/Actors.rvdata")
  74.     file.close
  75.     @window.contents.clear
  76.     text = "Done."
  77.     width = @window.contents.width
  78.     @window.contents.draw_text(0, 0, width, Window_Base::WLH, text, 1)
  79.   end
  80.  
  81.   def terminate
  82.     @choice.dispose
  83.     @window.dispose
  84.   end
  85.  
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement