Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parseSettings():
- settingsFile = open("settings.inf", "r", encoding="utf-8")
- (ball_size, ball_elasticity, ball_friction, ball_mass, rectangle_mass, rectangle_width, rectangle_height,
- rectangle_elasticity, rectangle_friction) = 0, 0, 0, 0, 0, 0, 0, 0, 0
- for i in settingsFile:
- if i == "\n":
- continue
- if "ball_size" in i:
- a = i.split()
- ball_size = float(a[2]) # 0
- elif "ball_elasticity" in i:
- a = i.split()
- ball_elasticity = float(a[2]) # 1
- elif "ball_friction" in i:
- a = i.split()
- ball_friction = float(a[2]) # 2
- elif "ball_mass" in i:
- a = i.split()
- ball_mass = float(a[2]) # 3
- elif "rectangle_mass" in i:
- a = i.split()
- rectangle_mass = float(a[2]) # 4
- elif "rectangle_width" in i:
- a = i.split()
- rectangle_width = float(a[2]) # 5
- elif "rectangle_height" in i:
- a = i.split()
- rectangle_height = float(a[2]) # 6
- elif "rectangle_elasticity" in i:
- a = i.split()
- rectangle_elasticity = float(a[2]) # 7
- elif "rectangle_friction" in i:
- a = i.split()
- rectangle_friction = float(a[2]) # 8
- return (ball_size, ball_elasticity, ball_friction, ball_mass, rectangle_mass, rectangle_width, rectangle_height,
- rectangle_elasticity, rectangle_friction)
- def testParse():
- tempSettings = parseSettings()
- print(f"Мячики\n"
- f"------\n"
- f"Радиус[0]: {tempSettings[0]}\n"
- f"Упругость[1]: {tempSettings[1]}\n"
- f"Трение[2]: {tempSettings[2]}\n"
- f"Масса[3]: {tempSettings[3]}\n"
- f"------\n")
- print(f"Прямоугольники\n"
- f"--------------\n"
- f"Масса[4]: {tempSettings[4]}\n"
- f"Ширина[5]: {tempSettings[5]}\n"
- f"Высота[6]: {tempSettings[6]}\n"
- f"Упругость[7]: {tempSettings[7]}\n"
- f"Трение[8]: {tempSettings[8]}\n"
- f"--------------\n")
- def hmm(fileText, string, value, action=True):
- fileText2 = fileText
- tempStr0 = ""
- tempStr = ""
- for i in fileText:
- tempStr = i
- if string in tempStr:
- tempStr0 = tempStr
- tempStr2 = tempStr.split()
- if action:
- tempStr2[2] = str(round(float(tempStr2[2]) + value, 1))
- else:
- tempStr2[2] = str(round(float(tempStr2[2]) - value, 1))
- tempStr = " ".join(tempStr2)
- break
- else:
- continue
- fileText2 = "\n".join(fileText2)
- fileText2 = fileText2.replace(tempStr0, tempStr)
- file = open("settings.inf", "w", encoding="utf-8")
- file.write(fileText2)
- file.close()
- def changeFileParameters(value, action=True, ball_size=False, ball_elasticity=False, ball_friction=False,
- ball_mass=False, rectangle_mass=False, rectangle_width=False,
- rectangle_height=False, rectangle_elasticity=False, rectangle_friction=False):
- tempStr0 = ""
- tempStr = ""
- file = open("settings.inf", "r", encoding="utf-8")
- fileText = file.read()
- fileText2 = fileText
- fileText = fileText.split("\n")
- file.close()
- if ball_size:
- hmm(fileText, "ball_size", value, action)
- elif ball_elasticity:
- hmm(fileText, "ball_elasticity", value, action)
- elif ball_friction:
- hmm(fileText, "ball_friction", value, action)
- elif ball_mass:
- hmm(fileText, "ball_mass", value, action)
- elif rectangle_mass:
- hmm(fileText, "rectangle_mass", value, action)
- elif rectangle_width:
- hmm(fileText, "rectangle_width", value, action)
- elif rectangle_height:
- hmm(fileText, "rectangle_height", value, action)
- return 0
- changeFileParameters(12, ball_size=True)
- testParse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement