extends Node var preyzone # the node that prey will go in when spawned var CollectLocation = Vector2.ZERO ## this comment is old and probably no longer applies and may be removed # maybe 0 is internal 1 is URL and 2 is embed if possibe # ok maybe later handle this with a tool script that takes the data from the world. # after all, others might need it if anyone actually made a character for this. # which is unlikely to ever hapen. var beamtrail = true#(OS.get_name() != "Android") var camlabel var wsize:int = 50 var screensize:int = 1 var theme = preload("res://UI_themes/main.tres") var ct = "" var settingsfile = ConfigFile.new() var preyfile = File.new() var dir = Directory.new() var showtouch = false enum xrayset {NEVER, WHEN_CLICK, ALWAYS} var xray:int = xrayset.WHEN_CLICK # the data about each prey. it is a array that contains a dictionary for each prey # it starts with the rabbit but more prey can be loaded in at startup or when the # uesr imports one. in the dictionary, there is name, SpriteMain, and shape. # the name is a string that is shown to the user in the menu. # the SpriteMain is the main sprite for when not digested. usually a ImageTexture # the shape is the shape object of the prey. usually a CapsuleShape2D # size is vector2 for initial scale when spawnd # file is the location of the file. a user:// folder or null if only in memory or built-in # that will be used by the prey manager to decide whether to grey out the delete button # collectsize is the size that the prey must be equal to or less than to be collect var preydata:Dictionary = { "Rabbit":{ "SpriteMain":preload("res://sprites/rabnorm_0.png"), "file":null, "shape":preload("res://shapes/rabbit.tres"), "shaperot":90, "size":Vector2(1,1), "collectsize":Vector2(0.30,0.30), "shrunksize":Vector2(0.20,0.20), "health":2000, }, "Mouse":{ "SpriteMain":preload("res://sprites/mounorm_0.png"), "shape":preload("res://shapes/mouse.tres"), "shaperot":90, "size":Vector2(0.7,0.7), "collectsize":Vector2(0.7,0.7), "shrunksize":Vector2(0.3,0.3), "health":2000, }, } # the amount that the prey's scale is multiplied by when colected and devided by when dropped var collectscale = 10 # prey's scale is multiplied by when go inside pred and divided by when leave pred var insidescale = 2 var preytoedit = "" #the name of the prey to edit in the edit menu func _ready(): var list = Directory.new() list.make_dir("user://prey/") list.make_dir("user://autoimport/") list.open("user://autoimport/") list.list_dir_begin(true) #first read autoimport to import png as memory preys var file_name = list.get_next() while file_name != "": if file_name.ends_with(".png") or file_name.ends_with(".webp"): #load image import_prey("user://autoimport/"+file_name) file_name = list.get_next() list.list_dir_end() #now import all .prey files in the prey folder list.open("user://prey/") list.list_dir_begin(true) file_name = list.get_next() while file_name != "": import_prey("user://prey/"+file_name) file_name = list.get_next() list.list_dir_end() #load settings from file settingsfile.load("user://settings") OS.min_window_size = Vector2(320,240) Global.theme.default_font.size = settingsfile.get_value("UI","font_size",def_font_side()) screensize = settingsfile.get_value("UI","screen_size",screensize) xray = settingsfile.get_value("UI","xray",xrayset.WHEN_CLICK) set_scree_size() func import_prey(file:String,external:bool = false) -> bool: # import prey from png image or prey file. "file" var is absolute dir # if external is true, dont set the file param. keep it at null so its memory prey var img = Image.new() var imgtex = ImageTexture.new() if dir.file_exists(file): if file.get_extension() == "png" or file.get_extension() == "webp": print("Importing image into prey: ",file.get_file()) #import image into new prey if img.load(file) == OK: print("Loaded "+file) imgtex.create_from_image(img,Texture.FLAG_FILTER) preydata[file.get_file()] = auto_shape(img) preydata[file.get_file()]["SpriteMain"] = imgtex preydata[file.get_file()]["file"] = null preydata[file.get_file()]["squeeze"] = 0.7 return true else: print("Failed to load "+file) return false elif file.get_extension() == "prey": print("Importing prey data: ",file.get_file()) #load prey file maybe i will use that extention. preyfile.open(file,File.READ) var fdata:Dictionary = preyfile.get_var(false) img.load_png_from_buffer(fdata.get("SpriteMain")) imgtex.create_from_image(img,Texture.FLAG_MIPMAPS | Texture.FLAG_FILTER) var shape = recttocapsule(fdata.get("shape")) var newprey:Dictionary newprey["SpriteMain"] = imgtex if not external: newprey["file"] = file newprey["shape"] = shape[0] newprey["shaperot"] = shape[1] newprey["size"] = fdata.get("size") newprey["collectsize"] = fdata.get("collectsize") newprey["shrunksize"] = fdata.get("shrunksize") newprey["health"] = fdata.get("health") newprey["squeeze"] = fdata.get("squeeze",0.7) preydata[fdata["name"]] = newprey preyfile.close() return true # this means successs but i need to make failure detect return false func save_prey(location:String,preyname:String): print("Saving prey: ",preyname," to ",location) #save prey to this location with data in .prey format var data:Dictionary = preydata.get(preyname,{}) if data.empty(): return false var savedata:Dictionary # gather data into export format savedata = { "name":preyname, "size":data.get("size"), "shrunksize":data.get("shrunksize"), "collectsize":data.get("collectsize"), "health":data.get("health",2000), "SpriteMain":data.get("SpriteMain").get_data().save_png_to_buffer(), "shape":capsuletorect(data.get("shape"),data.get("shaperot") == 90), "squeeze":data.get("squeeze"), } # save file or to buffer if its true. preyfile.open(location,File.WRITE) preyfile.store_var(savedata) preyfile.close() func auto_shape(image: Image): # make new capsule shape from image using dimensions # in fact it also provides other automatic data for the prey #var shape = CapsuleShape2D.new() var result = recttocapsule(image.get_size()-Vector2(2,2)) var shape = result[0] var rotate = result[1] return { "shape":shape, "shaperot":rotate, "size":Vector2.ONE, "shrunksize":Vector2(0.2,0.2), "collectsize":Vector2(0.3,0.3), } func def_font_side():# set default font size based on OS if OS.get_name() == "Android": return 32 else: return(14) func capsuletorect(shape:CapsuleShape2D,rotated = false): # converts capsule shape 2d to rect width and height var rad = shape.radius var hei = shape.height var x var y if not rotated: y = hei + (rad * 2) x = (rad * 2) else: x = hei + (rad * 2) y = (rad * 2) return(Vector2(x,y)) func recttocapsule(rect:Vector2,capsule:CapsuleShape2D = null) -> Array: if capsule == null: capsule = CapsuleShape2D.new() var rotate:int if rect.y > rect.x: rotate = 0 capsule.radius = rect.x / 2 capsule.height = rect.y - capsule.radius*2 else: rotate = 90 capsule.radius = rect.y / 2 capsule.height = rect.x - capsule.radius*2 return [capsule,rotate] func set_scree_size(): var size:Vector2 if screensize == 0: size = Vector2(800,600) elif screensize == 1: size = Vector2(960,720) elif screensize == 2: size = Vector2(1280,720) get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D,SceneTree.STRETCH_ASPECT_KEEP,size) if not OS.window_fullscreen and not OS.window_maximized: OS.window_size = size