Fixed crashes
This commit is contained in:
parent
7a34fd006b
commit
40e264083f
7 changed files with 114 additions and 39 deletions
|
@ -1,3 +1,6 @@
|
||||||
# Loader
|
# Loader
|
||||||
|
|
||||||
This is just `init.py` with my custom files preloaded
|
This is just `init.py` with my custom files preloaded.
|
||||||
|
|
||||||
|
In the future we will come up with some mechanism for auto-preloading `.pyc` files
|
||||||
|
in some special folder. But for now it is what it is.
|
||||||
|
|
|
@ -16,12 +16,7 @@
|
||||||
|
|
||||||
import Scrap
|
import Scrap
|
||||||
|
|
||||||
|
logger = None
|
||||||
def log(msg):
|
|
||||||
Scrap.Print("[STRNG][INIT] " + msg + "\n")
|
|
||||||
|
|
||||||
|
|
||||||
log('Init started')
|
|
||||||
|
|
||||||
PlaySpacelords = not Scrap.IsApp(436180) # 1 to activate the cross promotion
|
PlaySpacelords = not Scrap.IsApp(436180) # 1 to activate the cross promotion
|
||||||
##################################
|
##################################
|
||||||
|
@ -110,6 +105,17 @@ HasSuperDeal = OffLineGame and sDealType and sDealType != "" and (UpperMap in
|
||||||
OutMapSkip = OffLineGame and (UpperMap in OUTMAPS)
|
OutMapSkip = OffLineGame and (UpperMap in OUTMAPS)
|
||||||
InMapSkip = OffLineGame and (UpperMap in INMAPS)
|
InMapSkip = OffLineGame and (UpperMap in INMAPS)
|
||||||
|
|
||||||
|
###### Preloading custom stuff ######
|
||||||
|
Scrap.PreloadLibrary('Logger','Custom/Logger.pyc')
|
||||||
|
|
||||||
|
import Logger
|
||||||
|
logger = Logger.Logger('Loader')
|
||||||
|
logger.info('Logger initialized')
|
||||||
|
logger.debug(logger)
|
||||||
|
|
||||||
|
logger.info('Preloading MyMenu...')
|
||||||
|
Scrap.PreloadLibrary('MyMenu','Scorer/MyMenu.pyc')
|
||||||
|
logger.info('MyMenu preloaded')
|
||||||
|
|
||||||
#Scrap.PreloadLibrary('QuickConsole','QuickConsole.pyc') # QuickConsole no es una libreria para el sistema
|
#Scrap.PreloadLibrary('QuickConsole','QuickConsole.pyc') # QuickConsole no es una libreria para el sistema
|
||||||
|
|
||||||
|
@ -118,10 +124,6 @@ Scrap.PreloadLibrary('Items','Items.pyc')
|
||||||
Scrap.PreloadLibrary('SaveGame','SaveGame.pyc')
|
Scrap.PreloadLibrary('SaveGame','SaveGame.pyc')
|
||||||
|
|
||||||
###### Sistema de menues y scorer ######
|
###### Sistema de menues y scorer ######
|
||||||
log('Preloading ModsMenu')
|
|
||||||
Scrap.PreloadLibrary('MyMenu','Scorer/MyMenu.pyc')
|
|
||||||
log('ModsMenu preload injected')
|
|
||||||
|
|
||||||
if (Scrap.Get("IsXbox") == 1):
|
if (Scrap.Get("IsXbox") == 1):
|
||||||
Scrap.PreloadLibrary('XBMenu','Scorer/XBMenu.pyc')
|
Scrap.PreloadLibrary('XBMenu','Scorer/XBMenu.pyc')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,10 +1,40 @@
|
||||||
# Logger
|
# Logger
|
||||||
|
|
||||||
Logger for logging stuff.
|
Logger for logging stuff. Thanks to @earthnuker.
|
||||||
|
|
||||||
```pyhton
|
Quick snippet for initialisation in your `.py` file
|
||||||
import Logger
|
|
||||||
|
|
||||||
Logger.info("A")
|
```python
|
||||||
Logger.error("OH NO!")
|
logger = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger = __import__("Logger").Logger("Police")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def log(msg):
|
||||||
|
if logger is not None:
|
||||||
|
logger.info(msg)
|
||||||
|
else:
|
||||||
|
Scrap.Print("[Logger][File] " + str(msg) + "\n")
|
||||||
|
|
||||||
|
|
||||||
|
log("Starting module")
|
||||||
|
|
||||||
|
logger.info("A")
|
||||||
|
logger.error("OH NO!")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
NOTE: Never do something like:
|
||||||
|
|
||||||
|
```python
|
||||||
|
if logger:
|
||||||
|
this
|
||||||
|
else:
|
||||||
|
that
|
||||||
|
```
|
||||||
|
|
||||||
|
It will crahs.
|
||||||
|
|
||||||
|
TODO: come up with better system
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Scrap
|
import Scrap
|
||||||
|
import string
|
||||||
|
|
||||||
class Logger:
|
class Logger:
|
||||||
|
|
||||||
|
@ -7,23 +8,32 @@ class Logger:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Logger>"
|
return "<Logger: " + self.name + ">"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.__repr__()
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
# frame = sys.modules[__name__].last_frame
|
if string.find(self.level, "__") == 0:
|
||||||
# frame_info = (frame.f_code.co_name,frame.f_code.co_name)
|
return
|
||||||
# Scrap.Print(repr(frame_info)+"\n")
|
|
||||||
args = list(args)
|
args = list(args)
|
||||||
|
|
||||||
for i in range(len(args)):
|
for i in range(len(args)):
|
||||||
args[i] = str(args[i])
|
args[i] = str(args[i])
|
||||||
|
if args[i] == None:
|
||||||
|
args[i] = ""
|
||||||
|
|
||||||
args = ["[" + str(self.name) + "|" + string.upper(self.level) + "]"] + args
|
args = ["[" + str(self.name) + "|" + string.upper(self.level) + "]"] + args
|
||||||
|
|
||||||
msg = string.join(args, " ")
|
msg = string.join(args, " ")
|
||||||
|
|
||||||
Scrap.Print(msg + "\n")
|
Scrap.Print(msg + "\n")
|
||||||
|
|
||||||
def __getattr__(self, level):
|
def __getattr__(self, level):
|
||||||
self.level = level
|
self.level = level
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def __nonzero__(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
return True
|
||||||
|
|
|
@ -9,10 +9,22 @@ import SAct
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
logger = None
|
||||||
|
|
||||||
|
Scrap.Print("[STRNG][Police] 0" + "\n")
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger = __import__("Logger").Logger("Police")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def log(msg):
|
def log(msg):
|
||||||
|
if logger is not None:
|
||||||
|
logger.info(msg)
|
||||||
|
else:
|
||||||
Scrap.Print("[STRNG][Police] " + str(msg) + "\n")
|
Scrap.Print("[STRNG][Police] " + str(msg) + "\n")
|
||||||
|
|
||||||
|
log("Starting module")
|
||||||
|
|
||||||
# WARNING : Never import any pyhton source library at the start up!
|
# WARNING : Never import any pyhton source library at the start up!
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
import Scrap,SInput,SNet,SWeap,SScorer,SVec
|
import Scrap,SInput,SNet,SWeap,SScorer,SVec
|
||||||
|
|
||||||
|
logger = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger = __import__("Logger").Logger("Police")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def log(msg):
|
def log(msg):
|
||||||
|
if logger is not None:
|
||||||
|
logger.info(msg)
|
||||||
|
else:
|
||||||
Scrap.Print("[STRNG][MyMenu] " + str(msg) + "\n")
|
Scrap.Print("[STRNG][MyMenu] " + str(msg) + "\n")
|
||||||
|
|
||||||
|
|
||||||
log("Starting module")
|
log("Starting module")
|
||||||
|
|
||||||
# ResetToDefault()
|
# ResetToDefault()
|
||||||
|
@ -34,11 +42,11 @@ def MyMenu(id, control):
|
||||||
ResetToDefault()
|
ResetToDefault()
|
||||||
|
|
||||||
import Menu
|
import Menu
|
||||||
log("Creating mods menu")
|
log("Creating cusom menu")
|
||||||
|
|
||||||
Menu.StartNewMenu(id)
|
Menu.StartNewMenu(id)
|
||||||
|
|
||||||
Menu.VerticalMenu(id, Scrap.GetLangStr("Menu_Options_Mods"),(
|
Menu.VerticalMenu(id, Scrap.GetLangStr("Menu_Options_MyMenu"),(
|
||||||
[Scrap.GetLangStr("My_Menu_Test_Bool") + ":", "MyMenu.TestBool" ],
|
[Scrap.GetLangStr("My_Menu_Test_Bool") + ":", "MyMenu.TestBool" ],
|
||||||
[Scrap.GetLangStr("My_Menu_Test_Counter") + ":", "MyMenu.TestCounter" ],
|
[Scrap.GetLangStr("My_Menu_Test_Counter") + ":", "MyMenu.TestCounter" ],
|
||||||
[Scrap.GetLangStr("My_Menu_Test_Slider") + ":", "Menu.DummyFunc" ],
|
[Scrap.GetLangStr("My_Menu_Test_Slider") + ":", "Menu.DummyFunc" ],
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
import Scrap,SInput,SNet,SWeap,SScorer,SVec
|
import Scrap,SInput,SNet,SWeap,SScorer,SVec
|
||||||
|
|
||||||
|
logger = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger = __import__("Logger").Logger("Police")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def log(msg):
|
def log(msg):
|
||||||
Scrap.Print("[STRNG][PCMenu] " + msg + "\n")
|
if logger is not None:
|
||||||
|
logger.info(msg)
|
||||||
|
else:
|
||||||
|
Scrap.Print("[STRNG][PCMenu] " + str(msg) + "\n")
|
||||||
|
|
||||||
|
|
||||||
log("Starting module")
|
log("Starting module")
|
||||||
|
@ -10,10 +19,11 @@ log("Starting module")
|
||||||
MOTD = ""
|
MOTD = ""
|
||||||
|
|
||||||
Menu = None
|
Menu = None
|
||||||
MyMenuLib = __import__("modsmenu")
|
MyMenuLib = __import__("MyMenu")
|
||||||
MyMenu = MyMenuLib.MyMenu
|
|
||||||
|
|
||||||
log("Mods menu imported")
|
log("MyMenu imported")
|
||||||
|
|
||||||
|
MyMenu = MyMenuLib.MyMenu
|
||||||
|
|
||||||
def AbortWaitRedefine(id):
|
def AbortWaitRedefine(id):
|
||||||
global ControlMenuId
|
global ControlMenuId
|
||||||
|
|
Loading…
Reference in a new issue