Created
July 4, 2018 18:58
-
-
Save jedStevens/4e61c7866621a97bc6ff9cc125251bc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
func get_cropped_items(): | |
# Return the items in the cropping zone, | |
# calculates a crop beforehand | |
# CROP THE ITEMS | |
# 1. Find the search Area | |
var min_x = width | |
var max_x = 0 | |
var min_y = height | |
var max_y = 0 | |
for x in range(width): | |
for y in range(height): | |
var i = xy_to_index(x,y) | |
if is_item_at(i): | |
if x < min_x: | |
min_x = x | |
if x > max_x: | |
max_x = x | |
if y < min_y: | |
min_y = y | |
if y > max_y: | |
max_y = y | |
# 2. unpack the area to a list | |
var crop_w = max_x - min_x + 1 | |
var crop_h = max_y - min_y + 1 | |
var cropped_items = [] | |
for x in range(crop_w): | |
for y in range(crop_h): | |
var i = xy_to_index(min_x + x, min_y + y) | |
cropped_items.append(get_item(i)) | |
var size = Vector2(crop_w, crop_h) | |
return [cropped_items, size] | |
func get_item(i): | |
return Items.get_id_from_string($CraftingGrid.get_child(i).type) | |
func is_item_at(i): | |
pass | |
func xy_to_index(x,y): | |
return cols * y + x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment