Skip to content

Commit

Permalink
Version: 1.3.4
Browse files Browse the repository at this point in the history
  Features:
    - Add DISK API: functions for file manipulation
    - Add speaker.print API (Print your message to the ingame chat log)
  Bugfixes:
    - Fixed os.require API
  • Loading branch information
Relik77 committed Mar 20, 2018
1 parent e093fa5 commit 6aeb5bb
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 96 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ An API (Application Programming Interface) is a collection of code that, rather
- `os API` : The Operating System API allows for interfacing with the Lua based Operating System itself.
Exemple: `os.wait(callback, seconds)` wait a number of seconds before executing callback function.
- `term API` : The Terminal API provides functions for writing text to the terminal. Exemple: `term.write(text)` writes text to the screen
- `disk API` : The DISK API provides functions for file manipulation
- `lan API` : The LAN API provides functions to communicate using circuit network
- `wlan API` : The WLAN API provides functions to communicate using wirless network
- `speaker API` : The Speaker API makes it possible to issue map alerts

More information available with `help os` and `help term`.
More information available with `help {api name}`

Official *computer* mods
------------------------
Expand Down
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
---------------------------------------------------------------------------------------------------
Version: 1.3.4
Date: 20. 03. 2018
Features:
- Add DISK API: functions for file manipulation
- Add speaker.print API (Print your message to the ingame chat log)
Bugfixes:
- Fixed os.require API
---------------------------------------------------------------------------------------------------
Version: 1.3.3
Date: 15. 03. 2018
Bugfixes:
Expand Down
19 changes: 19 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require("logic.apis.os")
require("logic.apis.lan")
require("logic.apis.wlan")
require("logic.apis.speaker")
require("logic.apis.disk")

baseEnv = {
ipairs = ipairs,
Expand Down Expand Up @@ -496,6 +497,24 @@ end)

script.on_event(defines.events.on_tick, OnTick)
script.on_configuration_changed(OnConfigurationChanged)
script.on_load(function()
if not global.computers then
return
end

for index, data in pairs(global.computers) do
if data.process ~= nil then
local item = computer.load(data)
local env = item.data.env

for index, api in pairs(computer.apis) do
if env.apis[api.name] and not type(getmetatable(env.apis[api.name])) ~= "string" then
item:loadAPI(api, env.apis[api.name], env.proxies[api.name], env)
end
end
end
end
end)

script.on_event(defines.events.on_gui_click, OnGuiClick)
script.on_event(defines.events.on_gui_text_changed, OnGuiTextChanged)
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "computer_core",
"version": "1.3.3",
"version": "1.3.4",
"title": "Computer Core",
"author": "Relik",
"contact": "",
Expand Down
48 changes: 48 additions & 0 deletions logic/apis/disk.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require("logic.computer")

table.insert(computer.apis,{
name = "disk",
description = "The DISK API provides functions for file manipulation",
entities = nil,
prototype = {
-- Public methods
readFile = {
"disk.readFile(filepath) - Writes the value of each of its arguments to the file.",
function(self, filepath)
return self.__readFile(filepath)
end
},
writeFile = {
"disk.writeFile(filepath, ...) - Truncate the file and write the value of each of its arguments.",
function(self, filepath, ...)
return self.__writeFile(filepath, ...)
end
},
appendFile = {
"disk.appendFile(filepath, ...) - Append the value of each of its arguments to the file.",
function(self, filepath, ...)
local data = ""
if self.__fileExist(filepath) then
data = self.__readFile(filepath)
end
return self.__writeFile(filepath, data, ...)
end
},
removeFile = {
"disk.removeFile(filepath) - Append the value of each of its arguments to the file.",
function(self, filepath)
if self.__fileExist(filepath) then
self.__removeFile(filepath)
end
end
},
fileExist = {
"disk.fileExist(filepath) - Return true if given file exist.",
function(self, filepath)
return self.__fileExist(filepath)
end
},

-- Alias
}
})
10 changes: 10 additions & 0 deletions logic/apis/speaker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ table.insert(computer.apis, {
end
},
prototype = {
print = {
"speaker.print(text, playerForce = true) - Print your message to the ingame chat log",
function(self, text, playerForce)
if not playerForce then
self.__player.print(text)
else
self.__player.force.print(text)
end
end
},
mute = {
"speaker.mute() - Remove alert et mute speaker",
function(self)
Expand Down
Loading

0 comments on commit 6aeb5bb

Please sign in to comment.