Class: CPEE::Frames::NewFrameSet
- Inherits:
-
Riddl::Implementation
- Object
- Riddl::Implementation
- CPEE::Frames::NewFrameSet
- Defined in:
- lib/cpee-frames/implementation.rb
Overview
}}}
Instance Method Summary collapse
Instance Method Details
#response ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cpee-frames/implementation.rb', line 98 def response data_dir = @a[1] path = File.join(data_dir,@r.last,'frames.json') file = File.read(path) data_hash = JSON::parse(file) #check if new frame overlaps others if it does, delete overlapped frames data_hash["data"].each do | c | if CPEE::Frames::overlap?(c['lx'], c['ly'], c['rx'], c['ry'], @p[1].value.to_i, @p[2].value.to_i, (@p[1].value.to_i + @p[3].value.to_i - 1), (@p[2].value.to_i + @p[4].value.to_i - 1)) data_hash["data"].delete(c) end end #check if url is set if @p[7].value != "" urls = JSON::parse(@p[7].value); if @p[8].value == "" hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']}; else hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: JSON::parse(@p[8].value), callback: @h['CPEE_CALLBACK']}; end data_hash["data"].push(hash) File.write(path, JSON.dump(data_hash)) #only send active url to client infofile = File.join(data_dir,@r.last,'info.json') infojson = JSON::parse(File.read(infofile)) hash["url"] = urls.find{ |h| h['lang'] == infojson["lang"]}['url'] @a[0].send(JSON.dump(hash)) else File.write(path, JSON.dump(data_hash)) hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: "empty", showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']}; @a[0].send(JSON.dump(hash)) end nil end |