mirror of
https://codeberg.org/vlw/labylib.git
synced 2025-09-13 17:43:41 +02:00
Corrected filename
Oopsie commit! Filename 'animate.py' is now corrected to 'animated-textures.py'
This commit is contained in:
parent
fb9cc79c2c
commit
c7194c6039
2 changed files with 17 additions and 168 deletions
160
animate.py
160
animate.py
|
@ -1,160 +0,0 @@
|
||||||
import re
|
|
||||||
import json
|
|
||||||
import importlib
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# from labylib import Cape
|
|
||||||
|
|
||||||
# Don't forget to reflect in .gitignore if you change this
|
|
||||||
name = "animated-textures"
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
|
|
||||||
textures = f"./{name}/" # Cosmetic textures path
|
|
||||||
f = f"./{name}/config.json" # JSON Config file
|
|
||||||
default = '{"PHPSESSID": "","cosmetics": {"cape": {"interval": "15","randomOrder": "False"}}}' # Default config
|
|
||||||
pattern = "^[-,a-zA-Z0-9]{1,128}$" # PHPSESSID pattern
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.config = None
|
|
||||||
self.exists = True # Config file already exists
|
|
||||||
self.load()
|
|
||||||
|
|
||||||
# Example: getCosmetic("cape")
|
|
||||||
def getCosmetic(self,key):
|
|
||||||
return self.config["cosmetics"][key]
|
|
||||||
|
|
||||||
# Example: setCosmetic("cape","interval",30)
|
|
||||||
def setCosmetic(self,cosmetic,key,value):
|
|
||||||
self.config["cosmetics"][cosmetic][key] = value
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
def setPHPSESSID(self,phpsessid):
|
|
||||||
self.config["PHPSESSID"] = phpsessid
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
# -----------------------------------------------------
|
|
||||||
|
|
||||||
# (Over)write config file
|
|
||||||
def save(self):
|
|
||||||
f = open(Config.f,"w")
|
|
||||||
f.write(json.dumps(self.config))
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Create config file from default template
|
|
||||||
def create(self):
|
|
||||||
self.exists = False
|
|
||||||
|
|
||||||
Path(Config.textures).mkdir(parents=True,exist_ok=True)
|
|
||||||
|
|
||||||
f = open(Config.f,"w")
|
|
||||||
f.write(Config.default)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Load the config file from disk into memory
|
|
||||||
def load(self):
|
|
||||||
# Create config file if absent
|
|
||||||
if(Path(Config.f).is_file() == False):
|
|
||||||
self.create()
|
|
||||||
|
|
||||||
f = open(Config.f,"r")
|
|
||||||
self.config = json.load(f)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
class Main:
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.config = Config()
|
|
||||||
self.init()
|
|
||||||
|
|
||||||
# Guided step-by-step setup
|
|
||||||
def wizard(self):
|
|
||||||
# +-----------+
|
|
||||||
# | Labylib |
|
|
||||||
# +-----------+
|
|
||||||
def box(string):
|
|
||||||
charset = ["+","-","|"] # Corner,borderX,borderY
|
|
||||||
string = f" {string} " # Text padding
|
|
||||||
|
|
||||||
box = charset[0]
|
|
||||||
# Repeat 'borderX' char for string length
|
|
||||||
for x in string:
|
|
||||||
box += charset[1]
|
|
||||||
box += charset[0]
|
|
||||||
|
|
||||||
# Stitch it all together
|
|
||||||
string = f"{charset[2]}{string}{charset[2]}"
|
|
||||||
string = f"{box}\n{string}\n{box}"
|
|
||||||
|
|
||||||
return string
|
|
||||||
|
|
||||||
msgDone = "Done! Closing Wizard"
|
|
||||||
|
|
||||||
print(box("Labylib Setup Wizard"))
|
|
||||||
print("Make sure you read the README before you begin\n")
|
|
||||||
|
|
||||||
self.config.setPHPSESSID(input("Paste your PHPSESSID here:\n"))
|
|
||||||
|
|
||||||
advanced = input("\nDo you wish to modify the default cosmetic settings? 'y/n'[n]: ")
|
|
||||||
if(advanced != "y"):
|
|
||||||
print(box(msgDone))
|
|
||||||
self.start()
|
|
||||||
return
|
|
||||||
|
|
||||||
wizard = self.config.config["cosmetics"]
|
|
||||||
|
|
||||||
# Iterate over all cosmetics in config
|
|
||||||
for cosmetic in wizard:
|
|
||||||
print(box("Cosmetic > " + cosmetic.capitalize()))
|
|
||||||
|
|
||||||
# Iterate over every cosmetic setting
|
|
||||||
for key, default in wizard[cosmetic].items():
|
|
||||||
value = input(f"Set value for '{key}'[{default}]: ")
|
|
||||||
# Ignore input if empty or data type doesn't match default
|
|
||||||
if(len(value) < 1):
|
|
||||||
print(f"Input error: Expected data type '{type(default)}'. Falling back to default")
|
|
||||||
value = default
|
|
||||||
|
|
||||||
self.config.setCosmetic(cosmetic,key,value)
|
|
||||||
|
|
||||||
print(box(msgDone))
|
|
||||||
self.start()
|
|
||||||
|
|
||||||
#for cosmetic in wizard:
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
phpsessid = self.config.config["PHPSESSID"]
|
|
||||||
start = input(f"\nStart Labylib for PHPSESSID '{phpsessid}'? 'y/n/config'[y]: ")
|
|
||||||
|
|
||||||
if(start == "n"):
|
|
||||||
return
|
|
||||||
|
|
||||||
if(start == "config"):
|
|
||||||
self.wizard()
|
|
||||||
return
|
|
||||||
|
|
||||||
# TODO: Attach labylib hook here
|
|
||||||
|
|
||||||
def init(self):
|
|
||||||
print("Labylib 0.0.1\n")
|
|
||||||
|
|
||||||
if(self.config.exists and len(self.config.config["PHPSESSID"]) > 1):
|
|
||||||
self.start()
|
|
||||||
return
|
|
||||||
|
|
||||||
for cosmetic in self.config.config["cosmetics"]:
|
|
||||||
Path(Config.textures + cosmetic).mkdir(parents=True,exist_ok=True)
|
|
||||||
|
|
||||||
# Prompt if user wants to use guided setup
|
|
||||||
print("-- Labylib Animated Textures --\nSince this is your first time here, would you like to walk through the setup process?\n")
|
|
||||||
wizard = input("Start guided setup? 'y/n':[y] ")
|
|
||||||
if(wizard == "n"):
|
|
||||||
print(f"A config file '{Config.f}' has been created for you. Run this command again when you're ready")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.wizard()
|
|
||||||
|
|
||||||
# Start Labylib
|
|
||||||
labylib = Main()
|
|
|
@ -5,13 +5,16 @@ from pathlib import Path
|
||||||
|
|
||||||
# from labylib import Cape
|
# from labylib import Cape
|
||||||
|
|
||||||
|
# Don't forget to reflect in .gitignore if you change this
|
||||||
|
name = "animated-textures"
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
f = ".animate-config.json"
|
textures = f"./{name}/" # Cosmetic textures path
|
||||||
|
f = f"./{name}/config.json" # JSON Config file
|
||||||
|
default = '{"PHPSESSID": "","cosmetics": {"cape": {"interval": "15","randomOrder": "False"}}}' # Default config
|
||||||
pattern = "^[-,a-zA-Z0-9]{1,128}$" # PHPSESSID pattern
|
pattern = "^[-,a-zA-Z0-9]{1,128}$" # PHPSESSID pattern
|
||||||
|
|
||||||
template = '{\n\t"PHPSESSID": "",\n\t"cosmetics": {\n\t\t"cape": {\n\t\t\t"interval": 15,\n\t\t\t"random": false\n\t\t}\n\t}\n}'
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = None
|
self.config = None
|
||||||
self.exists = True # Config file already exists
|
self.exists = True # Config file already exists
|
||||||
|
@ -38,12 +41,14 @@ class Config:
|
||||||
f.write(json.dumps(self.config))
|
f.write(json.dumps(self.config))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Create config file from template
|
# Create config file from default template
|
||||||
def create(self):
|
def create(self):
|
||||||
self.exists = False
|
self.exists = False
|
||||||
|
|
||||||
|
Path(Config.textures).mkdir(parents=True,exist_ok=True)
|
||||||
|
|
||||||
f = open(Config.f,"w")
|
f = open(Config.f,"w")
|
||||||
f.write(Config.template)
|
f.write(Config.default)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Load the config file from disk into memory
|
# Load the config file from disk into memory
|
||||||
|
@ -55,6 +60,7 @@ class Config:
|
||||||
f = open(Config.f,"r")
|
f = open(Config.f,"r")
|
||||||
self.config = json.load(f)
|
self.config = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class Main:
|
class Main:
|
||||||
|
@ -129,17 +135,20 @@ class Main:
|
||||||
self.wizard()
|
self.wizard()
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Labylib is running.. (type 'stop' to close Labylib)")
|
# TODO: Attach labylib hook here
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
print("Labylib 0.0.1")
|
print("Labylib 0.0.1\n")
|
||||||
|
|
||||||
if(self.config.exists and len(self.config.config["PHPSESSID"]) > 1):
|
if(self.config.exists and len(self.config.config["PHPSESSID"]) > 1):
|
||||||
self.start()
|
self.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for cosmetic in self.config.config["cosmetics"]:
|
||||||
|
Path(Config.textures + cosmetic).mkdir(parents=True,exist_ok=True)
|
||||||
|
|
||||||
# Prompt if user wants to use guided setup
|
# Prompt if user wants to use guided setup
|
||||||
print("-- Welcome to Labylib --\nSince this is your first time here, would you like to walk through the setup process?\n")
|
print("-- Labylib Animated Textures --\nSince this is your first time here, would you like to walk through the setup process?\n")
|
||||||
wizard = input("Start guided setup? 'y/n':[y] ")
|
wizard = input("Start guided setup? 'y/n':[y] ")
|
||||||
if(wizard == "n"):
|
if(wizard == "n"):
|
||||||
print(f"A config file '{Config.f}' has been created for you. Run this command again when you're ready")
|
print(f"A config file '{Config.f}' has been created for you. Run this command again when you're ready")
|
||||||
|
|
Loading…
Add table
Reference in a new issue