Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackRam-oss committed Mar 11, 2023
1 parent cef7bc9 commit aa9789a
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,4 @@ game/cache

# Templete files
.renpy-sdk
Wiki
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Don Renpy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion game/tool/core.rpy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define config.log = "log.txt"

label after_load:
$ flags = updateFlags(flags, flag_keys)
$ updateFlags()
return
37 changes: 12 additions & 25 deletions game/tool/flags.rpy
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
# IMPORTANT: insert updateFlags() in start or before using flags
init python:
import pythonpackages.flags as myFlags

# flags are Boolean values, a good use is for example in quests to know quickly if MC has the possibility to do a certain thing, after unlocking it somehow.
# has the same alements as flag_keys, all set as False
# I suggest to leave it empty and add the elements only if it is an initial value and set as True
default flags = {}
define flag_keys = [
# Block all actions with check_block_spendtime
# Block all spend_time
"not_can_spend_time",
"goout",
]

init python:
def updateFlags(flags: dict[str, bool], flag_keys: list[str]):
def updateFlags():
"""update flags by making it with the same elements of flag_keys. in case you have to add them set them as False"""
# check if there are less elements than flag_keys
# in case you add them set with False
for x in flag_keys:
if ((x in flags) == False):
flags[x] = False
# check if there are more elements than flag_keys
# in case it eliminates them
flags_to_del = []
for x in flags:
if ((x in flag_keys) == False):
flags_to_del.append(x)
for x in flags_to_del:
del flags[x]
del flags_to_del
return flags
return myFlags.updateFlags(flags, flag_keys)

def getFlags(flag_id: str) -> bool:
"""returns the value of the flag_id in flags"""
if (not flag_id in flags):
updateFlags(flags = flags, flag_keys = flag_keys)
if (not flag_id in flags):
renpy.log("Error(getFlags): in flags is not there flag_id: "+flag_id)
else:
return False
return flags[flag_id]
return myFlags.getFlags(flag_id, flags)

def setFlags(flag_id: str, value: bool):
return myFlags.setFlags(flag_id, value, flags)
23 changes: 7 additions & 16 deletions game/tool/log_system.rpy
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
init -998 python:
import pythonpackages.renpy_custom_log as myLog

# 'define config.log' is in core.rpy
error_notify = __("Where was an {color=#f00}{b}ERROR{/b}{/color}. Please send the developer the logs found in: {color=#00ccff}[config.log]{/color}")
warn_notify = _("Where was an {color=#f5bc02}{b}WARN{/b}{/color}. Please send the developer the logs found in: {color=#00ccff}[config.log]{/color}")
error_notify = __("There is an {color=#f00}{b}ERROR{/b}{/color}. Please send the developer the logs found in: {color=#00ccff}[config.log]{/color}")
warn_notify = _("There is an {color=#f5bc02}{b}WARN{/b}{/color}. Please send the developer the logs found in: {color=#00ccff}[config.log]{/color}")
info_notify = False

def log_error(msg: str, filename_line = None):
renpy.log("Error: " + msg)
log_filename_line(filename_line)
myLog.log_error(msg, filename_line)
if error_notify:
notifyExPreventsLoops(msg = error_notify)
renpy.log("")
return

def log_warn(msg: str, filename_line = None):
renpy.log("Warn: " + msg)
log_filename_line(filename_line)
myLog.log_warn(msg, filename_line)
if not IsNullOrWhiteSpace(warn_notify):
notifyExPreventsLoops(msg = warn_notify)
renpy.log("")
return

def log_info(msg: str, filename_line = None):
renpy.log("Info: " + msg)
log_filename_line(filename_line)
myLog.log_info(msg, filename_line)
if not IsNullOrWhiteSpace(info_notify):
notifyExPreventsLoops(msg = info_notify)
renpy.log("")
return

def log_filename_line(filename_line = None):
if filename_line:
renpy.log("filename_line: " + str(filename_line))
return
Empty file added pythonpackages/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions pythonpackages/flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json

from pythonpackages.renpy_custom_log import *

__all__ = [
"updateFlags",
"getFlags",
"setFlags",
]


def updateFlags(flags: dict[str, bool], flag_keys: list[str]):
"""update flags by making it with the same elements of flag_keys. in case you have to add them set them as False"""
# check if there are less elements than flag_keys
# in case you add them set with False
for x in flag_keys:
if (not (x in flags)):
flags[x] = False
# check if there are more elements than flag_keys
# in case it eliminates them
flags_to_del = []
for x in flags:
if (not (x in flag_keys)):
flags_to_del.append(x)
for x in flags_to_del:
del flags[x]
del flags_to_del
return flags


def getFlags(flag_id: str, flags: dict[str, bool]) -> bool:
"""returns the value of the flag_id in flags"""
if (flag_id in flags):
return flags[flag_id]
else:
return False


def setFlags(flag_id: str, value: bool, flags: dict[str, bool]):
flags[flag_id] = value
return
35 changes: 35 additions & 0 deletions pythonpackages/renpy_custom_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import renpy.exports as renpy

__all__ = [
"log_error",
"log_warn",
"log_info",
"log_filename_line",
]


def log_error(msg: str, filename_line=None):
renpy.log("Error: " + msg)
log_filename_line(filename_line)
renpy.log("")
return


def log_warn(msg: str, filename_line=None):
renpy.log("Warn: " + msg)
log_filename_line(filename_line)
renpy.log("")
return


def log_info(msg: str, filename_line=None):
renpy.log("Info: " + msg)
log_filename_line(filename_line)
renpy.log("")
return


def log_filename_line(filename_line=None):
if filename_line:
renpy.log("filename_line: " + str(filename_line))
return
16 changes: 16 additions & 0 deletions pythonpackages/utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__all__ = [
"isNullOrEmpty",
"IsNullOrWhiteSpace",
]


def isNullOrEmpty(item: str) -> bool:
if not item:
return True
return False


def IsNullOrWhiteSpace(item: str) -> bool:
if not item or item.isspace():
return True
return False

0 comments on commit aa9789a

Please sign in to comment.