First commit

This commit is contained in:
2025-11-17 13:34:43 -06:00
commit bde690c9cb
36 changed files with 1363 additions and 0 deletions

10
4 Json/cross.json Normal file
View File

@@ -0,0 +1,10 @@
{
"info": {
"description": "Change Me",
"short_name": "changeme",
"short_name_pretty": "Change Me",
"type": "console"
},
"name": "ListsAndDictionaries",
"version": "1.0.0.0-prod"
}

14
4 Json/people.json Normal file
View File

@@ -0,0 +1,14 @@
[
{
"age": 33,
"name": "Demi Lovato"
},
{
"age": 39,
"name": "Linus Sebastion"
},
{
"age": 55,
"name": "Fred Durst"
}
]

97
4 Json/src/main.tcross Normal file
View File

@@ -0,0 +1,97 @@
func main(args)
{
while(true)
{
Console.WriteLine("Type a command");
Console.WriteLine("add: add a person");
Console.WriteLine("remove: remove a person");
Console.WriteLine("list: list all people");
Console.WriteLine("clear: clear all people");
Console.WriteLine("exit: leave");
const command = Console.ReadLine();
switch(command)
{
case "add":
{
Console.Write("Name: ");
const name = Console.ReadLine();
Console.Write("Age in years: ");
const age = ParseLong(Console.ReadLine());
if(TypeIsLong(age))
{
var people=Json.Decode(
FS.Local.FileExists("people.json") ?
FS.ReadAllText(FS.Local,"people.json") : "[]"
);
var exists = false;
each(var person : people)
{
if(person.name == name)
{
exists=true;
break;
}
}
if(!exists)
{
people.Add({
name,
age
});
FS.WriteAllText(FS.Local,"people.json", Json.Encode(people,true));
}
}
}
break;
case "remove":
{
Console.Write("Name: ");
const name = Console.ReadLine();
var people=Json.Decode(
FS.Local.FileExists("people.json") ?
FS.ReadAllText(FS.Local,"people.json") : "[]"
);
var exists = false;
each(var person : people)
{
if(person.name == name)
{
people.Remove(person);
exists=true;
break;
}
}
if(exists)
{
FS.WriteAllText(FS.Local,"people.json", Json.Encode(people,true));
}
}
break;
case "list":
{
var people=Json.Decode(
FS.Local.FileExists("people.json") ?
FS.ReadAllText(FS.Local,"people.json") : "[]"
);
each(var person : people)
{
Console.WriteLine($"Name: {person.name}");
Console.WriteLine($"Age: {person.age}");
Console.WriteLine();
}
}
break;
case "clear":
{
FS.WriteAllText(FS.Local,"people.json", Json.Encode([],true));
}
break;
case "exit":
return 0;
}
}
}