Fixed crashes

This commit is contained in:
strongleong 2023-02-07 19:38:24 +11:00
parent 7a34fd006b
commit 40e264083f
7 changed files with 114 additions and 39 deletions

View file

@ -1,3 +1,6 @@
# 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.

View file

@ -16,12 +16,7 @@
import Scrap
def log(msg):
Scrap.Print("[STRNG][INIT] " + msg + "\n")
log('Init started')
logger = None
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)
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
@ -118,10 +124,6 @@ Scrap.PreloadLibrary('Items','Items.pyc')
Scrap.PreloadLibrary('SaveGame','SaveGame.pyc')
###### Sistema de menues y scorer ######
log('Preloading ModsMenu')
Scrap.PreloadLibrary('MyMenu','Scorer/MyMenu.pyc')
log('ModsMenu preload injected')
if (Scrap.Get("IsXbox") == 1):
Scrap.PreloadLibrary('XBMenu','Scorer/XBMenu.pyc')
else:

View file

@ -1,10 +1,40 @@
# Logger
Logger for logging stuff.
Logger for logging stuff. Thanks to @earthnuker.
```pyhton
import Logger
Quick snippet for initialisation in your `.py` file
Logger.info("A")
Logger.error("OH NO!")
```python
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

View file

@ -1,29 +1,39 @@
import Scrap
import string
class Logger:
def __init__(self, name):
self.level=""
self.name=name
self.level = ""
self.name = name
def __repr__(self):
return "<Logger>"
return "<Logger: " + self.name + ">"
def __str__(self):
return self.__repr__()
def __call__(self, *args):
# frame = sys.modules[__name__].last_frame
# frame_info = (frame.f_code.co_name,frame.f_code.co_name)
# Scrap.Print(repr(frame_info)+"\n")
args=list(args)
if string.find(self.level, "__") == 0:
return
args = list(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
msg = string.join(args," ")
Scrap.Print(msg+"\n")
args = ["[" + str(self.name) + "|" + string.upper(self.level) + "]"] + args
msg = string.join(args, " ")
Scrap.Print(msg + "\n")
def __getattr__(self, level):
self.level=level
self.level = level
return self
def __nonzero__(self):
return True
def __bool__(self):
return True

View file

@ -9,10 +9,22 @@ import SAct
import sys
logger = None
Scrap.Print("[STRNG][Police] 0" + "\n")
try:
logger = __import__("Logger").Logger("Police")
except Exception:
pass
def log(msg):
Scrap.Print("[STRNG][Police] " + str(msg) + "\n")
if logger is not None:
logger.info(msg)
else:
Scrap.Print("[STRNG][Police] " + str(msg) + "\n")
log("Starting module")
# WARNING : Never import any pyhton source library at the start up!

View file

@ -1,9 +1,17 @@
import Scrap,SInput,SNet,SWeap,SScorer,SVec
logger = None
try:
logger = __import__("Logger").Logger("Police")
except Exception:
pass
def log(msg):
Scrap.Print("[STRNG][MyMenu] " + str(msg) + "\n")
if logger is not None:
logger.info(msg)
else:
Scrap.Print("[STRNG][MyMenu] " + str(msg) + "\n")
log("Starting module")
@ -34,11 +42,11 @@ def MyMenu(id, control):
ResetToDefault()
import Menu
log("Creating mods menu")
log("Creating cusom menu")
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_Counter") + ":", "MyMenu.TestCounter" ],
[Scrap.GetLangStr("My_Menu_Test_Slider") + ":", "Menu.DummyFunc" ],

View file

@ -1,8 +1,17 @@
import Scrap,SInput,SNet,SWeap,SScorer,SVec
logger = None
try:
logger = __import__("Logger").Logger("Police")
except Exception:
pass
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")
@ -10,10 +19,11 @@ log("Starting module")
MOTD = ""
Menu = None
MyMenuLib = __import__("modsmenu")
MyMenu = MyMenuLib.MyMenu
MyMenuLib = __import__("MyMenu")
log("Mods menu imported")
log("MyMenu imported")
MyMenu = MyMenuLib.MyMenu
def AbortWaitRedefine(id):
global ControlMenuId