Skip to content

Commit

Permalink
add custom components level
Browse files Browse the repository at this point in the history
  • Loading branch information
lets-all-be-stupid-forever committed Dec 17, 2024
1 parent dde63f2 commit b9ab035
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 45 deletions.
1 change: 1 addition & 0 deletions luasrc/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Binary file added luasrc/imgs/levels/chain_guy_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added luasrc/imgs/levels/custom_example_level.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions luasrc/levels/custom_components_example.lua
Original file line number Diff line number Diff line change
@@ -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,
})


44 changes: 1 addition & 43 deletions luasrc/levels/sandbox.lua
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)},
})
2 changes: 0 additions & 2 deletions src/w_levels.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b9ab035

Please sign in to comment.