diff --git a/cromulant/ants.py b/cromulant/ants.py index 88c78f2..ce66467 100644 --- a/cromulant/ants.py +++ b/cromulant/ants.py @@ -1,20 +1,41 @@ from __future__ import annotations -from typing import ClassVar +from typing import ClassVar, Any +from .config import Config from .utils import Utils -from .database import Database +from .storage import Storage class Ant: def __init__(self) -> None: now = Utils.now() - self.id: int self.created = now self.updated = now self.name = "" self.status = "" self.hits = 0 self.triumph = 0 + self.color: tuple[int, int, int] + + def to_dict(self) -> dict[str, Any]: + return { + "created": self.created, + "updated": self.updated, + "name": self.name, + "status": self.status, + "hits": self.hits, + "triumph": self.triumph, + "color": self.color, + } + + def from_dict(self, data: dict[str, Any]) -> None: + self.created = data["created"] + self.updated = data["updated"] + self.name = data["name"] + self.status = data["status"] + self.hits = data["hits"] + self.triumph = data["triumph"] + self.color = tuple(data["color"]) def get_name(self) -> str: return self.name or "Nameless" @@ -32,41 +53,36 @@ class Ants: ants: ClassVar[list[Ant]] = [] @staticmethod - def get_all() -> None: - Database.cursor.execute( - "SELECT id, created, updated, name, status, hits, triumph FROM ants" - ) - rows = Database.cursor.fetchall() + def prepare() -> None: + objs = Storage.get_ants() - for row in rows: + for obj in objs: ant = Ant() - ant.id = row[0] - ant.created = row[1] - ant.updated = row[2] - ant.name = row[3] - ant.status = row[4] - ant.hits = row[5] - ant.triumph = row[6] + ant.from_dict(obj) Ants.ants.append(ant) @staticmethod def hatch() -> None: + if len(Ants.ants) >= Config.max_ants: + Utils.print("Too many ants") + return + now = Utils.now() - Database.cursor.execute( - "INSERT INTO ants (created, updated) VALUES (?, ?)", - (now, now), - ) - - Database.connection.commit() - Database.cursor.execute("SELECT last_insert_rowid()") - row = Database.cursor.fetchone() - ant = Ant() - ant.id = row[0] + ant.created = now + ant.updated = now + ant.name = Utils.random_name() + ant.color = Utils.random_color() - Utils.print(f"Ant hatched: {ant.id}") + Ants.ants.append(ant) + Storage.save_ants(Ants.ants) + Utils.print(f"Ant hatched: {ant.name}") @staticmethod def terminate() -> None: pass + + @staticmethod + def get_names() -> list[str]: + return [ant.name for ant in Ants.ants] \ No newline at end of file diff --git a/cromulant/config.py b/cromulant/config.py index fbb5f8f..decb306 100644 --- a/cromulant/config.py +++ b/cromulant/config.py @@ -1,17 +1,29 @@ from pathlib import Path +import appdirs # type: ignore + class Config: title = "Cromulant" width = 800 height = 600 + max_ants = 100 here: str - database_path: Path - schema_path: Path + ants_json: Path + icon_path: Path + image_path: Path + names_json: Path @staticmethod def prepare() -> None: Config.here = Path(__file__).parent - Config.database_path = Config.here / "cromulant.db" - Config.schema_path = Config.here / "schema.sql" \ No newline at end of file + Config.ants_json = Path(appdirs.user_data_dir()) / "cromulant" / "ants.json" + + if not Config.ants_json.exists(): + Config.ants_json.parent.mkdir(parents=True, exist_ok=True) + Config.ants_json.write_text("[]") + + Config.icon_path = Config.here / "img" / "icon_4.jpg" + Config.image_path = Config.here / "img" / "icon_7.jpg" + Config.names_json = Config.here / "data" / "names.json" \ No newline at end of file diff --git a/cromulant/data/names.json b/cromulant/data/names.json new file mode 100644 index 0000000..ec3bc4f --- /dev/null +++ b/cromulant/data/names.json @@ -0,0 +1,1002 @@ +[ + "Aristotle", + "Plato", + "Jesus Christ", + "Socrates", + "Alexander the Great", + "Leonardo da Vinci", + "Confucius", + "Julius Caesar", + "Homer", + "Pythagoras", + "Archimedes", + "Moses", + "Muhammad", + "Abraham", + "Adolf Hitler", + "Wolfgang Amadeus Mozart", + "Charlemagne", + "William Shakespeare", + "Michelangelo", + "Augustus", + "Napoleon Bonaparte", + "Isaac Newton", + "Albert Einstein", + "Christopher Columbus", + "Johann Sebastian Bach", + "Dante Alighieri", + "Ludwig van Beethoven", + "Gautama Buddha", + "Cleopatra VII of Egypt", + "Martin Luther", + "Galileo Galilei", + "Herodotus", + "Paul of Tarsus", + "Augustine of Hippo", + "Euclid", + "Virgil", + "Nero", + "Thales", + "Karl Marx", + "Marco Polo", + "Cicero", + "Sophocles", + "Vincent van Gogh", + "Genghis Khan", + "Zoroaster", + "Hannibal Barca", + "Immanuel Kant", + "Hippocrates", + "Sigmund Freud", + "Pablo Picasso", + "Nefertiti", + "Solomon", + "Jeanne d'Arc", + "Qin Shi Huang", + "Aesop", + "Epicurus", + "Caligula", + "René Descartes", + "Thomas Aquinas", + "Tutankhamun", + "Johann Wolfgang von Goethe", + "Marcus Aurelius", + "Voltaire", + "Ovid", + "Niccolò Machiavelli", + "Blaise Pascal", + "Attila the Hun", + "David", + "Raphael", + "Charles Darwin", + "Che Guevara", + "Jean-Jacques Rousseau", + "Laozi", + "Mahatma Gandhi", + "Saladin", + "Saint Peter", + "Sappho", + "Aeschylus", + "Ptolemy", + "John the Baptist", + "Trajan", + "Mary Magdalene", + "Heraclitus", + "Gilgamesh", + "Vasco da Gama", + "Adam Smith", + "Elizabeth I of England", + "Horace", + "Louis XIV of France", + "Anne Boleyn", + "Ferdinand Magellan", + "Joseph Stalin", + "Ramesses II", + "Vladimir Lenin", + "Leonidas I", + "Avicenna", + "Akhenaten", + "Johannes Gutenberg", + "Euripides", + "Seneca the Younger", + "Albrecht Dürer", + "Pericles", + "Sun Tzu", + "Hadrian", + "Judas Iscariot", + "Mark Antony", + "Hammurabi", + "John Locke", + "Democritus", + "Aristophanes", + "Martin Luther King, Jr.", + "Plutarch", + "Friedrich Nietzsche", + "Victor Hugo", + "Imhotep", + "Elvis Presley", + "Salvador Dalí", + "Richard Wagner", + "Constantine I", + "Molière", + "Benito Mussolini", + "Hesiod", + "Xerxes I of Persia", + "Tiberius", + "Oscar Wilde", + "Francisco Goya", + "Peter Paul Rubens", + "Claude Monet", + "Diogenes of Sinope", + "Diocletian", + "Eratosthenes", + "Frédéric Chopin", + "Henry VIII of England", + "Mao Zedong", + "Marie Antoinette", + "Carl Friedrich Gauss", + "Giuseppe Verdi", + "Otto von Bismarck", + "Caravaggio", + "Isaac", + "Justinian I", + "Marilyn Monroe", + "Georg Wilhelm Friedrich Hegel", + "Sandro Botticelli", + "Giordano Bruno", + "Cyrus the Great", + "Louis Pasteur", + "Commodus", + "Spartacus", + "George Frideric Handel", + "Carl Linnaeus", + "Nostradamus", + "Darius I of Persia", + "Xenophon", + "Petrarch", + "Giovanni Boccaccio", + "Fyodor Dostoyevsky", + "Theodosius I", + "Elijah", + "Solon", + "Strabo", + "Max Weber", + "Leo Tolstoy", + "Thomas Hobbes", + "Khufu", + "Thucydides", + "Gottfried Wilhelm von Leibniz", + "Tacitus", + "John Calvin", + "Walt Disney", + "Thomas More", + "Le Corbusier", + "Vespasian", + "Jean-Paul Sartre", + "Johannes Kepler", + "Aleksandr Pushkin", + "Anaximander", + "Desiderius Erasmus", + "Suleiman the Magnificent", + "Winston Churchill", + "Nebuchadrezzar II", + "Parmenides", + "Johannes Vermeer", + "Ali", + "James Cook", + "Benjamin Franklin", + "Edgar Allan Poe", + "Joseph Haydn", + "Honoré de Balzac", + "Li Bai", + "Giotto di Bondone", + "George Washington", + "Donatello", + "Thomas Edison", + "Galen", + "Titian", + "Baruch Spinoza", + "Francis of Assisi", + "James Watt", + "Timur", + "Claudius", + "Sima Qian", + "Anton Chekhov", + "Protagoras", + "Hernán Cortés", + "Nicolaus Copernicus", + "Abraham Lincoln", + "Michael Faraday", + "Jimi Hendrix", + "Andy Warhol", + "Methuselah", + "Du Fu", + "Antonio Vivaldi", + "Phidias", + "Zeno of Elea", + "Empedocles", + "Mother Teresa", + "El Greco", + "Paracelsus", + "Bob Marley", + "Anaxagoras", + "Clovis I", + "Miguel de Cervantes", + "Philip II of Macedon", + "Charles V, Holy Roman Emperor", + "Marcel Proust", + "Plotinus", + "Averroes", + "Leonardo Fibonacci", + "Hieronymus Bosch", + "David Hume", + "Bruce Lee", + "Pompey", + "Charles de Gaulle", + "Septimius Severus", + "Pliny the Elder", + "Peter I of Russia", + "Bob Dylan", + "Antoninus Pius", + "Arthur Schopenhauer", + "Francisco Franco", + "Charlie Chaplin", + "Josephus", + "Hermann Hesse", + "Caracalla", + "Friedrich Engels", + "Saint Andrew", + "Rembrandt", + "William Wallace", + "Marcus Vitruvius Pollio", + "Paul Gauguin", + "Vercingetorix", + "Saint George", + "Heinrich Himmler", + "Pindar", + "Louis XVI of France", + "Johannes Brahms", + "Saint James the Great", + "John F. Kennedy", + "George Orwell", + "Mustafa Kemal Atatürk", + "Charles Martel", + "Thomas Mann", + "Diogenes Laertius", + "Marcus Vipsanius Agrippa", + "Pyrrhus of Epirus", + "Omar Khayyám", + "Alfred Nobel", + "Queen of Sheba", + "Marcus Junius Brutus", + "Donatien Alphonse François de Sade, Marquis de Sade", + "Romulus Augustus", + "Demosthenes", + "James Joyce", + "Francis Bacon", + "Johann Christoph Friedrich von Schiller", + "Fidel Castro", + "Mark Twain", + "Joseph Goebbels", + "Marie Curie", + "Aaron", + "Richard I of England", + "Lucius Cornelius Sulla", + "Bertolt Brecht", + "Pontius Pilate", + "Ernest Hemingway", + "Muhammad ibn Musa al-Khwarizmi", + "Jan Hus", + "Charles Baudelaire", + "Saddam Hussein", + "Hans Christian Andersen", + "Mary I of Scotland", + "Umar", + "John Maynard Keynes", + "Antonín Dvořák", + "Darius III of Persia", + "Ludwig Wittgenstein", + "Cato the Elder", + "Stanley Kubrick", + "Lucretius", + "Jack the Ripper", + "Cao Cao", + "Francis Drake", + "Nicholas II of Russia", + "Frida Kahlo", + "Amerigo Vespucci", + "Gabriel García Márquez", + "Catullus", + "Plautus", + "John Lennon", + "Narmer", + "Hypatia of Alexandria", + "Guan Yu", + "Thomas Jefferson", + "Daniel Defoe", + "Hermann Göring", + "Vlad III the Impaler", + "Catherine II of Russia", + "Napoleon III of France", + "Pierre-Auguste Renoir", + "Marlon Brando", + "Pelé", + "Pope John Paul II", + "Bertrand Russell", + "Hero of Alexandria", + "Polybius", + "Herod the Great", + "Émile Zola", + "Pippin the Younger", + "Henry Ford", + "Thutmose III", + "Denis Diderot", + "Charles de Secondat, baron de Montesquieu", + "Giacomo Casanova", + "James, son of Alphaeus", + "Oliver Cromwell", + "Djoser", + "Ptolemy I Soter", + "Franklin D. Roosevelt", + "Henri Matisse", + "Henrik Ibsen", + "Gaius Marius", + "Kublai Khan", + "Horatio Nelson, 1st Viscount Nelson", + "Zhuge Liang", + "Otho", + "Job", + "Ishmael", + "Anaximenes of Miletus", + "Hugh Capet of France", + "Arthur Rimbaud", + "Vitellius", + "Francisco Pizarro", + "Nikola Tesla", + "Alessandro Volta", + "Benedict of Nursia", + "Galba", + "Pierre Abélard", + "Mikhail Gorbachev", + "Oda Nobunaga", + "Odoacer", + "Jerome", + "Gian Lorenzo Bernini", + "Édith Piaf", + "Elizabeth II of the United Kingdom", + "Max Planck", + "William Blake", + "Johnny Cash", + "Ingmar Bergman", + "Suetonius", + "Leon Trotsky", + "Gorgias", + "Titus", + "Japheth", + "Philip II of Spain", + "Ivan IV of Russia", + "Émile Durkheim", + "Auguste Comte", + "Michel Foucault", + "Louis Armstrong", + "Carl Jung", + "Édouard Manet", + "Stephen King", + "Stendhal", + "Giacomo Puccini", + "Al Pacino", + "Josip Broz Tito", + "Louis the Pious", + "Khafra", + "Marlene Dietrich", + "Aristarchus of Samos", + "Gustav Mahler", + "Pablo Neruda", + "Ronald Reagan", + "Isaac Asimov", + "Eugène Delacroix", + "Mary I of England", + "Luke the Evangelist", + "Franz Kafka", + "Hirohito", + "Origen", + "Xenophanes", + "Mencius", + "Rachel", + "Erwin Rommel", + "Hokusai", + "Abu Bakr", + "Karl Popper", + "Maximilien Robespierre", + "Arthur Conan Doyle", + "Tertullian", + "Ramesses I", + "Woody Allen", + "Alfred Hitchcock", + "Frank Lloyd Wright", + "Frank Sinatra", + "Nikolai Gogol", + "Michel de Montaigne", + "Jan van Eyck", + "Rosa Luxemburg", + "Audrey Hepburn", + "Coco Chanel", + "Robert Alexander Schumann", + "Dmitri Mendeleev", + "Frederick I, Holy Roman Emperor", + "Tokugawa Ieyasu", + "Pyotr Ilyich Tchaikovsky", + "Franz Schubert", + "Simón Bolívar", + "Pliny the Younger", + "Jean de La Fontaine", + "Pope Gregory I", + "Seti I", + "John of England", + "Epictetus", + "Jean Piaget", + "Saint Nicholas", + "Clint Eastwood", + "Saint Joseph", + "John Forbes Nash", + "Aurelian", + "George Gordon Noel Byron, 6th Baron Byron", + "Numa Pompilius", + "Antoine Lavoisier", + "Zheng He", + "Maria Theresa of Austria", + "Claudio Monteverdi", + "Anne Frank", + "Paul McCartney", + "Catherine of Aragon", + "Agatha Christie", + "El Cid", + "Maurice Ravel", + "Niccolò Paganini", + "Simone de Beauvoir", + "Wilhelm II", + "Franz Liszt", + "Louis XV of France", + "Mark the Evangelist", + "Alcibiades", + "Nelson Mandela", + "Wilhelm Conrad Röntgen", + "Mehmed II", + "Emperor Jimmu", + "John Dalton", + "Nikita Khrushchev", + "Maimonides", + "Constantius Chlorus", + "Luciano Pavarotti", + "Al Capone", + "Isidore of Seville", + "Edgar Degas", + "Stephen Hawking", + "Richard Nixon", + "Florence Nightingale", + "Anselm of Canterbury", + "Christiaan Huygens", + "Giuseppe Garibaldi", + "Edvard Grieg", + "Sarah", + "Dido", + "Samson", + "Theodoric the Great", + "Gallienus", + "Ibn Khaldun", + "Shem", + "Hildegard of Bingen", + "Mata Hari", + "Robert De Niro", + "Croesus", + "Umberto Eco", + "Zeno of Citium", + "Samuel Beckett", + "Jack Nicholson", + "Liu Bei", + "John Chrysostom", + "James Clerk Maxwell", + "Amenhotep III", + "Fu Hsi", + "George Bernard Shaw", + "Jack London", + "Arnold Schwarzenegger", + "Ernest Rutherford", + "Louis XIII of France", + "Saul the King", + "Yellow Emperor", + "Jonathan Swift", + "Alexander von Humboldt", + "Alexander Graham Bell", + "Tycho Brahe", + "Levi", + "Philip IV of France", + "Catherine de' Medici", + "John Stuart Mill", + "Terence", + "Hector Berlioz", + "Jane Austen", + "J. R. R. Tolkien", + "Edvard Munch", + "Jean Auguste Dominique Ingres", + "Eric Clapton", + "Roald Amundsen", + "Alexander Fleming", + "Praxiteles", + "Isaiah", + "Charles Dickens", + "Louis IX of France", + "Ambrose", + "Charles Perrault", + "Jalal ad-Din Muhammad Rumi", + "Macrinus", + "Apuleius", + "Enrico Fermi", + "John von Neumann", + "Heinrich Heine", + "Theophrastus", + "Astrid Lindgren", + "Silvio Berlusconi", + "Godfrey of Bouillon", + "Pol Pot", + "Alaric I", + "Noam Chomsky", + "Jacques-Louis David", + "Constantius II", + "Ignatius of Loyola", + "Leonid Brezhnev", + "Elizabeth Báthory", + "Jim Morrison", + "Antoni Gaudí", + "Felix Mendelssohn-Bartholdy", + "William the Conqueror", + "Arius", + "Jules Verne", + "Decius", + "Robert Koch", + "Johann Pachelbel", + "Robert Hooke", + "Boris Yeltsin", + "Ray Charles", + "Petronius", + "Arminius", + "Bernard of Clairvaux", + "Gaius Maecenas", + "Charles the Bald, Holy Roman Emperor", + "André-Marie Ampère", + "Henri Bergson", + "Chiang Kai-shek", + "Richard Strauss", + "Lewis Carroll", + "Ferdinand de Saussure", + "Chuck Norris", + "Albertus Magnus", + "Leucippus", + "Aleister Crowley", + "Evangelista Torricelli", + "Rudolf Steiner", + "Masaccio", + "Hatshepsut", + "Nefertari", + "Josef Mengele", + "Melchizedek", + "Menander", + "Pope Clement I", + "Filippo Brunelleschi", + "Ashoka", + "George Harrison", + "Andrea Palladio", + "Horemheb", + "Harry S. Truman", + "Maxim Gorky", + "Virginia Woolf", + "Quintilian", + "Roger Bacon", + "Bedřich Smetana", + "François Rabelais", + "Gordian III", + "Tintoretto", + "Esau", + "George Sand", + "Hipparchus", + "Juvenal", + "Anders Celsius", + "Sneferu", + "Bartholomäus", + "Hamilcar Barca", + "David Ricardo", + "Brigitte Bardot", + "Steven Spielberg", + "Pope Benedict XVI", + "Albert Camus", + "Dwight D. Eisenhower", + "Arcadius", + "Paul von Hindenburg", + "Federico García Lorca", + "Hor-Aha", + "Miyamoto Musashi", + "Huang Xian Fan", + "Belisarius", + "Snorri Sturluson", + "Rudyard Kipling", + "Geoffrey Chaucer", + "Diodorus Siculus", + "Ashurbanipal", + "Caspar David Friedrich", + "Georges Bizet", + "Julius Nepos", + "Al-Farabi", + "Adolf Eichmann", + "Saint Christopher", + "Lucius Tarquinius Superbus", + "Eusebius of Caesarea", + "William of Ockham", + "Saint Anne", + "Saint Jude", + "Sun Yat-sen", + "Cardinal Richelieu", + "Lech Wałęsa", + "Henri de Toulouse-Lautrec", + "Theodore Roosevelt", + "Alexander Severus", + "Erik the Red", + "Georg Ohm", + "Milan Kundera", + "Freddie Mercury", + "Ivan Pavlov", + "J. M. W. Turner", + "Gustave Eiffel", + "James Prescott Joule", + "Manetho", + "Pope Alexander VI", + "Federico Fellini", + "Ringo Starr", + "Theodosius II", + "Basil of Caesarea", + "Servius Tullius", + "Amedeo Modigliani", + "Osman I", + "Hayao Miyazaki", + "Joan Miró", + "Guglielmo Marconi", + "Sylvester Stallone", + "Ho Chi Minh", + "Piero della Francesca", + "Aisha bint Abu Bakr", + "Anthony the Great", + "Helena of Constantinople", + "Germanicus", + "Rainer Maria Rilke", + "Joshua", + "Grigori Rasputin", + "Robert Boyle", + "Henry III of France", + "Anacreon", + "Nimrod", + "Anton Bruckner", + "François Villon", + "Sargon of Akkad", + "Murasaki Shikibu", + "Heraclius", + "Lucius Verus", + "Henry IV of France", + "Fra Angelico", + "James Dean", + "Harun al-Rashid", + "Diego Velázquez", + "André Gide", + "Sarah Bernhardt", + "Merneptah", + "Comenius", + "Augusto Pinochet", + "Paul Verlaine", + "Helen Keller", + "Flavius Aëtius", + "Cambyses II of Persia", + "Jean Sibelius", + "Gustave Flaubert", + "Albert Schweitzer", + "Alfred the Great", + "Bartolomeu Dias", + "Karl Dönitz", + "Antisthenes", + "Epaminondas", + "Otto I, Holy Roman Emperor", + "Giorgione", + "Marcel Duchamp", + "Lady Godiva", + "Gustave Courbet", + "Sean Connery", + "Pierre-Simon Laplace", + "Warren Buffett", + "Knut Hamsun", + "Miles Davis", + "Nicolas Poussin", + "Erich Fromm", + "Tina Turner", + "Pieter Brueghel the Elder", + "Peisistratos", + "Jacques Offenbach", + "Jimmy Carter", + "Edward VI of England", + "Philip the Arab", + "Anicius Manlius Severinus Boethius", + "Toyotomi Hideyoshi", + "Claudius II", + "Pope Urban II", + "Catiline", + "Franz Joseph I of Austria", + "John Milton", + "Lady Jane Grey", + "Yasser Arafat", + "Henry Dunant", + "Leone Battista Alberti", + "Alexander IV of Macedon", + "Manco Capac", + "Walter Scott", + "Philip II of France", + "George H. W. Bush", + "Didius Julianus", + "William Faulkner", + "Eva Braun", + "Wassily Kandinsky", + "Menes", + "Jacques Cartier", + "Nagarjuna", + "Ibn Battuta", + "Pope Silvester I", + "Ammianus Marcellinus", + "Sallust", + "Al-Ghazali", + "Zhang Fei", + "Philo", + "Diophantus", + "Béla Bartók", + "Anthony of Padua", + "Catherine of Alexandria", + "H. P. Lovecraft", + "Joseph of Arimathea", + "Sophia Loren", + "Tullus Hostilius", + "John the Evangelist", + "Nicholas of Cusa", + "Antonio Salieri", + "Abu Nuwas", + "Agrippina the Younger", + "Octave Mirbeau", + "Julian the Apostate", + "Madame de Pompadour", + "Valentinian I", + "Ptolemy II Philadelphus", + "Carus", + "Carinus", + "Menkaura", + "Giuseppe Arcimboldo", + "Jean Racine", + "Kofi Annan", + "Alvar Aalto", + "Bill Gates", + "Thutmose I", + "Jean-Baptiste Lamarck", + "Janis Joplin", + "Antoine de Saint-Exupéry", + "Ivan Turgenev", + "Bernhard Riemann", + "Charles Bukowski", + "Georg Philipp Telemann", + "Wu Zetian", + "Batu Khan", + "Paul Klee", + "Guy de Maupassant", + "Themistocles", + "Erich Maria Remarque", + "Dio Cassius", + "Louis XVIII of France", + "Martin of Tours", + "Bernard Montgomery, 1st Viscount Montgomery of Alamein", + "Valens", + "Malcolm X", + "Anthony Hopkins", + "Rudolf Hess", + "Paolo Veronese", + "Caesarion", + "Cato the Younger", + "Anatole France", + "Gaozu of Han", + "Diogenes Apolloniates", + "Piet Mondrian", + "Francis I of France", + "Frank Zappa", + "Nasreddin", + "Shennong", + "Irenaeus", + "Uthman ibn Affan", + "Reinhard Heydrich", + "John Wayne", + "Pyrrho", + "Mikhail Bakunin", + "Emily Brontë", + "Milton Friedman", + "Trebonianus Gallus", + "Woodrow Wilson", + "Clement of Alexandria", + "Bill Clinton", + "Thomas the Apostle", + "Abraham Maslow", + "Jacques Chirac", + "Edmund Husserl", + "Joseph Conrad", + "Pepi II Neferkare", + "Rudolf Diesel", + "Domenico Scarlatti", + "Ennio Morricone", + "Polykleitos", + "Bathsheba", + "Akihito", + "Antonio Stradivari", + "Yuri Andropov", + "Seleucus I Nicator", + "Wilhelm Keitel", + "Elagabalus", + "Ancus Marcius", + "Lysippos", + "Leif Ericson", + "Quintillus", + "Søren Kierkegaard", + "Sitting Bull", + "Robert Baden-Powell, 1st Baron Baden-Powell", + "Philip the Apostle", + "Sergei Rachmaninoff", + "Eva Perón", + "Orson Welles", + "Skanderbeg", + "Cleisthenes", + "Jean Cocteau", + "Vladimir Vladimirovich Nabokov", + "Jürgen Habermas", + "Simon the Zealot", + "Akira Kurosawa", + "Pierre Curie", + "Pope Gregory VII", + "Alexander I of Russia", + "Stefan Zweig", + "Darius II of Persia", + "Dmitri Shostakovich", + "Maurice Maeterlinck", + "Antigonus I Monophthalmus", + "Leonhard Euler", + "Eleanor of Aquitaine", + "Martial", + "Emperor Wu of Han", + "Artaxerxes II of Persia", + "Leni Riefenstahl", + "Guillaume Apollinaire", + "John Dewey", + "George Berkeley", + "Lucian", + "Pope Innocent III", + "Camille Pissarro", + "Ulfilas", + "Roxelana", + "Paulo Coelho", + "Ahmose I", + "Theodor Mommsen", + "Archduke Franz Ferdinand of Austria", + "Erik Satie", + "Alexander II of Russia", + "James Brown", + "Leonard Cohen", + "Greta Garbo", + "Girolamo Savonarola", + "Cassander", + "Pope Julius II", + "Valentinian III", + "Alexander Nevsky", + "Chuck Berry", + "Edward I of England", + "John Steinbeck", + "George Gershwin", + "Ferdowsi", + "Henry Purcell", + "Oskar Schindler", + "Thomas Malthus", + "Muhammad Ali", + "Johann Gottlieb Fichte", + "Dustin Hoffman", + "Juan Carlos I of Spain", + "Donato Bramante", + "Salvador Allende", + "Harrison Ford", + "Neil Armstrong", + "Antoine Henri Becquerel", + "Charles V of France", + "Padmasambhava", + "Bayezid I", + "Jimmy Page", + "Jean-Baptiste Lully", + "Camille Saint-Saëns", + "Basil II", + "Roxana", + "Gustave Doré", + "David Bowie", + "Giorgio Vasari", + "Antiochus III the Great", + "Heinrich Böll", + "Martin Bormann", + "Aristippus", + "Isocrates", + "Djer", + "Ingrid Bergman", + "Ludwig Andreas Feuerbach", + "Seth", + "Novalis", + "Carl Maria von Weber", + "Romain Rolland", + "David Hilbert", + "Cimabue", + "Pertinax", + "Tomaso Albinoni", + "Frederick II, Holy Roman Emperor", + "Apelles", + "Hu Jintao", + "Marcus Terentius Varro", + "Pier Paolo Pasolini", + "Charles Manson", + "Absalom", + "Modest Petrovich Mussorgsky", + "Alain Delon", + "Ozzy Osbourne", + "Lysimachus", + "Archilochus", + "Giovanni Pierluigi da Palestrina", + "Herod Antipas", + "Charles Babbage", + "Joséphine de Beauharnais", + "Louis the German", + "Artaxerxes I of Persia", + "Konrad Adenauer", + "Andrea Mantegna", + "Joseph Fourier", + "Smenkhkare", + "John the Apostle", + "Joseph Louis Lagrange", + "Cai Lun", + "Marcion of Sinope", + "Frederick II of Prussia", + "Gregor Mendel", + "Gaetano Donizetti", + "Pocahontas", + "Johann Heinrich Pestalozzi", + "Maximinus Thrax", + "Cleopatra I of Egypt", + "Lothair I", + "Nicholas Flamel", + "Sun Quan", + "Walter Benjamin", + "Christoph Willibald Gluck", + "Olympias", + "Apollonius of Rhodes", + "Elias Canetti", + "Philip IV of Spain", + "Pope Urban I", + "Pope Leo X", + "Archytas", + "Cao Pi", + "Herbert Spencer", + "Philip III of Spain", + "Vincenzo Bellini", + "Zhu Xi", + "Francis Ford Coppola", + "Galerius", + "Tarquinius Priscus", + "Jean-Paul Marat", + "Idi Amin", + "Mozi", + "Jacques de Molay", + "Antinous", + "Gustav I of Sweden", + "Ariel Sharon", + "Yukio Mishima", + "Theocritus", + "Emperor Meiji" +] \ No newline at end of file diff --git a/cromulant/database.py b/cromulant/database.py deleted file mode 100644 index f7ecb08..0000000 --- a/cromulant/database.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import annotations - -import sqlite3 -from pathlib import Path - -from .config import Config - - -class Database: - connection: sqlite3.Connection - cursor: sqlite3.Cursor - - @staticmethod - def prepare() -> None: - Database.connection = sqlite3.connect(Config.database_path) - Database.cursor = Database.connection.cursor() - - @staticmethod - def create() -> None: - with Config.schema_path.open("r") as file: - schema = file.read() - - Database.cursor.executescript(schema) - Database.connection.commit() diff --git a/cromulant/game.py b/cromulant/game.py index 7b06bd2..153939e 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -1,11 +1,40 @@ +from PySide6.QtWidgets import QWidget +from PySide6.QtGui import QColor +from PySide6.QtGui import QPainter +from PySide6.QtCore import Qt +from PySide6.QtWidgets import QHBoxLayout +from PySide6.QtWidgets import QLabel + +from .ants import Ants from .window import Window + +class CircleWidget(QWidget): + def __init__(self, color, parent=None): + super().__init__(parent) + self.color = QColor(*color) + self.setFixedSize(20, 20) + + def paintEvent(self, event): + painter = QPainter(self) + painter.setRenderHint(QPainter.Antialiasing) + painter.setBrush(self.color) + painter.setPen(Qt.NoPen) + painter.drawEllipse(0, 0, self.width(), self.height()) + + class Game: @staticmethod def update_view() -> None: - scene = Window.view.scene() - scene.addRect(0, 0, 10, 10) - scene.addRect(10, 10, 10, 10) - scene.addRect(20, 20, 10, 10) - scene.addRect(30, 30, 10, 10) - scene.addRect(40, 40, 10, 10) \ No newline at end of file + for ant in Ants.ants: + container = QHBoxLayout() + circle = CircleWidget(ant.color) + text = QLabel(ant.status) + container.addWidget(circle) + container.addWidget(text) + Window.view.addLayout(container) + + + @staticmethod + def log(message: str) -> None: + Window.log.append(message) \ No newline at end of file diff --git a/cromulant/img/icon_1.jpg b/cromulant/img/icon_1.jpg new file mode 100644 index 0000000..7263e01 Binary files /dev/null and b/cromulant/img/icon_1.jpg differ diff --git a/cromulant/img/icon_2.jpg b/cromulant/img/icon_2.jpg new file mode 100644 index 0000000..aca7a33 Binary files /dev/null and b/cromulant/img/icon_2.jpg differ diff --git a/cromulant/img/icon_3.jpg b/cromulant/img/icon_3.jpg new file mode 100644 index 0000000..29198eb Binary files /dev/null and b/cromulant/img/icon_3.jpg differ diff --git a/cromulant/img/icon_4.jpg b/cromulant/img/icon_4.jpg new file mode 100644 index 0000000..0aa4585 Binary files /dev/null and b/cromulant/img/icon_4.jpg differ diff --git a/cromulant/img/icon_5.jpg b/cromulant/img/icon_5.jpg new file mode 100644 index 0000000..35e68e9 Binary files /dev/null and b/cromulant/img/icon_5.jpg differ diff --git a/cromulant/img/icon_6.jpg b/cromulant/img/icon_6.jpg new file mode 100644 index 0000000..68df6f6 Binary files /dev/null and b/cromulant/img/icon_6.jpg differ diff --git a/cromulant/img/icon_7.jpg b/cromulant/img/icon_7.jpg new file mode 100644 index 0000000..27c7fcc Binary files /dev/null and b/cromulant/img/icon_7.jpg differ diff --git a/cromulant/main.py b/cromulant/main.py index 3eae4ee..86bd654 100644 --- a/cromulant/main.py +++ b/cromulant/main.py @@ -1,23 +1,16 @@ from __future__ import annotations from .config import Config -from .database import Database -from .window import Window +from .utils import Utils from .ants import Ants +from .window import Window def main() -> None: Config.prepare() - Database.prepare() - Database.create() - - Ants.get_all() - - Window.make() - Window.add_buttons() - Window.add_view() - Window.add_log() - Window.start() + Utils.prepare() + Ants.prepare() + Window.prepare() if __name__ == "__main__": diff --git a/cromulant/schema.sql b/cromulant/schema.sql deleted file mode 100644 index c16d285..0000000 --- a/cromulant/schema.sql +++ /dev/null @@ -1,22 +0,0 @@ -CREATE TABLE IF NOT EXISTS ants ( - -- Internal ID of the ant - id INTEGER PRIMARY KEY AUTOINCREMENT, - - -- The date when the ant was created - created INTEGER NOT NULL DEFAULT 0, - - -- The date when the ant was last changed - updated INTEGER NOT NULL DEFAULT 0, - - -- The public name of the ant - name TEXT NOT NULL DEFAULT "", - - -- The current text of the ant - status TEXT NOT NULL DEFAULT "", - - -- The total number of hits taken - hits INTEGER NOT NULL DEFAULT 0, - - -- The total number of triumph achieved - triumph INTEGER NOT NULL DEFAULT 0 -); \ No newline at end of file diff --git a/cromulant/storage.py b/cromulant/storage.py new file mode 100644 index 0000000..231ca46 --- /dev/null +++ b/cromulant/storage.py @@ -0,0 +1,26 @@ +import json +from typing import TYPE_CHECKING + +from .config import Config + +if TYPE_CHECKING: + from .ants import Ant + + +class Storage: + @staticmethod + def get_ants() -> None: + with Config.ants_json.open() as file: + return json.load(file) + + @staticmethod + def save_ants(ants: list["Ant"]) -> None: + objs = [ant.to_dict() for ant in ants] + + with Config.ants_json.open("w") as file: + json.dump(objs, file) + + @staticmethod + def get_names() -> None: + with Config.names_json.open() as file: + return json.load(file) \ No newline at end of file diff --git a/cromulant/utils.py b/cromulant/utils.py index f91540b..db9ea87 100644 --- a/cromulant/utils.py +++ b/cromulant/utils.py @@ -1,7 +1,16 @@ +import random +import colorsys import time +from .storage import Storage class Utils: + names: list[str] = [] + + @staticmethod + def prepare() -> None: + Utils.names = Storage.get_names() + @staticmethod def now() -> float: return int(time.time()) @@ -53,3 +62,17 @@ class Utils: @staticmethod def print(text: str) -> None: print(text) # noqa: T201 + + @staticmethod + def random_color() -> str: + h,s,l = random.random(), 0.5 + random.random()/2.0, 0.4 + random.random()/5.0 + r, g, b = [int(256*i) for i in colorsys.hls_to_rgb(h,l,s)] + return r, g, b + + @staticmethod + def random_name() -> str: + from .ants import Ants + + used = Ants.get_names() + filtered = [name for name in Utils.names if name not in used] + return random.choice(filtered) \ No newline at end of file diff --git a/cromulant/window.py b/cromulant/window.py index 8712735..48e0e49 100644 --- a/cromulant/window.py +++ b/cromulant/window.py @@ -9,6 +9,10 @@ from PySide6.QtWidgets import QVBoxLayout from PySide6.QtWidgets import QPushButton from PySide6.QtWidgets import QHBoxLayout from PySide6.QtWidgets import QTextEdit +from PySide6.QtWidgets import QLabel +from PySide6.QtGui import QPixmap +from PySide6.QtGui import QIcon +from PySide6.QtCore import Qt from .config import Config @@ -18,8 +22,17 @@ class Window: window: QMainWindow root: QHBoxLayout view: QGraphicsView + view_scene: QGraphicsScene log: QTextEdit + @staticmethod + def prepare() -> None: + Window.make() + Window.add_buttons() + Window.add_view() + Window.add_log() + Window.start() + @staticmethod def make() -> None: Window.app = QApplication([]) @@ -31,37 +44,51 @@ class Window: Window.root = QVBoxLayout() central_widget.setLayout(Window.root) Window.window.setCentralWidget(central_widget) + Window.window.setWindowIcon(QIcon(str(Config.icon_path))) + Window.app.setStyleSheet("QWidget { background-color: #3c3681; color: #FFF; }") @staticmethod def add_buttons() -> None: btn_hatch = QPushButton("Hatch") btn_terminate = QPushButton("Terminate") btn_update = QPushButton("Update") + btn_close = QPushButton("Close") btn_hatch.clicked.connect(Window.hatch) btn_terminate.clicked.connect(Window.terminate) btn_update.clicked.connect(Window.update_view) + btn_close.clicked.connect(Window.close) layout = QHBoxLayout() layout.addWidget(btn_hatch) layout.addWidget(btn_terminate) layout.addWidget(btn_update) + layout.addWidget(btn_close) Window.root.addLayout(layout) @staticmethod def add_view() -> None: - Window.view = QGraphicsView() - scene = QGraphicsScene() - Window.view.setScene(scene) - Window.root.addWidget(Window.view) + Window.view = QVBoxLayout() + Window.root.addLayout(Window.view) @staticmethod def add_log() -> None: + container = QHBoxLayout() + + image_label = QLabel() + pixmap = QPixmap(str(Config.image_path)) + scaled_pixmap = pixmap.scaled(100, pixmap.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation) + image_label.setPixmap(scaled_pixmap) + image_label.setFixedWidth(100) + container.addWidget(image_label) + Window.log = QTextEdit() Window.log.setReadOnly(True) Window.log.setFixedHeight(100) - Window.root.addWidget(Window.log) + container.addWidget(Window.log) + + Window.root.addLayout(container) @staticmethod def update_view() -> None: @@ -82,3 +109,7 @@ class Window: def start() -> None: Window.window.show() Window.app.exec() + + @staticmethod + def close() -> None: + Window.app.quit() diff --git a/requirements.txt b/requirements.txt index 09c5122..35345fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -PySide6 == 6.7.2 \ No newline at end of file +PySide6 == 6.7.2 +appdirs == 1.4.4 \ No newline at end of file