windows full features

This commit is contained in:
KAymeric
2024-05-26 01:37:06 +02:00
parent 7071b0a81c
commit e47c8cf7ce
7 changed files with 75 additions and 32 deletions

View File

@@ -1,7 +1,8 @@
import random as rd
import math
from gdpc import Editor, Block, geometry, Transform
from utils.Enums import COLLUMN_STYLE
from utils.Enums import COLLUMN_STYLE, BORDER_RADIUS
from utils.functions import *
from buildings.geometry.Point import Point
from buildings.geometry.Vertice import Vertice
@@ -13,6 +14,7 @@ class Window:
self.has_multiple_windows = self.has_multiple_windows()
self.is_alternate = self.is_alternate()
self.has_vertical_crossbar, self.has_horizontal_crossbar = self.has_crossbars()
self.border_radius = self.border_radius()
self.padding = 0
self.editor, self.materials = None,None
@@ -24,12 +26,12 @@ class Window:
self.padding = (facade_len - self.width)//2
self.width = facade_len - self.padding*2
self.is_alternate = True
if not self.is_grounded: editor.transform @= Transform((0,(facade_height-self.height)//2,0))
editor.transform @= Transform((self.padding,0,0))
if self.has_multiple_windows: self.build_multiple_windows()
else :
self.place_glasses(self.padding, self.width+self.padding)
self.place_glasses(0, self.width)
def build_multiple_windows(self):
slices = rd.randint(3, self.width//self.rdata["size"]["min_width"])
@@ -48,9 +50,8 @@ class Window:
if i == mid: wsize, isize = wsize + remainder, isize + remainder
# kepp a spacing between windows, "is revert" is used to keep symetry
if is_window:
x= self.padding + gap
self.place_glasses(x, x+wsize)
if is_window:
self.place_glasses(gap, gap+wsize)
gap += wsize
else :
gap += isize
@@ -70,9 +71,10 @@ class Window:
is_block = not is_block
else:
geometry.placeCuboid(self.editor,(x1,0,0),(x2,self.height,0),Block(self.materials[1]))
geometry.placeCuboid(self.editor,(x1,0,0),(x2-1,self.height,0),Block(self.materials[1]))
self.build_crossbars(x1, x2-1, len)
if len > 1: self.build_border_radius(x1, x2-1)
def get_size(self, max_width : int ,max_height : int) -> tuple[int,int]:
return (
@@ -83,29 +85,38 @@ class Window:
def build_crossbars(self, x1 : int, x2 : int, len : int):
if self.has_vertical_crossbar and self.height >= self.rdata["crossbars"]["min_height_for_vertical_crossbar"]:
y = self.height//2
geometry.placeCuboid(self.editor,(x1,y,0),(x2,self.height-y,0),Block(self.materials[3]))
geometry.placeCuboid(self.editor,(x1,y,0),(x2,y,0),Block(self.materials[3]))
if self.has_horizontal_crossbar and len >= self.rdata["crossbars"]["min_width_for_horizontal_crossbar"]:
pass
x = len//2
geometry.placeCuboid(self.editor,(x1+x,0,0),(x2-x,self.height,0),Block(self.materials[3], {"up" : "true"}))
def build_border_radius(self, x1 : int, x2 : int):
if self.border_radius != BORDER_RADIUS.NONE:
self.editor.placeBlock((x1,self.height,0),Block(self.materials[4], {"facing": "west", "half": "top"}))
self.editor.placeBlock((x2,self.height,0),Block(self.materials[4], {"facing": "east", "half": "top"}))
if self.border_radius == BORDER_RADIUS.TOP_AND_BOTTOM:
self.editor.placeBlock((x1,0,0),Block(self.materials[4], {"facing": "west"}))
self.editor.placeBlock((x2,0,0),Block(self.materials[4], {"facing": "east"}))
def is_grounded(self):
# if the window is grounded or if there is a padding between the window and the ground
if self.rdata["grounded"] >= rd.random(): return True
return False
return self.rdata["grounded"] >= rd.random()
def has_multiple_windows(self):
if self.width > self.rdata["size"]["max_width"]: return True
if self.width >= self.rdata["multiple"]["min_width"]:
return True
if self.rdata["multiple"]["proba"] >= rd.random(): return True
return False
elif self.width >= self.rdata["multiple"]["min_width"]:
return self.rdata["multiple"]["proba"] >= rd.random()
else : return False
def is_alternate(self):
# if the window alternate between glass_blocks and glass_panes
if self.rdata["alternate"] >= rd.random(): return True
return False
return self.rdata["alternate"] >= rd.random()
def has_crossbars(self):
# if the window has crossbars
data = self.rdata["crossbars"]
return (data["vertical_crossbar"] >= rd.random(), data["horizontal_crossbar"] >= rd.random())
return (data["vertical_crossbar"] >= rd.random(), data["horizontal_crossbar"] >= rd.random())
def border_radius(self):
return select_random(self.rdata["border_radius"], BORDER_RADIUS)