Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('chat')
- require('lists')
- require('sets')
- require('tables')
- require('strings')
- local json = require('json')
- local file = require('files')
- local slips = require('slips')
- local res = require('resources')
- local texts = require('texts')
- local relative_depth_to_addons_findAll = '../../..'
- local storages_path = relative_depth_to_addons_findAll..'/addons/findAll/data/storages.json'
- local items_to_chars_path = relative_depth_to_addons_findAll..'/addons/findAll/data/items_to_chars.json'
- local storages_file = file.new(storages_path)
- if not storages_file:exists() then
- windower.add_to_chat( 8, "Unable to find storages path: "..storages_path )
- return false
- else
- windower.add_to_chat( 8, "Found storages path: "..storages_path )
- end
- local global_storages = json.read( storages_file )
- if global_storages == nil then
- windower.add_to_chat(8, "Unable to load json file" )
- return false
- end
- local item_to_char_storage_table = T{}
- for character_name, storages in pairs(global_storages) do
- for storage_name, storage_list in pairs(storages) do
- if ( storage_name ~= 'gil' ) then
- for item_id, item_quantity in pairs(storage_list) do
- if item_to_char_storage_table[item_id] == nil then
- item_to_char_storage_table[item_id] = T{}
- item_to_char_storage_table[item_id][character_name] = T{}
- item_to_char_storage_table[item_id][character_name][storage_name] = item_quantity
- else
- if item_to_char_storage_table[item_id][character_name] == nil then
- item_to_char_storage_table[item_id][character_name] = T{}
- item_to_char_storage_table[item_id][character_name][storage_name] = item_quantity
- else
- if item_to_char_storage_table[item_id][character_name][storage_name] == nil then
- item_to_char_storage_table[item_id][character_name][storage_name] = item_quantity
- else
- item_to_char_storage_table[item_id][character_name][storage_name] = item_quantity + item_to_char_storage_table[item_id][character_name][storage_name]
- end
- end
- end
- end
- end
- end
- end
- local items_to_chars_json = L{}
- for item_id, character_storage_tables in pairs(item_to_char_storage_table) do
- -- magic +0 to convert string to number, for indexing res.items
- local resource_item = res.items[ item_id + 0 ]
- local characters_json = L{}
- for character, storage_tables in pairs( character_storage_tables ) do
- local storages_json = L{}
- for storage, quantity in pairs( storage_tables ) do
- storages_json:append('"'..storage..'":'..quantity)
- end
- characters_json:append('"'..character..'":{'..storages_json:concat(',')..'}')
- end
- items_to_chars_json:append('"'..resource_item['en']..'":{'..characters_json:concat(',')..'}')
- end
- local new_data_file = file.new( items_to_chars_path )
- if not new_data_file:exists() then
- new_data_file:create()
- end
- new_data_file:write('{'..items_to_chars_json:concat(',\n')..'}')
- return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement