forked from sk8terkyd/digital-logic-sim-chip-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChip.py
executable file
·61 lines (40 loc) · 2.21 KB
/
Chip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/python
# Import json and os for file parsing/code to json and to filepath check.
import json
import os
class Chip:
# Description: This class is used for dealing with chips in an easier
# way.
# Arguments: str file_path
# Purpose: Retrieves and organizes the data for the Chip.
# Notes: Fully rewritten
def __init__(self, file_path):
# Load data
try:
chipFile = open(file_path)
self.chipRawData = json.load(chipFile)
chipFile.close()
except:
print("Your file was not found. Please ensure that it is in the same directory as this project, and that you are running this code in the parent directory of this project.")
quit()
# Sort data
try:
self.chipName = self.chipRawData['name']
self.chipComponents = self.chipRawData['componentNameList']
# Only keep the important things
self.componentData = []
for chipUsed in range(len(self.chipRawData['savedComponentChips'])):
# Get data of all chips used
chipUsedData = {'name': self.chipRawData['savedComponentChips'][chipUsed]['chipName'], 'inputPins': self.chipRawData['savedComponentChips'][chipUsed]['inputPins'], 'outputPinNames': self.chipRawData['savedComponentChips'][chipUsed]['outputPinNames']}
# Add data of the chips that are not built in NOT IMPLEMENTED
# if not chipUsedData['name'] in ['SIGNAL IN', 'SIGNAL OUT', 'AND', 'NOT']:
# chipUsedData['componentData'] = repr(Chip(f"{chipUsedData['name']}.txt"))
# Add data to components for this Chip
self.componentData.append(chipUsedData)
except:
print("Are you sure this is a Chip save file, in json form? Please check your save file, just in case.")
quit()
# Make formal data for Chip
self.chipData = {'name': self.chipName, 'chipComponents': self.chipComponents, 'componentData': self.componentData}
def __repr__(self):
return str(self.chipData)