mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Merge pull request #18 from Danielv123/dev
MP desync issues fixed, prerealease 1
This commit is contained in:
commit
4f8ad5eec6
11 files changed
+235
-76
No files matched your search
@@ -96,7 +96,7 @@ setInterval(function() {
|
|||||||
// send our RCON command with whatever we got
|
// send our RCON command with whatever we got
|
||||||
client.exec("/c remote.call('clusterio', 'importMany', '" + sadas + "')");
|
client.exec("/c remote.call('clusterio', 'importMany', '" + sadas + "')");
|
||||||
}
|
}
|
||||||
}, 10000)
|
}, 3000)
|
||||||
/*
|
/*
|
||||||
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
fs.watch(config.factorioDirectory + "/script-output/orders.txt", "utf8", function(eventType, filename) {
|
||||||
|
|
||||||
|
|||||||
+96
-28
@@ -9,23 +9,40 @@ function OnBuiltEntity(event)
|
|||||||
local entity = event.created_entity
|
local entity = event.created_entity
|
||||||
--only add entities that are not ghosts
|
--only add entities that are not ghosts
|
||||||
if entity.type ~= "entity-ghost" then
|
if entity.type ~= "entity-ghost" then
|
||||||
if entity.name == INPUT_CHEST_NAME then
|
AddEntity(entity)
|
||||||
global.inputChests = global.inputChests or {}
|
end
|
||||||
--add the chests to a lists if these chests so they can be interated over
|
end
|
||||||
global.inputChests[HashPosition(entity.position)] = entity
|
|
||||||
elseif entity.name == OUTPUT_CHEST_NAME then
|
function AddAllEntitiesOfName(name)
|
||||||
global.outputChests = global.outputChests or {}
|
for k, surface in pairs(game.surfaces) do
|
||||||
--add the chests to a lists if these chests so they can be interated over
|
AddEntities(surface.find_entities_filtered({["name"] = name}))
|
||||||
global.outputChests[HashPosition(entity.position)] = entity
|
end
|
||||||
elseif entity.name == INPUT_TANK_NAME then
|
end
|
||||||
global.inputTanks = global.inputTanks or {}
|
|
||||||
--add the chests to a lists if these chests so they can be interated over
|
function AddEntities(entities)
|
||||||
global.inputTanks[HashPosition(entity.position)] = entity
|
for k, entity in pairs(entities) do
|
||||||
elseif entity.name == OUTPUT_TANK_NAME then
|
AddEntity(entity)
|
||||||
global.outputTanks = global.outputTanks or {}
|
end
|
||||||
--add the chests to a lists if these chests so they can be interated over
|
end
|
||||||
global.outputTanks[HashPosition(entity.position)] = entity
|
|
||||||
end
|
function AddEntity(entity)
|
||||||
|
if entity.name == INPUT_CHEST_NAME then
|
||||||
|
global.inputChests = global.inputChests or {}
|
||||||
|
--add the chests to a lists if these chests so they can be interated over
|
||||||
|
global.inputChests[HashPosition(entity.position)] = entity
|
||||||
|
elseif entity.name == OUTPUT_CHEST_NAME then
|
||||||
|
global.outputChests = global.outputChests or {}
|
||||||
|
--add the chests to a lists if these chests so they can be interated over
|
||||||
|
global.outputChests[HashPosition(entity.position)] = entity
|
||||||
|
elseif entity.name == INPUT_TANK_NAME then
|
||||||
|
global.inputTanks = global.inputTanks or {}
|
||||||
|
--add the chests to a lists if these chests so they can be interated over
|
||||||
|
global.inputTanks[HashPosition(entity.position)] = entity
|
||||||
|
elseif entity.name == OUTPUT_TANK_NAME then
|
||||||
|
global.outputTanks = global.outputTanks or {}
|
||||||
|
--add the chests to a lists if these chests so they can be interated over
|
||||||
|
global.outputTanks[HashPosition(entity.position)] = entity
|
||||||
|
entity.active = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -67,9 +84,8 @@ script.on_event(defines.events.on_preplayer_mined_item, function(event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
script.on_event(defines.events.on_tick, function(event)
|
script.on_event(defines.events.on_tick, function(event)
|
||||||
|
|
||||||
global.inputChests = global.inputChests or {}
|
global.inputChests = global.inputChests or {}
|
||||||
global.outputChests = global.outputChests or {}
|
global.outputChests = global.outputChests or {}
|
||||||
global.inputTanks = global.inputTanks or {}
|
global.inputTanks = global.inputTanks or {}
|
||||||
@@ -79,6 +95,13 @@ script.on_event(defines.events.on_tick, function(event)
|
|||||||
|
|
||||||
local todo = game.tick % UPATE_RATE
|
local todo = game.tick % UPATE_RATE
|
||||||
|
|
||||||
|
local onlinePlayers = GetOnlinePlayerCount()
|
||||||
|
|
||||||
|
if global.previousPlayerCount == nil or global.previousPlayerCount ~= onlinePlayers then
|
||||||
|
Reset()
|
||||||
|
end
|
||||||
|
global.previousPlayerCount = onlinePlayers
|
||||||
|
|
||||||
if todo == 0 then
|
if todo == 0 then
|
||||||
HandleInputChests()
|
HandleInputChests()
|
||||||
elseif todo == 1 then
|
elseif todo == 1 then
|
||||||
@@ -94,6 +117,33 @@ script.on_event(defines.events.on_tick, function(event)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
function GetOnlinePlayerCount()
|
||||||
|
local onlinePlayers = 0
|
||||||
|
for k, player in pairs(game.players) do
|
||||||
|
if player.connected then
|
||||||
|
onlinePlayers = onlinePlayers + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return onlinePlayers
|
||||||
|
end
|
||||||
|
|
||||||
|
function Reset()
|
||||||
|
global.outputList = {}
|
||||||
|
global.inputList = {}
|
||||||
|
global.itemStorage = {}
|
||||||
|
|
||||||
|
global.inputChests = {}
|
||||||
|
global.outputChests = {}
|
||||||
|
global.inputTanks = {}
|
||||||
|
global.outputTanks = {}
|
||||||
|
|
||||||
|
AddAllEntitiesOfName(INPUT_CHEST_NAME)
|
||||||
|
AddAllEntitiesOfName(OUTPUT_CHEST_NAME)
|
||||||
|
AddAllEntitiesOfName(INPUT_TANK_NAME)
|
||||||
|
AddAllEntitiesOfName(OUTPUT_TANK_NAME)
|
||||||
|
game.print("reset")
|
||||||
|
end
|
||||||
|
|
||||||
function HandleInputChests()
|
function HandleInputChests()
|
||||||
for k, v in pairs(global.inputChests) do
|
for k, v in pairs(global.inputChests) do
|
||||||
if v.valid then
|
if v.valid then
|
||||||
@@ -114,9 +164,7 @@ function HandleInputTanks()
|
|||||||
if v.valid then
|
if v.valid then
|
||||||
--get the content of the chest
|
--get the content of the chest
|
||||||
local fluid = v.fluidbox[1]
|
local fluid = v.fluidbox[1]
|
||||||
if fluid ~= nil and
|
if fluid ~= nil and math.floor(fluid.amount) > 0 then
|
||||||
fluid.type == "crude-oil" and
|
|
||||||
math.floor(fluid.amount) > 0 then
|
|
||||||
AddItemToInputList(fluid.type, math.floor(fluid.amount))
|
AddItemToInputList(fluid.type, math.floor(fluid.amount))
|
||||||
fluid.amount = fluid.amount - math.floor(fluid.amount)
|
fluid.amount = fluid.amount - math.floor(fluid.amount)
|
||||||
end
|
end
|
||||||
@@ -165,12 +213,23 @@ end
|
|||||||
function HandleOutputTanks()
|
function HandleOutputTanks()
|
||||||
local MAX_FLUID_AMOUNT = 1000
|
local MAX_FLUID_AMOUNT = 1000
|
||||||
for k,v in pairs(global.outputTanks) do
|
for k,v in pairs(global.outputTanks) do
|
||||||
local fluid = v.fluidbox[1] or {type = "crude-oil", amount = 0}
|
--.recipe.products[1].name
|
||||||
if fluid.type == "crude-oil" then
|
|
||||||
|
|
||||||
local missingFluid = math.ceil(MAX_FLUID_AMOUNT - fluid.amount)
|
if v.recipe ~= nil then
|
||||||
|
local fluidName = v.recipe.products[1].name
|
||||||
|
|
||||||
|
--either get the fluid or reset it to the requested fluid
|
||||||
|
local fluid = v.fluidbox[1] or {type = fluidName, amount = 0}
|
||||||
|
if fluid.type ~= fluidName then
|
||||||
|
fluid = {type = fluidName, amount = 0}
|
||||||
|
end
|
||||||
|
|
||||||
|
--if any fluid is missing then request the fluid
|
||||||
|
--from store and give either what it's missing or
|
||||||
|
--the rest of the liquid in the system
|
||||||
|
local missingFluid = math.max(math.ceil(MAX_FLUID_AMOUNT - fluid.amount), 0)
|
||||||
if missingFluid > 0 then
|
if missingFluid > 0 then
|
||||||
local fluidToInsert = RequestItemsFromStorage("crude-oil", missingFluid)
|
local fluidToInsert = RequestItemsFromStorage(fluidName, missingFluid)
|
||||||
if fluidToInsert > 0 then
|
if fluidToInsert > 0 then
|
||||||
fluid.amount = fluid.amount + fluidToInsert
|
fluid.amount = fluid.amount + fluidToInsert
|
||||||
else
|
else
|
||||||
@@ -178,8 +237,9 @@ function HandleOutputTanks()
|
|||||||
AddItemToOutputList(fluid.type, fluidToRequestAmount)
|
AddItemToOutputList(fluid.type, fluidToRequestAmount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
v.fluidbox[1] = fluid
|
||||||
end
|
end
|
||||||
v.fluidbox[1] = fluid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -264,7 +324,15 @@ remote.add_interface("clusterio",
|
|||||||
GiveItemsToStorage(itemName, itemCount)
|
GiveItemsToStorage(itemName, itemCount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
|
printStorage = function()
|
||||||
|
local items = ""
|
||||||
|
for itemName, itemCount in pairs(global.itemStorage) do
|
||||||
|
items = items.."\n"..itemName..": "..tostring(itemCount)
|
||||||
|
end
|
||||||
|
game.print(items)
|
||||||
|
end,
|
||||||
|
reset = Reset
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
|
|||||||
entity.icon = iconPath or entity.icon
|
entity.icon = iconPath or entity.icon
|
||||||
|
|
||||||
-- add the entity to a technology so it can be unlocked
|
-- add the entity to a technology so it can be unlocked
|
||||||
local wasAddedToTech = AddEntityToTech("construction-robotics", name)
|
--local wasAddedToTech = AddEntityToTech("construction-robotics", name)
|
||||||
|
|
||||||
data:extend(
|
data:extend(
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
|
|||||||
--shouldn't be enabled to begin with.
|
--shouldn't be enabled to begin with.
|
||||||
--but if the recipe isn't attached to a tech then it should
|
--but if the recipe isn't attached to a tech then it should
|
||||||
--be enabled to begin with because otherwise the player can never use the item ingame
|
--be enabled to begin with because otherwise the player can never use the item ingame
|
||||||
enabled = not wasAddedToTech,
|
enabled = true,
|
||||||
ingredients =
|
ingredients =
|
||||||
{
|
{
|
||||||
{"steel-chest", 1},
|
{"steel-chest", 1},
|
||||||
@@ -55,6 +55,7 @@ function MakeLogisticEntity(entity, name, pictureFilename, pictureTablePath, ico
|
|||||||
stack_size = 50
|
stack_size = 50
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return entity
|
||||||
end
|
end
|
||||||
|
|
||||||
--adds a recipe to a tech and returns true or if that fails returns false
|
--adds a recipe to a tech and returns true or if that fails returns false
|
||||||
@@ -83,7 +84,6 @@ MakeLogisticEntity(table.deepcopy(data.raw["logistic-container"]["logistic-chest
|
|||||||
MakeLogisticEntity(table.deepcopy(data.raw["container"]["iron-chest"]), INPUT_CHEST_NAME, INPUT_CHEST_PICTURE_PATH, { "picture" }, INPUT_CHEST_ICON_PATH)
|
MakeLogisticEntity(table.deepcopy(data.raw["container"]["iron-chest"]), INPUT_CHEST_NAME, INPUT_CHEST_PICTURE_PATH, { "picture" }, INPUT_CHEST_ICON_PATH)
|
||||||
|
|
||||||
--make tanks
|
--make tanks
|
||||||
MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), OUTPUT_TANK_NAME, OUTPUT_TANK_PICTURE_PATH, { "pictures", "picture", "sheet" }, OUTPUT_TANK_ICON_PATH)
|
|
||||||
MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), INPUT_TANK_NAME, INPUT_TANK_PICTURE_PATH, { "pictures", "picture", "sheet" }, INPUT_TANK_ICON_PATH)
|
MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), INPUT_TANK_NAME, INPUT_TANK_PICTURE_PATH, { "pictures", "picture", "sheet" }, INPUT_TANK_ICON_PATH)
|
||||||
|
|
||||||
|
|
||||||
@@ -92,6 +92,73 @@ MakeLogisticEntity(table.deepcopy(data.raw["storage-tank"]["storage-tank"]), IN
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
--[[This section is purely to create the output tank]]--
|
||||||
|
--------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local CRAFING_FLUID_CATEGORY_NAME = "crafting-fluids"
|
||||||
|
|
||||||
|
data:extend(
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "recipe-category",
|
||||||
|
name = CRAFING_FLUID_CATEGORY_NAME
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
local fluidCreator = MakeLogisticEntity(table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"]), OUTPUT_TANK_NAME, OUTPUT_TANK_PICTURE_PATH, { "animation" }, OUTPUT_TANK_ICON_PATH)
|
||||||
|
fluidCreator.fluid_boxes =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
production_type = "output",
|
||||||
|
pipe_picture = assembler3pipepictures(),
|
||||||
|
pipe_covers = pipecoverspictures(),
|
||||||
|
base_area = 250,
|
||||||
|
base_level = 1,
|
||||||
|
pipe_connections =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type="output", position = {0, 2}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
off_when_no_fluid_recipe = false
|
||||||
|
}
|
||||||
|
fluidCreator.crafting_categories = {CRAFING_FLUID_CATEGORY_NAME}
|
||||||
|
fluidCreator.energy_usage = "1kW"
|
||||||
|
fluidCreator.ingredient_count = 1
|
||||||
|
fluidCreator.module_specification.module_slots = 0
|
||||||
|
|
||||||
|
for k,v in pairs(data.raw.fluid) do
|
||||||
|
data:extend(
|
||||||
|
{
|
||||||
|
{
|
||||||
|
type = "recipe",
|
||||||
|
name = v.name,
|
||||||
|
icon = v.icon,
|
||||||
|
category = CRAFING_FLUID_CATEGORY_NAME,
|
||||||
|
energy_required = 1,
|
||||||
|
subgroup = "barrel",
|
||||||
|
order = "b[fill-crude-oil-barrel]",
|
||||||
|
enabled = true,
|
||||||
|
ingredients = {},
|
||||||
|
results=
|
||||||
|
{
|
||||||
|
{type="fluid", name=v.name, amount=-1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
@@ -6,6 +6,6 @@
|
|||||||
"date": "19-08-2016",
|
"date": "19-08-2016",
|
||||||
"author": "Danielv123 & Keyboardhack",
|
"author": "Danielv123 & Keyboardhack",
|
||||||
"dependencies": ["base >= 0.13"],
|
"dependencies": ["base >= 0.13"],
|
||||||
"factorio_version": "0.13",
|
"factorio_version": "0.14",
|
||||||
"description": "Adds 2 chests to transfer items between saves and servers over the internet."
|
"description": "Adds 2 chests to transfer items between saves and servers over the internet."
|
||||||
}
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
@echo off
|
|
||||||
@cls
|
|
||||||
|
|
||||||
@set /p host="Enter host (default: "127.0.0.1"): "
|
|
||||||
@if "%host%"=="" set host=127.0.0.1
|
|
||||||
|
|
||||||
@set /p port="Enter port (default: 25575): "
|
|
||||||
@if "%port%"=="" set port=25575
|
|
||||||
|
|
||||||
@set /p passwd="Enter password: "
|
|
||||||
@if "%passwd%"=="" set passwd=
|
|
||||||
|
|
||||||
set name=connect_%host%-%port%
|
|
||||||
|
|
||||||
@set /p name="Enter shortcut name (default: "%name%.bat"): "
|
|
||||||
@if "%name%"=="" set name=connect_%host%-%port%
|
|
||||||
|
|
||||||
set command=@mcrcon.exe -t -H %host% -P %port% -p %passwd%
|
|
||||||
|
|
||||||
@echo %command% >> %name%.bat
|
|
||||||
@echo.
|
|
||||||
@echo Command: "%command%"
|
|
||||||
@echo.
|
|
||||||
@echo Shortcut "%name%.bat" created!
|
|
||||||
@echo.
|
|
||||||
|
|
||||||
@set "host="
|
|
||||||
@set "port="
|
|
||||||
@set "passwd="
|
|
||||||
|
|
||||||
@pause
|
|
||||||
@@ -2,14 +2,4 @@ cd "Factorio_0.13.17"
|
|||||||
@RD /S /Q "temp"
|
@RD /S /Q "temp"
|
||||||
cd "bin/x64/"
|
cd "bin/x64/"
|
||||||
start factorio.exe --start-server testmap.zip --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json
|
start factorio.exe --start-server testmap.zip --rcon-port 12345 --rcon-password 123 --server-settings server-settings.json
|
||||||
cd ..
|
|
||||||
cd ..
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
::start cmd /C node client.js
|
|
||||||
::start cmd /C node master.js
|
|
||||||
|
|
||||||
::cd "Factorio 0.13.9 - Copy/bin/x64"
|
|
||||||
::@start factorio.exe
|
|
||||||
|
|
||||||
pause
|
pause
|
||||||
@@ -93,6 +93,13 @@ app.get("/inventory", function(req, res) {
|
|||||||
res.send(docs);
|
res.send(docs);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// endpoint for getting the chartjs library
|
||||||
|
app.get("/chart.js", function(req, res) {
|
||||||
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
// Check it and send it
|
||||||
|
res.end(fs.readFileSync("node_modules/chartjs/chart.js"));
|
||||||
|
});
|
||||||
|
|
||||||
var server = app.listen(config.masterPort || 8080, function () {
|
var server = app.listen(config.masterPort || 8080, function () {
|
||||||
console.log("Listening on port %s...", server.address().port);
|
console.log("Listening on port %s...", server.address().port);
|
||||||
|
|||||||
+9
-1
@@ -1,7 +1,8 @@
|
|||||||
<doctype HTML>
|
<!doctype HTML>
|
||||||
<head>
|
<head>
|
||||||
<title>Clusterio</title>
|
<title>Clusterio</title>
|
||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/0.2.0/Chart.min.js" type="text/javascript"></script>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -25,6 +26,13 @@
|
|||||||
<h2>Storage</h2>
|
<h2>Storage</h2>
|
||||||
<div id="contents">
|
<div id="contents">
|
||||||
</div>
|
</div>
|
||||||
|
<canvas id="contentGraph" width="200" height="200"></canvas>
|
||||||
|
</div>
|
||||||
|
<div id="production">
|
||||||
|
<h2>Production</h2>
|
||||||
|
<div id="legend">
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
+45
-1
@@ -1,10 +1,25 @@
|
|||||||
|
|
||||||
|
|
||||||
contents = {
|
contents = {
|
||||||
"iron-plate":100,
|
"iron-plate":100,
|
||||||
"copper-plate":7312,
|
"copper-plate":7312,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function djb2(str){
|
||||||
|
var hash = 5381;
|
||||||
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
hash = ((hash << 5) + hash) + str.charCodeAt(i); /* hash * 33 + c */
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hashColor(str) {
|
||||||
|
var hash = djb2(str);
|
||||||
|
var r = (hash & 0xFF0000) >> 16;
|
||||||
|
var g = (hash & 0x00FF00) >> 8;
|
||||||
|
var b = hash & 0x0000FF;
|
||||||
|
return "#" + ("0" + r.toString(16)).substr(-2) + ("0" + g.toString(16)).substr(-2) + ("0" + b.toString(16)).substr(-2);
|
||||||
|
}
|
||||||
|
|
||||||
function drawcontents(data) {
|
function drawcontents(data) {
|
||||||
keys = Object.keys(data);
|
keys = Object.keys(data);
|
||||||
result = "<table>";
|
result = "<table>";
|
||||||
@@ -14,14 +29,43 @@ function drawcontents(data) {
|
|||||||
result = result + "</table>"
|
result = result + "</table>"
|
||||||
document.getElementById("contents").innerHTML = result;
|
document.getElementById("contents").innerHTML = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
xmlhttp.onreadystatechange = function() {
|
xmlhttp.onreadystatechange = function() {
|
||||||
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
data = JSON.parse(xmlhttp.responseText);
|
data = JSON.parse(xmlhttp.responseText);
|
||||||
drawcontents(data);
|
drawcontents(data);
|
||||||
|
// render our piechart with up to date information
|
||||||
|
piedata = [];
|
||||||
|
for(i=0;i<data.length;i++) {
|
||||||
|
piedata[piedata.length] = {
|
||||||
|
value: Number(data[i].count),
|
||||||
|
color: hashColor(data[i].name),
|
||||||
|
label: data[i].name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PieChart.Pie(piedata, {
|
||||||
|
animation: false,
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
labels: {
|
||||||
|
fontColor: 'rgb(255, 99, 132)'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hover: {
|
||||||
|
mode: "label",
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlhttp.open("GET", "inventory", true);
|
xmlhttp.open("GET", "inventory", true);
|
||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
|
// create chart of items in master storage
|
||||||
|
// setTimeout is used to put this processing in the back of the queue, after the HTML canvas is done
|
||||||
|
setTimeout(function(){
|
||||||
|
ctx = document.querySelector("#contentGraph").getContext('2d');
|
||||||
|
PieChart = new Chart(ctx);
|
||||||
|
},10)
|
||||||
@@ -16,9 +16,15 @@
|
|||||||
#body {
|
#body {
|
||||||
margin-left:200px;
|
margin-left:200px;
|
||||||
}
|
}
|
||||||
|
#contents {
|
||||||
|
width:300px;
|
||||||
|
}
|
||||||
#contents table {
|
#contents table {
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
}
|
}
|
||||||
|
#contentGraph {
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
.button-black {
|
.button-black {
|
||||||
width:100%;
|
width:100%;
|
||||||
height:40px;
|
height:40px;
|
||||||
|
|||||||
Reference in new issue
Block a user