introduction of items
This commit is contained in:
		
							
								
								
									
										26
									
								
								app/pylocal/items.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/pylocal/items.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
import subprocess
 | 
			
		||||
import xml.etree.ElementTree as xmltree
 | 
			
		||||
 | 
			
		||||
from . import core
 | 
			
		||||
 | 
			
		||||
valid_resources = [
 | 
			
		||||
    "food", "shinies", "psi" # early game
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
def generate_item(resource, target):
 | 
			
		||||
    if core.desktop_mode:
 | 
			
		||||
        rant_path = core.path_appdir / "opt/rant/bin/rant"
 | 
			
		||||
    else:
 | 
			
		||||
        rant_path = "rant" # rely on OS PATH
 | 
			
		||||
    proc_rant = subprocess.run([rant_path, (core.path_appdir / f"rant/{resource}/{target}.rant").as_posix()], capture_output=True)
 | 
			
		||||
    return proc_rant.stdout.decode()
 | 
			
		||||
 | 
			
		||||
class TickItem(object):
 | 
			
		||||
    def __init__(self, resource, amount, target):
 | 
			
		||||
        if resource not in valid_resources:
 | 
			
		||||
            raise TypeError
 | 
			
		||||
        
 | 
			
		||||
        self.resource = resource
 | 
			
		||||
        self.amount = amount
 | 
			
		||||
        self.target = target
 | 
			
		||||
        self.desc = generate_item(resource, target)
 | 
			
		||||
@@ -4,7 +4,7 @@ import subprocess
 | 
			
		||||
 | 
			
		||||
import flask
 | 
			
		||||
 | 
			
		||||
from . import core
 | 
			
		||||
from . import core, items
 | 
			
		||||
 | 
			
		||||
def generate_flavor_text():
 | 
			
		||||
    if core.desktop_mode:
 | 
			
		||||
@@ -45,7 +45,11 @@ def tick():
 | 
			
		||||
        case 1: # FLAVOR
 | 
			
		||||
            result["log"] = generate_flavor_text()
 | 
			
		||||
        case 10: # ENCHUMAN
 | 
			
		||||
            result["items"] = {} # TODO: implement items
 | 
			
		||||
            result["items"] = {
 | 
			
		||||
                # TODO: read ranges from XML rule files
 | 
			
		||||
                "food": [items.TickItem("food", random.uniform(0.0, 20.0), "humans")],
 | 
			
		||||
                "shinies": [items.TickItem("food", random.uniform(0.0, 20.0), "humans")]
 | 
			
		||||
            }
 | 
			
		||||
        case _:
 | 
			
		||||
            core.log.warning("undefined tick: {0}".format(result["event_type"]))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user