diff --git a/luasrc/app.lua b/luasrc/app.lua index 5741c98..029db5c 100644 --- a/luasrc/app.lua +++ b/luasrc/app.lua @@ -14,6 +14,7 @@ require 'levels.seven_seg' require 'levels.bus' require 'levels.mof3' require 'levels.simple_ram' +require 'levels.custom_components_example' require 'levels.collatz' require 'levels.gcd' require 'levels.riscv_alu' diff --git a/luasrc/imgs/levels/chain_guy_image.png b/luasrc/imgs/levels/chain_guy_image.png new file mode 100644 index 0000000..55b2528 Binary files /dev/null and b/luasrc/imgs/levels/chain_guy_image.png differ diff --git a/luasrc/imgs/levels/custom_example_level.png b/luasrc/imgs/levels/custom_example_level.png new file mode 100644 index 0000000..7f0d220 Binary files /dev/null and b/luasrc/imgs/levels/custom_example_level.png differ diff --git a/luasrc/levels/custom_components_example.lua b/luasrc/levels/custom_components_example.lua new file mode 100644 index 0000000..8b1d0ed --- /dev/null +++ b/luasrc/levels/custom_components_example.lua @@ -0,0 +1,61 @@ +local LevelComponent = require 'level_component' +local Clock = require 'clock' + +local BasicKeyboard = require 'component_examples.basic_keyboard' +local BasicROM = require 'component_examples.basic_rom' +local BasicRAM = require 'component_examples.basic_ram' +local BasicRAMDisplay = require 'component_examples.basic_ram_display' + +local chips = {} +table.insert(chips, Clock(false)) +table.insert(chips, BasicKeyboard()) +table.insert(chips, BasicROM()) + +-- Here's an example on how to share data between components: +-- Our "display" component directly access the memory from the RAM component, +-- that doesnt even know the display exists. In this specific case it assumes +-- the table "memory" is created in the constructor of the ram component, but +-- a callback could also be used. +-- Mind also that you can have components that dont directly interact with the +-- image chip (the ramdisplay here has an "display_offset" pin input, but it +-- could have no pin and it would still work) +local ram = BasicRAM() +local ramDisplay = BasicRAMDisplay(ram.memory, 16, 16) +table.insert(chips, ram) +table.insert(chips, ramDisplay) + + +addLevel({ + id='CUSTOMCOMP', + icon = "../luasrc/imgs/levels/custom_example_level.png", + name = 'Custom Components Example', + unlockedBy='RAM8', + desc = [[ + +!img:imgs/levels/chain_guy_image.png + +Example level with custom components. No objective. + +The idea is to show how the user can extend Circuit Artist to add its own levels and components to interact with the circuit (for example, if you want to add instructions for a custom CPU). + +You have an example of custom (reusable) components such as: + +- A WASD Keyboard input +- A ROM component +- A RAM component +- A RAM Display component + +You can create your own components and levels in the `luasrc/scripts/` folder of your game installation. (if the folder is not there you can create one from the template in `luasrc/template_scripts/`) + +You can look at the `luasrc/` folder for references/examples. + +The game will look for the `scripts/init.lua` script at initialization, so you can import/register your levels and scripts from there. + +You can open the game folder in steam via right click on the game name in "library", then go to "Manage" -> "Browse Local Files". + +`Attention:` Mind not modifying scripts outside the `luasrc/scripts/` folder because they are overidden in updates. +]], + chips = chips, +}) + + diff --git a/luasrc/levels/sandbox.lua b/luasrc/levels/sandbox.lua index b907c5a..b72c704 100644 --- a/luasrc/levels/sandbox.lua +++ b/luasrc/levels/sandbox.lua @@ -1,36 +1,11 @@ local LevelComponent = require 'level_component' local Clock = require 'clock' -local BasicKeyboard = require 'component_examples.basic_keyboard' -local BasicROM = require 'component_examples.basic_rom' -local BasicRAM = require 'component_examples.basic_ram' -local BasicRAMDisplay = require 'component_examples.basic_ram_display' - -local chips = {} -table.insert(chips, Clock(false)) -table.insert(chips, BasicKeyboard()) -table.insert(chips, BasicROM()) - --- Here's an example on how to share data between components: --- Our "display" component directly access the memory from the RAM component, --- that doesnt even know the display exists. In this specific case it assumes --- the table "memory" is created in the constructor of the ram component, but --- a callback could also be used. --- Mind also that you can have components that dont directly interact with the --- image chip (the ramdisplay here has an "display_offset" pin input, but it --- could have no pin and it would still work) -local ram = BasicRAM() -local ramDisplay = BasicRAMDisplay(ram.memory, 16, 16) -table.insert(chips, ram) -table.insert(chips, ramDisplay) - - addLevel({ icon = "../luasrc/imgs/levels/sandbox_icon.png", name = 'Sandbox', desc = [[ - !img:imgs/levels/sss.png Sandbox mode. No objective. @@ -40,23 +15,6 @@ You have a `clock` and a `power_on_reset` inputs. The `clock` input allows you to create synchronous auto-update circuits. The `power_on_reset` input allows you to initialize memory when applicable. It stays on (`1`) for the 2 first clock cycles, then it becomes off (`0`) forever. - -You also have an example of custom (reusable) components such as: - -- A WASD Keyboard input -- A ROM component -- A RAM component -- A RAM Display component - -You can create your own components and levels in the `luasrc/scripts/` folder of your game installation. (if the folder is not there you can create one from the template in `luasrc/template_scripts/`) - -You can look at the `luasrc/` folder for references/examples. - -The game will look for the `scripts/init.lua` script at initialization, so you can import/register your levels and scripts from there. - -You can open the game folder in steam via right click on the game name in "library", then go to "Manage" -> "Browse Local Files". - -`Attention:` Mind not modifying scripts outside the `luasrc/scripts/` folder because they are overidden in updates. ]], - chips = chips, + chips = {Clock(false)}, }) diff --git a/src/w_levels.c b/src/w_levels.c index 4d27b25..4dff624 100644 --- a/src/w_levels.c +++ b/src/w_levels.c @@ -170,8 +170,6 @@ void LevelsDraw(Ui* ui) { LevelOptions* co = ApiGetLevelOptions(); for (int i = 0; i < NUM_LEVEL_OPTS; i++) { if (co->options[i].name) { - printf("lvl %d %s\n", i, co->options[i].name); - // && !C.btn_opts[i].hidden BtnDrawIcon(&C.btn_opts[i], ui->scale, co->options[i].icon.tex, co->options[i].icon.region); if (co->options[i].complete) {