-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit afa47e2
Showing
28 changed files
with
3,833 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
pcall(function() | ||
require "defines" | ||
end) | ||
require "core.class" | ||
require "core.defines" | ||
require "core.logging" | ||
require "player.playerController" | ||
helmod = {} | ||
|
||
|
||
--=========================== | ||
-- trace=4 | ||
-- debug=3 | ||
-- info=2 | ||
-- erro=1 | ||
-- nothing=0 | ||
Logging:new(0) | ||
Logging.console = true | ||
Logging.force = true | ||
--=========================== | ||
function helmod:on_init(event) | ||
self.name = "helmod" | ||
--self.version = "0.1.1" | ||
self.loaded = false; | ||
|
||
self.playerControllers = {} | ||
|
||
if global.beacon == nil then | ||
global.beacon = helmod_defines.beacon | ||
end | ||
|
||
if global.factory == nil then | ||
global.factory = helmod_defines.factory | ||
end | ||
|
||
end | ||
|
||
--=========================== | ||
function helmod:on_configuration_changed(data) | ||
if not data or not data.mod_changes then | ||
return | ||
end | ||
if data.mod_changes["helmod"] then | ||
self:on_init() | ||
end | ||
end | ||
|
||
--=========================== | ||
function helmod:on_load(event) | ||
if self.loaded ~= true then | ||
self:on_init() | ||
end | ||
end | ||
|
||
--=========================== | ||
function helmod:on_tick(event) | ||
if game.tick % 60 == 0 then | ||
--Logging:debug("tick 60") | ||
if self.loaded ~= true then | ||
self:init_playerController() | ||
self.loaded = true; | ||
Logging:debug("global=",global) | ||
end | ||
end | ||
if game.tick % 300 == 0 then | ||
Logging:write() | ||
end | ||
end | ||
|
||
--=========================== | ||
function helmod:init_playerController() | ||
for key, player in pairs(game.players) do | ||
if player.has_game_view() then | ||
self.playerControllers[player.index] = PlayerController:new(player) | ||
self.playerControllers[player.index]:bindController() | ||
end | ||
end | ||
end | ||
|
||
--=========================== | ||
function helmod:on_gui_click(event) | ||
if self.playerControllers ~= nil then | ||
for r, playerControllers in pairs(self.playerControllers) do | ||
playerControllers:on_gui_click(event) | ||
end | ||
end | ||
end | ||
|
||
--=========================== | ||
function helmod:on_player_created(event) | ||
if self.loaded ~= true then | ||
self:init_playerController() | ||
self.loaded = true; | ||
end | ||
end | ||
|
||
--=========================== | ||
function proxy_init(event) | ||
helmod:on_init(event) | ||
end | ||
|
||
function proxy_load(event) | ||
helmod:on_load(event) | ||
end | ||
|
||
function proxy_configuration_changed(data) | ||
helmod:on_configuration_changed(data) | ||
end | ||
|
||
function proxy_tick(event) | ||
helmod:on_tick(event) | ||
end | ||
|
||
function proxy_player_created(event) | ||
helmod:on_player_created(event) | ||
end | ||
|
||
function proxy_gui_click(event) | ||
helmod:on_gui_click(event) | ||
end | ||
|
||
|
||
script.on_init(proxy_init) | ||
script.on_load(proxy_load) | ||
script.on_configuration_changed(proxy_configuration_changed) | ||
script.on_event(defines.events.on_tick, proxy_tick) | ||
script.on_event(defines.events.on_player_created, proxy_player_created) | ||
script.on_event(defines.events.on_gui_click,proxy_gui_click) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
----------------------------------------------------- | ||
---- SETCLASS CLONES THE BASIC OBJECT CLASS TO CREATE NEW CLASSES | ||
----------------------------------------------------- | ||
-- Supports INHERITANCE | ||
--------------------------------------------------------------- | ||
-- EVERYTHING INHERITS FROM THIS BASIC OBJECT CLASS | ||
BaseObject = { | ||
super = nil, | ||
name = "Object", | ||
new = | ||
function(class) | ||
local obj = {class = class} | ||
local meta = { | ||
__index = function(self,key) return class.methods[key] end | ||
} | ||
setmetatable(obj,meta) | ||
return obj | ||
end, | ||
methods = {classname = function(self) return(self.class.name) end}, | ||
data = {} | ||
} | ||
|
||
function setclass(name, super) | ||
if (super == nil) then | ||
super = BaseObject | ||
end | ||
|
||
local class = { | ||
super = super; | ||
name = name; | ||
new = | ||
function(self, ...) | ||
local arg = {...} | ||
local obj = super.new(self, "___CREATE_ONLY___"); | ||
-- check if calling function init | ||
-- pass arguments into init function | ||
if (super.methods.init) then | ||
obj.init_super = super.methods.init | ||
end | ||
|
||
if (self.methods.init) then | ||
if (tostring(arg[1]) ~= "___CREATE_ONLY___") then | ||
obj.init = self.methods.init | ||
if obj.init then | ||
obj:init(unpack(arg)) | ||
end | ||
end | ||
end | ||
|
||
return obj | ||
end, | ||
methods = {} | ||
} | ||
|
||
-- if class slot unavailable, check super class | ||
-- if applied to argument, pass it to the class method new | ||
setmetatable(class, { | ||
__index = function(self,key) return self.super[key] end, | ||
__call = function(self,...) | ||
local arg = {...} | ||
return self.new(self,unpack(arg)) | ||
end | ||
}) | ||
|
||
-- if instance method unavailable, check method slot in super class | ||
setmetatable(class.methods, { | ||
__index = function(self,key) return class.super.methods[key] end | ||
}) | ||
return class | ||
end |
Oops, something went wrong.